Skip to content

Commit

Permalink
Merge pull request #10159 from rouault/fix_10154_continuation
Browse files Browse the repository at this point in the history
Internal libgeotiff: resync with OSGeo/libgeotiff#118
  • Loading branch information
rouault committed Jun 11, 2024
2 parents 8130bd2 + e509d34 commit cf2f9d0
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 9 deletions.
17 changes: 16 additions & 1 deletion frmts/gtiff/gt_wkt_srs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,8 @@ OGRSpatialReferenceH GTIFGetOGISDefnAsOSR(GTIF *hGTIF, GTIFDefn *psDefn)
for (; i < 10; i++)
adfParam[i] = 0.0;

// libgeotiff is unfortunately inconsistent. When it synthetizes the
#if LIBGEOTIFF_VERSION <= 1730
// libgeotiff <= 1.7.3 is unfortunately inconsistent. When it synthetizes the
// projection parameters from the EPSG ProjectedCRS code, it returns
// them normalized in degrees. But when it gets them from
// ProjCoordTransGeoKey and other Proj....GeoKey's it return them in
Expand All @@ -1418,6 +1419,20 @@ OGRSpatialReferenceH GTIFGetOGISDefnAsOSR(GTIF *hGTIF, GTIFDefn *psDefn)
adfParam[2] *= psDefn->UOMAngleInDegrees;
adfParam[3] *= psDefn->UOMAngleInDegrees;
}
#else
// If GTIFF_READ_ANGULAR_PARAMS_IN_DEGREE=YES (non-nominal case), undo
// the conversion to degrees, that has been done by libgeotiff > 1.7.3
if (GDALGTIFKeyGetSHORT(hGTIF, ProjCoordTransGeoKey, &tmp, 0, 1) &&
psDefn->UOMAngleInDegrees != 0 && psDefn->UOMAngleInDegrees != 1 &&
CPLTestBool(CPLGetConfigOption(
"GTIFF_READ_ANGULAR_PARAMS_IN_DEGREE", "NO")))
{
adfParam[0] /= psDefn->UOMAngleInDegrees;
adfParam[1] /= psDefn->UOMAngleInDegrees;
adfParam[2] /= psDefn->UOMAngleInDegrees;
adfParam[3] /= psDefn->UOMAngleInDegrees;
}
#endif

/* --------------------------------------------------------------------
*/
Expand Down
33 changes: 29 additions & 4 deletions frmts/gtiff/libgeotiff/geo_normalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -2241,15 +2241,16 @@ static void GTIFFetchProjParms( GTIF * psGTIF, GTIFDefn * psDefn )
break;
}

for( int iParam = 0; iParam < psDefn->nParms; iParam++ )
{
switch( psDefn->ProjParmId[iParam] )
{

/* -------------------------------------------------------------------- */
/* Normalize any linear parameters into meters. In GeoTIFF */
/* the linear projection parameter tags are normally in the */
/* units of the coordinate system described. */
/* -------------------------------------------------------------------- */
for( int iParam = 0; iParam < psDefn->nParms; iParam++ )
{
switch( psDefn->ProjParmId[iParam] )
{
case ProjFalseEastingGeoKey:
case ProjFalseNorthingGeoKey:
case ProjFalseOriginEastingGeoKey:
Expand All @@ -2263,6 +2264,30 @@ static void GTIFFetchProjParms( GTIF * psGTIF, GTIFDefn * psDefn )
}
break;

/* -------------------------------------------------------------------- */
/* Normalize any angular parameters into degrees. In GeoTIFF */
/* the angular projection parameter tags are normally in the */
/* units of GeogAngularUnit. Note: this conversion is only done */
/* since libgeotiff 1.7.4 */
/* -------------------------------------------------------------------- */

case ProjStdParallel1GeoKey:
case ProjStdParallel2GeoKey:
case ProjNatOriginLongGeoKey:
case ProjNatOriginLatGeoKey:
case ProjFalseOriginLongGeoKey:
case ProjFalseOriginLatGeoKey:
case ProjCenterLongGeoKey:
case ProjCenterLatGeoKey:
case ProjStraightVertPoleLongGeoKey:
case ProjRectifiedGridAngleGeoKey:
if( psDefn->UOMAngleInDegrees != 0
&& psDefn->UOMAngleInDegrees != 1.0 )
{
psDefn->ProjParm[iParam] *= psDefn->UOMAngleInDegrees;
}
break;

default:
break;
}
Expand Down
12 changes: 9 additions & 3 deletions frmts/gtiff/libgeotiff/geo_normalize.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,15 @@ typedef struct {
int nParms;

/** Projection parameter value. The identify of this parameter
is established from the corresponding entry in ProjParmId. The
value will be measured in meters, or decimal degrees if it is a
linear or angular measure. */
is established from the corresponding entry in ProjParmId.
In GeoTIFF keys, the values of the projection parameters are expressed
in the units of ProjLinearUnitsGeoKey (for linear measures) or
GeogAngularUnitsGeoKey (for angular measures).
However, the value returned in ProjParam[] will be normalized to meters
or decimal degrees.
Note: until libgeotiff 1.7.3, the conversion to degrees for angular
measures was *not* done when ProjCoordTransGeoKey is present.
*/
double ProjParm[MAX_GTIF_PROJPARMS];

/** Projection parameter identifier. For example ProjFalseEastingGeoKey.
Expand Down
2 changes: 1 addition & 1 deletion frmts/gtiff/libgeotiff/geotiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#define GEOTIFF_SPEC_1_1_MINOR_REVISION 1

/* Library version */
#define LIBGEOTIFF_VERSION 1710
#define LIBGEOTIFF_VERSION 1740

#include "geo_config.h"
#include "geokeys.h"
Expand Down

0 comments on commit cf2f9d0

Please sign in to comment.