2
votes

I'm trying to extract Lat/Long coordinates for each pixel in a raster image using Python. I'd like to keep this process open-source, as I know I could do it using the arcpy module (Convert raster to points and then get point info with point.POINT_X etc.)

*For clarity: I'm trying to get latitude and longitude coordinates of a Landsat raster dataset.

1
Are we talking about literal latitude and longitude here? Is the image a picture of the Earth? Or do you just mean general x/y coordinates of pixels in an image? - Kevin
Sorry I didn't clarify. Latitude Longitude values for a Landsat raster dataset. - Scott
Have you considered instead finding the spatial extent (xmin/xmax/ymin/ymax) and resolution (cell size) of the raster, then generating an array of lat/long values based on where the pixels have to fall give those limits? Using that mathematical approach would be simpler than extracting pixel coordinates, and also easier to do without arcpy. - Erica

1 Answers

0
votes

Disclaimer: I'm the author of the following library.

You can convert your raster into a point cloud with lidario.Translator. It will return a np.array with the coordinates of each pixel in your tif file.

Geotiff to np.array:

import lidario as lio
    
# Create a Translator object which will take a tif file and return a np.array
translator = lio.Translator("geotiff", "np")
    
# Translate the tif file and get the np.array
point_cloud = translator.translate("/path/to/file.tif")