I currently have a 171 x 171 image from a GeoTiff file (although in other cases, I might have much bigger images). My goal is to take each pixel in the image and convert to latitude/longitude pair.
I am already able to convert the corners of the image to latitude/longitude pair based on this StackOverflow post: Obtain Latitude and Longitude from a GeoTIFF File. This post was helpful since my original coordinates were in UTM Zone 15.
However, I now want to convert all of the pixels of the image to latitude, longitude pair and store the results in a numpy array of the same dimension. So the output would be a numpy array that is 171 x 171 x 2 with each element of the numpy array being a tuple of the (longitude, latitude) pair.
The most relevant post I've seen on this is https://scriptndebug.wordpress.com/2014/11/24/latitudelongitude-of-each-pixel-using-python-and-gdal/. However, that post suggests to essentially create a for loop over each pixel and convert to latitude, longitude. Is there a way that is more efficient?
Just to give more context on my actual use case, my end goal is I have a bunch of satellite imagery (for example in this case, each image is 171 x 171). I am trying to create a building segmentation model. Right now, I am trying to produce labeled data points by creating a mask on each image that labels a pixel a 1 if it corresponds to a building, else 0. To start, I'm using the Microsoft US Building Footprint data: https://github.com/microsoft/USBuildingFootprints where they've released GeoJSON files of polygons (defined by latitude, longitude) of buildings they've detected. The way I'm thinking about doing this is:
- Find the latitude, longitude of each pixel in my image. Thus, I will have 171 x 171 Points. Put this in a GeoSeries
- Intersect the Points (in a GeoSeries) with the Microsoft US Building Footprints data (using GeoPandas intersects: https://geopandas.org/reference.html#geopandas.GeoSeries.intersects)
- If the Point intersects with any Polygons in the Microsoft US Building Footprint data, then label 1, else 0.
Right now I'm on step (1), that is, efficiently find the latitude/longitude coordinate of each pixel in the image.