Skip to content

Commit af121ef

Browse files
authored
Merge pull request #118 from rouault/fix_gdal_10154
GTIFGetDefn(): add missing normalization of angular units to degree
2 parents 9af3298 + 46244ce commit af121ef

File tree

8 files changed

+158
-9
lines changed

8 files changed

+158
-9
lines changed

libgeotiff/geo_normalize.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,15 +2241,16 @@ static void GTIFFetchProjParms( GTIF * psGTIF, GTIFDefn * psDefn )
22412241
break;
22422242
}
22432243

2244+
for( int iParam = 0; iParam < psDefn->nParms; iParam++ )
2245+
{
2246+
switch( psDefn->ProjParmId[iParam] )
2247+
{
2248+
22442249
/* -------------------------------------------------------------------- */
22452250
/* Normalize any linear parameters into meters. In GeoTIFF */
22462251
/* the linear projection parameter tags are normally in the */
22472252
/* units of the coordinate system described. */
22482253
/* -------------------------------------------------------------------- */
2249-
for( int iParam = 0; iParam < psDefn->nParms; iParam++ )
2250-
{
2251-
switch( psDefn->ProjParmId[iParam] )
2252-
{
22532254
case ProjFalseEastingGeoKey:
22542255
case ProjFalseNorthingGeoKey:
22552256
case ProjFalseOriginEastingGeoKey:
@@ -2263,6 +2264,30 @@ static void GTIFFetchProjParms( GTIF * psGTIF, GTIFDefn * psDefn )
22632264
}
22642265
break;
22652266

2267+
/* -------------------------------------------------------------------- */
2268+
/* Normalize any angular parameters into degrees. In GeoTIFF */
2269+
/* the angular projection parameter tags are normally in the */
2270+
/* units of GeogAngularUnit. Note: this conversion is only done */
2271+
/* since libgeotiff 1.7.4 */
2272+
/* -------------------------------------------------------------------- */
2273+
2274+
case ProjStdParallel1GeoKey:
2275+
case ProjStdParallel2GeoKey:
2276+
case ProjNatOriginLongGeoKey:
2277+
case ProjNatOriginLatGeoKey:
2278+
case ProjFalseOriginLongGeoKey:
2279+
case ProjFalseOriginLatGeoKey:
2280+
case ProjCenterLongGeoKey:
2281+
case ProjCenterLatGeoKey:
2282+
case ProjStraightVertPoleLongGeoKey:
2283+
case ProjRectifiedGridAngleGeoKey:
2284+
if( psDefn->UOMAngleInDegrees != 0
2285+
&& psDefn->UOMAngleInDegrees != 1.0 )
2286+
{
2287+
psDefn->ProjParm[iParam] *= psDefn->UOMAngleInDegrees;
2288+
}
2289+
break;
2290+
22662291
default:
22672292
break;
22682293
}

libgeotiff/geo_normalize.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,15 @@ typedef struct {
121121
int nParms;
122122

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

129135
/** Projection parameter identifier. For example ProjFalseEastingGeoKey.

libgeotiff/geotiff.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
#define GEOTIFF_SPEC_1_1_MINOR_REVISION 1
4848

4949
/* Library version */
50-
#define LIBGEOTIFF_VERSION 1730
50+
#define LIBGEOTIFF_VERSION 1740
5151

5252
#include "geo_config.h"
5353
#include "geokeys.h"

libgeotiff/test/Makefile.am

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ EXTRA_DIST = testlistgeo testlistgeo_out.dist \
5555
data/lambert_cylindrical_equal_area.tif \
5656
data/ProjectedCSTypeGeoKey_4087_equidistant_cylindrical.tif \
5757
data/equidistant_cylindrical.tif \
58-
data/pixel_is_point_wgs84.tif
58+
data/pixel_is_point_wgs84.tif \
59+
data/epsg_27563_only_pcs_code.tif \
60+
data/epsg_27563_allgeokeys.tif
5961

6062
check-local:
6163
$(TESTLISTGEO) $(LISTGEOEXE)
757 Bytes
Binary file not shown.
924 Bytes
Binary file not shown.

libgeotiff/test/testlistgeo

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,14 @@ mv testlistgeo_out.dist.normalized.tmp testlistgeo_out.dist.normalized
244244
sed "s/ProjCenterLongGeoKey: 46.437229 ( 46d26'14.02\"E)/ProjCenterLongGeoKey: 46.437229 ( 46d26'14.03\"E)/" < testlistgeo_out.dist.normalized > testlistgeo_out.dist.normalized.tmp
245245
mv testlistgeo_out.dist.normalized.tmp testlistgeo_out.dist.normalized
246246

247+
echo "Testing listgeo epsg_27563_only_pcs_code.tif" >> ${OUT}
248+
$EXE ${DATA_DIR}/epsg_27563_only_pcs_code.tif >>${OUT}
249+
echo "" >>${OUT}
250+
251+
echo "Testing listgeo epsg_27563_allgeokeys.tif" >> ${OUT}
252+
$EXE ${DATA_DIR}/epsg_27563_allgeokeys.tif >>${OUT}
253+
echo "" >>${OUT}
254+
247255
# do 'diff' with distribution results
248256
# after cleaning for avoid spurios result due
249257
# to different build dir

libgeotiff/test/testlistgeo_out.dist

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,3 +2005,111 @@ Upper Right ( 2d 0' 0.00"E, 54d 0' 0.00"N)
20052005
Lower Right ( 2d 0' 0.00"E, 50d 0' 0.00"N)
20062006
Center ( 0d 0' 0.00"E, 52d 0' 0.00"N)
20072007

2008+
Testing listgeo epsg_27563_only_pcs_code.tif
2009+
Geotiff_Information:
2010+
Version: 1
2011+
Key_Revision: 1.0
2012+
Tagged_Information:
2013+
ModelTiepointTag (2,3):
2014+
0 0 0
2015+
827294.141443773 523985.644431661 0
2016+
ModelPixelScaleTag (1,3):
2017+
0.500636999995913 0.500637000001734 0
2018+
End_Of_Tags.
2019+
Keyed_Information:
2020+
GTModelTypeGeoKey (Short,1): ModelTypeProjected
2021+
GTRasterTypeGeoKey (Short,1): RasterPixelIsArea
2022+
GTCitationGeoKey (Ascii,33): "NTF (Paris) / Lambert Sud France"
2023+
GeogCitationGeoKey (Ascii,12): "NTF (Paris)"
2024+
GeogAngularUnitsGeoKey (Short,1): Angular_Grad
2025+
ProjectedCSTypeGeoKey (Short,1): Code-27563 (NTF (Paris) / Lambert Sud France)
2026+
ProjLinearUnitsGeoKey (Short,1): Linear_Meter
2027+
End_Of_Keys.
2028+
End_Of_Geotiff.
2029+
2030+
PCS = 27563 (NTF (Paris) / Lambert Sud France)
2031+
Projection = 18093 (Lambert Sud France)
2032+
Projection Method: CT_LambertConfConic_1SP
2033+
ProjNatOriginLatGeoKey: 44.100000 ( 44d 6' 0.00"N)
2034+
ProjNatOriginLongGeoKey: 0.000000 ( 0d 0' 0.00"E)
2035+
ProjScaleAtNatOriginGeoKey: 0.999877
2036+
ProjFalseEastingGeoKey: 600000.000000 m
2037+
ProjFalseNorthingGeoKey: 200000.000000 m
2038+
GCS: 4807/NTF (Paris)
2039+
Datum: 6807/Nouvelle Triangulation Francaise (Paris)
2040+
Ellipsoid: 7011/Clarke 1880 (IGN) (6378249.20,6356515.00)
2041+
Prime Meridian: 8903/Paris (2.337229/ 2d20'14.03"E)
2042+
Projection Linear Units: 9001/metre (1.000000m)
2043+
2044+
Corner Coordinates:
2045+
Upper Left ( 827294.141, 523985.644) ( 2d59' 3.48"E, 46d58'37.71"N)
2046+
Lower Left ( 827294.141, 523980.638) ( 2d59' 3.47"E, 46d58'37.54"N)
2047+
Upper Right ( 827299.148, 523985.644) ( 2d59' 3.71"E, 46d58'37.70"N)
2048+
Lower Right ( 827299.148, 523980.638) ( 2d59' 3.71"E, 46d58'37.54"N)
2049+
Center ( 827296.645, 523983.141) ( 2d59' 3.59"E, 46d58'37.62"N)
2050+
2051+
Testing listgeo epsg_27563_allgeokeys.tif
2052+
Geotiff_Information:
2053+
Version: 1
2054+
Key_Revision: 1.0
2055+
Tagged_Information:
2056+
ModelTiepointTag (2,3):
2057+
0 0 0
2058+
827294.141443773 523985.644431661 0
2059+
ModelPixelScaleTag (1,3):
2060+
0.500636999995913 0.500637000001734 0
2061+
End_Of_Tags.
2062+
Keyed_Information:
2063+
GTModelTypeGeoKey (Short,1): ModelTypeProjected
2064+
GTRasterTypeGeoKey (Short,1): RasterPixelIsArea
2065+
GTCitationGeoKey (Ascii,33): "NTF (Paris) / Lambert Sud France"
2066+
GeographicTypeGeoKey (Short,1): GCS_NTF_Paris
2067+
GeogCitationGeoKey (Ascii,12): "NTF (Paris)"
2068+
GeogGeodeticDatumGeoKey (Short,1): Code-6807 (Nouvelle Triangulation Francaise (Paris))
2069+
GeogPrimeMeridianGeoKey (Short,1): PM_Paris
2070+
GeogAngularUnitsGeoKey (Short,1): Angular_Grad
2071+
GeogAngularUnitSizeGeoKey (Double,1): 0.0157079632679489
2072+
GeogEllipsoidGeoKey (Short,1): Ellipse_Clarke_1880_IGN
2073+
GeogSemiMajorAxisGeoKey (Double,1): 6378249.2
2074+
GeogInvFlatteningGeoKey (Double,1): 293.466021293627
2075+
GeogPrimeMeridianLongGeoKey (Double,1): 2.5969213
2076+
GeogTOWGS84GeoKey (Double,7): -168 -60 320
2077+
0 0 0
2078+
0
2079+
ProjectedCSTypeGeoKey (Short,1): Code-27563 (NTF (Paris) / Lambert Sud France)
2080+
PCSCitationGeoKey (Ascii,33): "NTF (Paris) / Lambert Sud France"
2081+
ProjectionGeoKey (Short,1): Code-18093 (Lambert Sud France)
2082+
ProjCoordTransGeoKey (Short,1): CT_LambertConfConic_1SP
2083+
ProjLinearUnitsGeoKey (Short,1): Linear_Meter
2084+
ProjLinearUnitSizeGeoKey (Double,1): 1
2085+
ProjNatOriginLongGeoKey (Double,1): 0
2086+
ProjNatOriginLatGeoKey (Double,1): 49
2087+
ProjFalseEastingGeoKey (Double,1): 600000
2088+
ProjFalseNorthingGeoKey (Double,1): 200000
2089+
ProjScaleAtNatOriginGeoKey (Double,1): 0.999877499
2090+
VerticalUnitsGeoKey (Short,1): Linear_Meter
2091+
End_Of_Keys.
2092+
End_Of_Geotiff.
2093+
2094+
PCS = 27563 (NTF (Paris) / Lambert Sud France)
2095+
Projection = 18093 (Lambert Sud France)
2096+
Projection Method: CT_LambertConfConic_1SP
2097+
ProjNatOriginLatGeoKey: 44.100000 ( 44d 6' 0.00"N)
2098+
ProjNatOriginLongGeoKey: 0.000000 ( 0d 0' 0.00"E)
2099+
ProjScaleAtNatOriginGeoKey: 0.999877
2100+
ProjFalseEastingGeoKey: 600000.000000 m
2101+
ProjFalseNorthingGeoKey: 200000.000000 m
2102+
GCS: 4807/NTF (Paris)
2103+
Datum: 6807/Nouvelle Triangulation Francaise (Paris)
2104+
Ellipsoid: 7011/Clarke 1880 (IGN) (6378249.20,6356515.00)
2105+
Prime Meridian: 8903/Paris (2.337229/ 2d20'14.03"E)
2106+
TOWGS84: -168,-60,320,0,0,0,0
2107+
Projection Linear Units: 9001/metre (1.000000m)
2108+
2109+
Corner Coordinates:
2110+
Upper Left ( 827294.141, 523985.644) ( 2d59' 3.48"E, 46d58'37.71"N)
2111+
Lower Left ( 827294.141, 523980.638) ( 2d59' 3.47"E, 46d58'37.54"N)
2112+
Upper Right ( 827299.148, 523985.644) ( 2d59' 3.71"E, 46d58'37.70"N)
2113+
Lower Right ( 827299.148, 523980.638) ( 2d59' 3.71"E, 46d58'37.54"N)
2114+
Center ( 827296.645, 523983.141) ( 2d59' 3.59"E, 46d58'37.62"N)
2115+

0 commit comments

Comments
 (0)