1

I am following this guy's code from here: pixel/array position to lat long gdal Python and more specifically this:

import rasterio

with rasterio.open('rasters/raster.tif') as map_layer:
    pixels2coords = map_layer.xy(pixel_x, pixel_y)  #input px, py

in order to translate pixel coordinates into lat, long.

My .tif image has this shape:

map_layer.width = 715

map_layer.height = 462

When I give a random pixel_x < 462 everything is fine (for any pixel_y).

However, when I give a random pixel_x > 462

For instance, I get this error:

IndexError: index 525 is out of bounds for axis 0 with size 462

I checked the image as you can see above and it loads it correctly. I mean the width and height are correct. I have spent all day trying to fix it, I do not why this happens...Any idea?

I cannot post the whole code is...it is many lines and too complicated to post a minimum runnable code.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
just_learning
  • 413
  • 2
  • 11
  • 24

0 Answers0