From b9f0c642f1a547555c27b069d6cfe488b20a5c6e Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Fri, 7 Jun 2024 18:32:16 +0200 Subject: [PATCH] Internal libgeotiff: resync with https://github.com/OSGeo/libgeotiff/pull/118 --- frmts/gtiff/gt_wkt_srs.cpp | 17 ++++++++++++- frmts/gtiff/libgeotiff/geo_normalize.c | 33 ++++++++++++++++++++++---- frmts/gtiff/libgeotiff/geo_normalize.h | 12 +++++++--- frmts/gtiff/libgeotiff/geotiff.h | 2 +- 4 files changed, 55 insertions(+), 9 deletions(-) diff --git a/frmts/gtiff/gt_wkt_srs.cpp b/frmts/gtiff/gt_wkt_srs.cpp index a1ea06dfac60..919829f2d511 100644 --- a/frmts/gtiff/gt_wkt_srs.cpp +++ b/frmts/gtiff/gt_wkt_srs.cpp @@ -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 @@ -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 /* -------------------------------------------------------------------- */ diff --git a/frmts/gtiff/libgeotiff/geo_normalize.c b/frmts/gtiff/libgeotiff/geo_normalize.c index 11517462c761..f16b67be4d9d 100644 --- a/frmts/gtiff/libgeotiff/geo_normalize.c +++ b/frmts/gtiff/libgeotiff/geo_normalize.c @@ -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: @@ -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; } diff --git a/frmts/gtiff/libgeotiff/geo_normalize.h b/frmts/gtiff/libgeotiff/geo_normalize.h index 87dd22c7e7df..79f588c813b9 100644 --- a/frmts/gtiff/libgeotiff/geo_normalize.h +++ b/frmts/gtiff/libgeotiff/geo_normalize.h @@ -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. diff --git a/frmts/gtiff/libgeotiff/geotiff.h b/frmts/gtiff/libgeotiff/geotiff.h index 29f22917f4c4..75de593c8a0e 100644 --- a/frmts/gtiff/libgeotiff/geotiff.h +++ b/frmts/gtiff/libgeotiff/geotiff.h @@ -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"