I have the following numpy array:
supervised.shape
(1270, 1847)
I am trying to use the following code to save it to GeoTIFF using rasterio
:
with rasterio.open('/my/path/ReferenceRaster.tif') as src:
ras_meta = src.profile
with rasterio.open('/my/output/path/output_supervised.tif', 'w', **ras_meta) as dst:
dst.write(supervised)
Where ras_meta
is:
{'driver': 'GTiff', 'dtype': 'float32', 'nodata': None, 'width': 1847, 'height': 1270, 'count': 1, 'crs': CRS.from_epsg(32736), 'transform': Affine(10.0, 0.0, 653847.1979372115,
0.0, -10.0, 7807064.5603836905), 'tiled': False, 'interleave': 'band'}
I am facing the following error which I cannot understand since both the reference raster and my supervised
array have the same shape
ValueError: Source shape (1270, 1847) is inconsistent with given indexes 1
Any idea what is the issue here? I am not completly understanding the meaning of the error.
Rasterio has one C library dependency: GDAL >=1.11 . GDAL itself depends on many of other libraries provided by most major operating systems and also depends on the non standard GEOS and PROJ4 libraries. Python package dependencies (see also requirements. txt): affine, cligj, click, enum34, numpy .
Rasterio supports three primary methods for transforming of coordinates from image pixel (row, col) to and from geographic/projected (x, y) coordinates. The interface for performing these coordinate transformations is available in rasterio.
Geographic information systems use GeoTIFF and other formats to organize and store gridded raster datasets such as satellite imagery and terrain models. Rasterio reads and writes these formats and provides a Python API based on Numpy N-dimensional arrays and GeoJSON.
write
expects an array with shape (band, row, col)
. You can either reshape your array, or you can use write(supervised, indexes=1)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With