How to save return data as geotiff

How can we save directly the return data as a geotiff?


Hi David,

you can save data by first specifying data_folder argument of WmsRequest / WcsRequest and then calling:



images = m_wms_request.get_data(save_data=True)

This will save geotiff files exactly as obtained from Sentinel Hub service.

Also note that once you read data from images into numpy arrays sentinelhub package will only be able to save these values into normal tiff file and not geotiff file anymore.

There’s a possibility to store a geo-referenced tiff file from numpy array but it’s not as convenient as the above method suggested by @maleksandrov.

If for example you download the data using Wms/WcsRequest, manipulate it in some way (i.e. do some feature extraction, classification, etc.) and want to store these derived quantities then the above suggestion is not helpful. In such cases one way to produce geo-referenced tiff file from numpy array is by using rasterio python package. The following code snippet saves array of dimension hxw (1-band to georeference tiff):

# array of shape (h, w)
dst_shape = array.shape

# bbox is the bounding box BBox instance used in Wms/WcsRequest 
dst_transform = rasterio.transform.from_bounds(*bbox.get_lower_left(), *bbox.get_upper_right(),
                                               width=dst_shape[1], height=dst_shape[0])
dst_crs = {'init': CRS.ogc_string(}

# Write it out to a file.
with, 'w', driver='GTiff',
                              width=dst_shape[1], height=dst_shape[0],
                              count=1, dtype=np.unit8, nodata=0,
                              transform=dst_transform, crs=dst_crs) as dst:
    dst.write(array.astype(np.uint8), indexes=1)