I have a Python script that I am using to load .asc raster files and then work with the contents therein. However, it isn't loading the correct information that is specified in the headers. The .asc file that I am using has the following for headers:

ncols        2131
nrows        2220
xllcorner    670813.505443912582
yllcorner    5480455.007973534055
cellsize     3.000109992417

But when I run the following simple script to obtain the values of xllcorner, yllcorner, and cellsize:

from osgeo import gdal

dempath = 'My_DEM.asc'
dem_file = gdal.Open(dempath)
dem_transform = dem_file.GetGeoTransform()

I get the following as output:

(670813.5054439126, 3.000109992417, 0.0, 5487115.2521567, 0.0, -3.000109992417)

So as we can see, the yllcorner value that is loaded from the asc file isn't 5480455.007973534055, or any rounding off of it, that I would expect it to be. Instead I am getting 5487115.2521567, which is far off enough that it causes problems for me later on. I can import the correct header information with a variety of ways that are not using the GDAL Python wrappers, but ideally I'd like to keep using the GDAL Python wrappers. Is there something special I am forgetting to specify in my script like projection information? Is this a known bug in GDAL? How can I resolve this issue without having to write my own asc file parser?


No, it's not a bug. 5487115.2521567 is correct.

The GeoTransform doesn't give you the lower left, it gives you the origin. Which is the upper left. You can calculate the lower left from the origin + y pixel size * no. rows:

yllcorner = dem_transform [3] + dem_transform[5] * dem_file.RasterYSize

| improve this answer | |
  • Today I learned something very new and useful about how the GDAL Python wrappers are actually loading these data in. Thanks so much for showing me what it's actually doing. – R. M. Spies Aug 14 '19 at 19:11

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.