Skip to content Skip to sidebar Skip to footer

How To Grab A Geo Tiff Image With Python

Today I'm in trouble because for the first time I have to work with TIFF files, and I have an error. I'm trying to grab a raster with the values of pollution agents in Europe, so I

Solution 1:

geoTiff

Your file is not a regular tiff-file, it's a geoTiff file which needs a special library.

For python there is the georasters library to read those files. You can then show them with matplotlib.

Using requests has a way nicer interface than urllib in my opinion:

import requests
from PIL import Image
import georasters as gr
import matplotlib.pyplot as plt


url = 'http://wdc.dlr.de/wdcservices/wcs.php'

query = {
    'COVERAGE': '17e72d93-76d9-4af6-9899-b7b04e2763c8',
    'service': 'wcs',
    'version': '1.0.0',
    'crs': 'epsg:4326',
    'bbox': '-25,30,45,70',
    'RESX': '0.1',
    'RESY': '0.1',
    'request': 'getcoverage',
    'format': 'application/x-tiff-32f',
    'TIME': '2015-12-13T00',
    'elevation': '0',
    'OUTPUTFILENAME': '17e72d93-76d9-4af6-9899-b7b04e2763c8_2015-12-13T00_0'
}

with open('test.tiff', 'wb') as f:

    ret = requests.get(url, stream=True, params=query)
    fordatain ret.iter_content(1024):
        f.write(data)

data = gr.from_file('test.tiff')

plt.imshow(data.raster, cmap='gray')
plt.show()

Result: result

Solution 2:

I've worked too with .tiff images

What I used was imread from openCV and it worked really well

Post a Comment for "How To Grab A Geo Tiff Image With Python"