Thursday 28 April 2016

Finding the pixel coordinates using GDAL/numpy


Is there a way to get the XY cordinates of a pixel based on the array index using numpy/gdal?


I have a new set of extents for a raster and, based on these newer extents, want to determine the centroid of the raster (polygon). Wondering if there are any functions which can return the coordinate values based on the pixel indices.



Answer



Gdal probably has a handy function. Have you looked at these links?



But knowing that the header of the image contains the bounding coordinates and projection information, you could calculate them yourself (not recommended unless you enjoy learning things the hard way). EX: I knew my pixel size was 30m. For point 3,4 from the origin it's simple algebra: 3x30 +/- Origin's X, 4x30 +/- Origin's Y Caveats:



  • assumes you're nowhere near zone boundaries

  • not very accurate beyond locating the right pixel

  • remember to deal with negative coordinates properly (the +/- in the example)


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...