Opened 10 years ago
Closed 10 years ago
#5301 closed defect (fixed)
GeoTransform
Reported by: | pmatusov | Owned by: | warmerdam |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | Docs | Version: | unspecified |
Severity: | normal | Keywords: | GeoTransform |
Cc: |
Description
I was wandering in the dark, trying to figure out why GDAL sometimes writes NITF correctly, and sometimes – not. The issue was geolocation matrix – which is 6-element in GDAL, meaning simple affine transformation. I believe there are either bugs in GDAL, or considerable discrepancies in description:
Here - http://www.gdal.org/gdal_datamodel.html - it says this:
The affine transform consists of six coefficients returned by GDALDataset::GetGeoTransform() which map pixel/line coordinates into georeferenced space using the following relationship:
Xgeo = GT(0) + Xpixel*GT(1) + Yline*GT(2) Ygeo = GT(3) + Xpixel*GT(4) + Yline*GT(5)
In case of north up images, the GT(2) and GT(4) coefficients are zero, and the GT(1) is pixel width, and GT(5) is pixel height. The (GT(0),GT(3)) position is the top left corner of the top left pixel of the raster. This is something very reasonable. However: Here – http://www.gdal.org/gdal_tutorial.html - it says this: As described in the GDAL Data Model, a GDALDataset contains a list of raster bands, all pertaining to the same area, and having the same resolution. It also has metadata, a coordinate system, a georeferencing transform, size of raster and various other information.
adfGeoTransform[0] /* top left x */ adfGeoTransform[1] /* w-e pixel resolution */ adfGeoTransform[2] /* rotation, 0 if image is "north up" */ adfGeoTransform[3] /* top left y */ adfGeoTransform[4] /* rotation, 0 if image is "north up" */ adfGeoTransform[5] /* n-s pixel resolution */
I wonder what is actually implemented…
Peter
Change History (4)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
According to the description of the data model (http://www.gdal.org/gdal_datamodel.html) -
Xgeo = GT(0) + Xpixel*GT(1) + Yline*GT(2) Ygeo = GT(3) + Xpixel*GT(4) + Yline*GT(5)
- in case of non-north-up-oriented images, the affine matrix components are these:
GT(0) and GT(3) are {Lon, Lat} in geodetic notation or {easting, northing} in UTM; GT(1) and GT(2) are partial derivatives in the sense {dLon/dX, dLon/dY} or {deasting/dX, deasting/dx}, and GT(4) and GT(5) are partial derivatives in the sense {dLat/dX, dLat/dY} or {dnorthing/dX, dnorthing/dx}.
It does not match with the description of gdal tutorial (http://www.gdal.org/gdal_tutorial.html ):
adfGeoTransform[0] /* top left x */ adfGeoTransform[1] /* w-e pixel resolution */ adfGeoTransform[2] /* rotation, 0 if image is "north up" */ adfGeoTransform[3] /* top left y */ adfGeoTransform[4] /* rotation, 0 if image is "north up" */ adfGeoTransform[5] /* n-s pixel resolution */
At the very best, for affine mapping between pixel space and flat-Earth geodetic space with a uniform ground sample distance (GSD) in X and Y coordinates, this definition could be re-worded as follows: If alpha is defined as the angle between (model-specific) North direction and the image's NEGATIVE Y axis (so that zero alpha corresponded to North-Up orientation), then
adfGeoTransform[0] /* top left x */ adfGeoTransform[1] /* (ground sample distance) x (cosine alpha) */ adfGeoTransform[2] /* (ground sample distance) x (sine alpha) */ adfGeoTransform[3] /* top left y */ adfGeoTransform[4] /* (ground sample distance) x (sine of alpha */ adfGeoTransform[5] /* (ground sample distance) x (minus cosine of alpha */
For the case of North-Up orientation and same GSD in Easting and Northing, the corrected definition matches the tutorial. I checked GDAL code archive, and it looks like GDAL calculates the matrix coefficients according to the data model (correctly, I wouldn't dare to imply otherwise), so what needs changing is the GDAL tutorial page. Am I making sense?
Peter
comment:3 by , 10 years ago
I wish I could go back and reformat the comment so the line breaks were where they should have been...
comment:4 by , 10 years ago
Component: | default → Docs |
---|---|
Milestone: | 1.9.3 |
Resolution: | → fixed |
Status: | new → closed |
I don't perceive any discrepancy in the two descriptions. They are just two equivalent ways of presenting the same information. Perhaps some precision of the fact that GT[5] is negative in case of "north up" images, but other than that that looks OK to me. Do you have a suggestion to make things clearer ?