11

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.

1 Answer 1

8

write expects an array with shape (band, row, col). You can either reshape your array, or you can use write(supervised, indexes=1).

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the tip. I was already investigating the np.transpose option but you answer definetly put me on the right way

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.