Skip to content

Commit 584d5ad

Browse files
authored
Merge pull request #10192 from rouault/backport-10159-to-release/3.9
[Backport 3.9] Internal libgeotiff: resync with OSGeo/libgeotiff#118
2 parents 35459c9 + d81f52e commit 584d5ad

File tree

7 files changed

+359
-136
lines changed

7 files changed

+359
-136
lines changed
757 Bytes
Binary file not shown.

autotest/gcore/tiff_srs.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,3 +1424,106 @@ def test_tiff_srs_build_compd_crs_name_without_citation():
14241424

14251425
ds = gdal.Open("data/gtiff/compdcrs_no_citation.tif")
14261426
assert ds.GetSpatialRef().GetName() == "WGS 84 / UTM zone 17N + EGM2008 height"
1427+
1428+
1429+
def test_tiff_srs_read_epsg_27563_allgeokeys():
1430+
1431+
ds = gdal.Open("data/gtiff/epsg_27563_allgeokeys.tif")
1432+
srs = ds.GetSpatialRef()
1433+
wkt = srs.ExportToWkt(["FORMAT=WKT2_2019"])
1434+
# deal with differences of precision according to PROJ version
1435+
wkt = wkt.replace("49.0000000000001", "49")
1436+
wkt = wkt.replace("49.0000000000002", "49")
1437+
assert 'PARAMETER["Latitude of natural origin",49,ANGLEUNIT["grad"' in wkt
1438+
assert (
1439+
srs.ExportToProj4()
1440+
== "+proj=lcc +lat_1=44.1 +lat_0=44.1 +lon_0=0 +k_0=0.999877499 +x_0=600000 +y_0=200000 +ellps=clrk80ign +pm=paris +towgs84=-168,-60,320,0,0,0,0 +units=m +no_defs"
1441+
)
1442+
1443+
1444+
def test_tiff_srs_write_read_epsg_27563_only_code(tmp_vsimem):
1445+
1446+
filename = str(tmp_vsimem / "test.tif")
1447+
srs = osr.SpatialReference()
1448+
srs.ImportFromEPSG(27563)
1449+
ds = gdal.GetDriverByName("GTiff").Create(filename, 1, 1)
1450+
ds.SetSpatialRef(srs)
1451+
ds = None
1452+
1453+
ds = gdal.Open(filename)
1454+
srs = ds.GetSpatialRef()
1455+
assert (
1456+
'PARAMETER["Latitude of natural origin",49,ANGLEUNIT["grad"'
1457+
in srs.ExportToWkt(["FORMAT=WKT2_2019"])
1458+
)
1459+
assert (
1460+
srs.ExportToProj4()
1461+
== "+proj=lcc +lat_1=44.1 +lat_0=44.1 +lon_0=0 +k_0=0.999877499 +x_0=600000 +y_0=200000 +ellps=clrk80ign +pm=paris +towgs84=-168,-60,320,0,0,0,0 +units=m +no_defs"
1462+
)
1463+
1464+
1465+
@pytest.mark.parametrize(
1466+
"config_options",
1467+
[
1468+
{},
1469+
{
1470+
"GTIFF_WRITE_ANGULAR_PARAMS_IN_DEGREE": "YES",
1471+
"GTIFF_READ_ANGULAR_PARAMS_IN_DEGREE": "YES",
1472+
},
1473+
],
1474+
)
1475+
def test_tiff_srs_write_read_epsg_27563_full_def(tmp_vsimem, config_options):
1476+
1477+
with gdal.config_options(config_options):
1478+
filename = str(tmp_vsimem / "test.tif")
1479+
srs = osr.SpatialReference()
1480+
srs.SetFromUserInput(
1481+
"""PROJCRS["NTF (Paris) / Lambert Sud France",
1482+
BASEGEOGCRS["NTF (Paris)",
1483+
DATUM["Nouvelle Triangulation Francaise (Paris)",
1484+
ELLIPSOID["Clarke 1880 (IGN)",6378249.2,293.466021293627,
1485+
LENGTHUNIT["metre",1]]],
1486+
PRIMEM["Paris",2.5969213,
1487+
ANGLEUNIT["grad",0.0157079632679489]],
1488+
ID["EPSG",4807]],
1489+
CONVERSION["Lambert Sud France",
1490+
METHOD["Lambert Conic Conformal (1SP)",
1491+
ID["EPSG",9801]],
1492+
PARAMETER["Latitude of natural origin",49,
1493+
ANGLEUNIT["grad",0.0157079632679489],
1494+
ID["EPSG",8801]],
1495+
PARAMETER["Longitude of natural origin",0,
1496+
ANGLEUNIT["grad",0.0157079632679489],
1497+
ID["EPSG",8802]],
1498+
PARAMETER["Scale factor at natural origin",0.999877499,
1499+
SCALEUNIT["unity",1],
1500+
ID["EPSG",8805]],
1501+
PARAMETER["False easting",600000,
1502+
LENGTHUNIT["metre",1],
1503+
ID["EPSG",8806]],
1504+
PARAMETER["False northing",200000,
1505+
LENGTHUNIT["metre",1],
1506+
ID["EPSG",8807]]],
1507+
CS[Cartesian,2],
1508+
AXIS["easting (X)",east,
1509+
ORDER[1],
1510+
LENGTHUNIT["metre",1]],
1511+
AXIS["northing (Y)",north,
1512+
ORDER[2],
1513+
LENGTHUNIT["metre",1]]]"""
1514+
)
1515+
ds = gdal.GetDriverByName("GTiff").Create(filename, 1, 1)
1516+
ds.SetSpatialRef(srs)
1517+
ds = None
1518+
1519+
ds = gdal.Open(filename)
1520+
srs = ds.GetSpatialRef()
1521+
wkt = srs.ExportToWkt(["FORMAT=WKT2_2019"])
1522+
# deal with differences of precision according to PROJ version
1523+
wkt = wkt.replace("49.0000000000001", "49")
1524+
wkt = wkt.replace("49.0000000000002", "49")
1525+
assert 'PARAMETER["Latitude of natural origin",49,ANGLEUNIT["grad"' in wkt
1526+
assert (
1527+
srs.ExportToProj4()
1528+
== "+proj=lcc +lat_1=44.1 +lat_0=44.1 +lon_0=0 +k_0=0.999877499 +x_0=600000 +y_0=200000 +ellps=clrk80ign +pm=paris +units=m +no_defs"
1529+
)

doc/source/drivers/raster/gtiff.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,34 @@ the default behavior of the GTiff driver.
11171117
expected to be necessary, unless GDAL is incorrectly determining the disk
11181118
space available on the destination file system.
11191119

1120+
- .. config:: GTIFF_READ_ANGULAR_PARAMS_IN_DEGREE
1121+
:choices: YES, NO
1122+
:default: NO
1123+
:since: 3.9.1
1124+
1125+
Conformant GeoTIFF files should have the values of angular projection
1126+
parameters written in the unit of the GeogAngularUnitsGeoKey. But some
1127+
non-conformant implementations, such as GDAL <= 3.9.0, always wrote them
1128+
in degrees.
1129+
This option can be set to YES when reading such non-conformant GeoTIFF
1130+
files (typically using grads), to instruct GDAL (>= 3.9.1) that the projection
1131+
parameters are in degrees, instead of being expressed in the unit of the
1132+
GeogAngularUnitsGeoKey.
1133+
1134+
- .. config:: GTIFF_WRITE_ANGULAR_PARAMS_IN_DEGREE
1135+
:choices: YES, NO
1136+
:default: NO
1137+
:since: 3.9.1
1138+
1139+
Conformant GeoTIFF files should have the values of angular projection
1140+
parameters written in the unit of the GeogAngularUnitsGeoKey. But some
1141+
non-conformant implementations, such as GDAL >= 3.0 and <= 3.9.0, assumed
1142+
those values to be in degree.
1143+
This option can be set to YES to force writing such non-conformant GeoTIFF
1144+
files. It should *not* be nominally used, except to workaround interoperability
1145+
issues.
1146+
1147+
11201148
Codec Recommendations
11211149
---------------------
11221150

0 commit comments

Comments
 (0)