1

I'm trying to better understand GeoTransform. For getting the extents of a raster, I've seen solutions posted such as below. But doesn't this only account for perfectly square rasters? From my understanding it gets the upper left x and y geographical positions, gets the geographical distance covered by an individual pixel, and the amount of pixels.

import gdal
from gdalconst import GA_ReadOnly

data = gdal.Open('C:/Temp/myimage.tif', GA_ReadOnly)
geoTransform = data.GetGeoTransform()
minx = geoTransform[0]
maxy = geoTransform[3]
maxx = minx + geoTransform[1] * data.RasterXSize
miny = maxy + geoTransform[5] * data.RasterYSize
print [minx, miny, maxx, maxy]
data = None

upper_left = [minx, maxy]
bottom_left = [minx, miny]
upper_right = [maxx, maxy]
bottom_right = [maxx, miny]

If you were attempting to redraw the shape with this, it would only work for perfect squares right? If the lower left corner is shifted slightly further left from the top left, it wouldn't be accounted for?

When I do gdalinfo, I get the following results for corner coordinates:

Corner Coordinates:

Upper Left ( 248061.434, 4620818.949) ( 72d 1'39.76"W, 41d41'57.41"N)

Lower Left ( 248061.434, 4553370.949) ( 71d59'58.78"W, 41d 5'33.28"N)

Upper Right ( 275337.434, 4620818.949) ( 71d42' 1.04"W, 41d42'26.81"N)

Lower Right ( 275337.434, 4553370.949) ( 71d40'30.95"W, 41d 6' 2.06"N)

Center ( 261699.434, 4587094.949) ( 71d51' 2.32"W, 41d24' 0.34"N)

6
  • 1
    Rasters are always perfect rectangles with some fixed number of rows and columns. Some of the pixels may present nodata. If you are interested in the area covered by of valid pixels in different projections I think that you should polygonize the valid area and use the vectorized version for further analysis.
    – user30184
    Mar 8 at 12:36
  • Oh, so thats why there's also a "ghost" pixel with no data around some parts of my raster. Its padding that extra pixel to create a perfect rectangle. That makes sense. Thanks. I edited in gdalinfo results. Do you know why the coordinates in the results appear to be the same in meters but different in degrees? The meter results make sense to me if its a perfect rectangle.
    – AskioFrio
    Mar 8 at 13:03
  • What is the coordinate system of your data?
    – user30184
    Mar 8 at 13:26
  • EPSG:32619 - WGS 84 / UTM zone 19N - Projected
    – AskioFrio
    Mar 8 at 13:31
  • Corner coordinates are expressed in two different coordinate systems. What is rectangular in one does not need to be that in another. Actually the lon-lat coordinates are achieved by converting the corner points in the vector world. You can try and convert coordinates corner by corner. gdaltransform -s_srs epsg:32619 -t_srs epsg:4326 Enter X Y [Z [T]] values separated by space, and press Return. 248061.434 4620818.949 -72.0277103882385 41.6992808880501 0 248061.434 4553370.949 -71.9996603133268 41.0925770822793 0.
    – user30184
    Mar 8 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.