[gdal-dev] GeoTransform confusion

Even Rouault even.rouault at spatialys.com
Thu Nov 19 01:26:23 PST 2015


Le jeudi 19 novembre 2015 09:24:46, Simon Lyngby Kokkendorff a écrit :
> Basically it seems to be an issue with interpreting "center" directives
> when doing the gdal_translate. Consider:
> 
> ncols 2
> nrows 2
> xllcenter 0.0
> yllcenter 0.0
> cellsize 1.0
> nodata_value -999
> 2 2
> 2 2
> 
> gdalinfo on this file, will give the expected GeoTransform:
> 
> In [2]: ds = gdal.Open("center.asc")
> 
> In [3]: ds.GetGeoTransform()
> Out[3]: (-0.5, 1.0, 0.0, 1.5, 0.0, -1.0)
> 
> Seems OK to me.
> 
> If I then do a gdal_translate: gdal_translate center.asc center.tif, I get
> another interpretation:
> 
> In [4]: ds = gdal.Open("center.tif")
> 
> In [5]: ds.GetGeoTransform()
> Out[5]: (0.0, 1.0, 0.0, 1.0, 0.0, -1.0)
> 
> And, if I do a roundtrip: gdal_translate -of AAIGRID center.tif
> center_back.asc, I get:
> ncols        2
> nrows        2
> xllcorner    0.000000000000
> yllcorner    -1.000000000000
> cellsize     1.000000000000
> NODATA_value -999
>  2 2
>  2 2
> 
> Which is definitely not the same GeoTransform as my input center.asc, but
> shifted half a cellsize from what I would expect...
> 
> In [6]: ds = gdal.Open("center_back.asc")
> 
> In [7]: ds.GetGeoTransform()
> Out[7]: (0.0, 1.0, 0.0, 1.0, 0.0, -1.0)
> 
> 
> 
> GDAL version:
> GDAL 1.11.2, released 2015/02/10

Simon,

Regarding the fact that the geotiff file looses the half-pixel shift, it seems 
to be due to the absence of a SRS. If I do "gdal_translate test.asc test.tif -
a_srs EPSG:32630" for example, then the geotransform I get back is correct. 
This is a defect of the GeoTIFF writer that writes the GeoTIFF Tiepoints with 
the PixelIsPoint convention (since your original data is flagged as such), but 
fails to write GTRasterTypeGeoKey=RasterPixelIsPoint as a geotiff key when 
there's no SRS. Could be worth a ticket.

Some background: https://trac.osgeo.org/gdal/wiki/rfc33_gtiff_pixelispoint

A workaround :
gdal_translate test.asc test.tif -mo AREA_OR_POINT=AREA

This will force the geotiff writer to use the default convention, and thus 
avoiding going back to the centerofpixel convention when writing the GeoTIFF 
tiepoints.

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list