[gdal-dev] Errors in geotransform computation from ENVI rotated header?

Kevin B. McCarty kmccarty at gmail.com
Wed Jul 19 11:00:48 PDT 2017


Hi Guillaume,

On Wed, Jul 19, 2017 at 3:28 AM, Guillaume Pasero
<guillaume.pasero at c-s.fr> wrote:
>
> Hi,
>
> I think my issue is not strictly related. The problem I had was about the way the rotation angle is computed in WriteProjectionInfo() when the determinant of the geotransform is positive.
>
> Let's call det(GT) the determinant of the 2x2 sub-matrix of GT, without origin terms. In a standard case : GT[1] > 0 and GT[5] < 0 (Y axis downwards) and we have a negative determinant. Even when there is a rotation, it doesn't change the sign of the determinant and the formula to compute the rotation angle is good. However, when the determinant is positive (like when both spacing are positive), then the computation of the rotation angle has to be changed.

Yes, that makes sense to me.

It seems to me that when the matrix determinant is positive (and the
geotransform is not the default no-translation identity), the correct
thing to do from a mathematical standpoint is to force exactly one of
the output x-pixel or y-pixel sizes to be negative in order to
compensate.  This is the only way I can see that the geotransform
could be made to still have a positive determinant at the time of a
later read of that same file.

I guess it should be the y-pixel size, since folks are already used to
that being negative (in the reverse, more usual situation of a
negative-determinant matrix) in e.g. world files.  From a practical
standpoint, though, I have no idea how many applications out there
would both allow, and correctly interpret, an ENVI header with a
negative y-pixel size.

With respect to my suggested corrections for the ProcessMapinfo()
function at read time, I believe that the corresponding fix to the
WriteProjectionInfo() function is simple in the usual case of a
negative matrix determinant: it is just to swap the use of the [2] and
[4] elements of adfGeoTransform[] everywhere that either is used in
that function in the computation of variables dfPixelXSize,
dfPixelYSize, dfRotation1 and dfRotation2.

I would have to think a little more about what the right calculation
should be in the case of a positive matrix determinant.  If Taylor
Brown doesn't respond to this thread within a few days, I'll try to
put together a patch myself that incorporates all of this.

-- 
Kevin B. McCarty
<kmccarty at gmail.com>


More information about the gdal-dev mailing list