Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport release/3.10] Assorted set of fixes for WMTS issue #11412

Merged
merged 3 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<Capabilities xmlns="http://www.opengis.net/wmts/1.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml" xsi:schemaLocation="http://www.opengis.net/wmts/1.0 http://schemas.opengis.net/wmts/1.0/wmtsGetCapabilities_response.xsd" version="1.0.0">
<!-- Service Identification -->
<ows:ServiceIdentification>
<ows:Title>THEMIS_NightIR_ControlledMosaics_100m_v2_oct2018</ows:Title>
<ows:ServiceType>OGC WMTS</ows:ServiceType>
<ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion>
</ows:ServiceIdentification> <!-- Operations Metadata -->
<ows:OperationsMetadata>
<ows:Operation name="GetCapabilities">
<ows:DCP>
<ows:HTTP>
<ows:Get xlink:href="https://trek.nasa.gov/tiles/Mars/EQ/THEMIS_NightIR_ControlledMosaics_100m_v2_oct2018/1.0.0/WMTSCapabilities.xml">
<ows:Constraint name="GetEncoding">
<ows:AllowedValues>
<ows:Value>RESTful</ows:Value>
</ows:AllowedValues>
</ows:Constraint>
</ows:Get>

</ows:HTTP>
</ows:DCP>
</ows:Operation>
<ows:Operation name="GetTile">
<ows:DCP>
<ows:HTTP>
<ows:Get xlink:href="https://trek.nasa.gov/tiles/Mars/EQ/THEMIS_NightIR_ControlledMosaics_100m_v2_oct2018/1.0.0/">
<ows:Constraint name="GetEncoding">
<ows:AllowedValues>
<ows:Value>RESTful</ows:Value>
</ows:AllowedValues>
</ows:Constraint>
</ows:Get>

</ows:HTTP>
</ows:DCP>
</ows:Operation>
</ows:OperationsMetadata>
<Contents>
<!--Layer-->
<Layer>
<ows:Title>THEMIS_NightIR_ControlledMosaics_100m_v2_oct2018</ows:Title>
<ows:Identifier>THEMIS_NightIR_ControlledMosaics_100m_v2_oct2018</ows:Identifier>
<ows:BoundingBox crs="urn:ogc:def:crs:EPSG::104905">
<ows:LowerCorner>-179.9999997 -65.0006576</ows:LowerCorner>
<ows:UpperCorner>179.9998849 65.0007535</ows:UpperCorner>
</ows:BoundingBox>
<ows:WGS84BoundingBox crs="urn:ogc:def:crs:OGC:2:84">
<ows:LowerCorner>-179.9999997 -65.0006576</ows:LowerCorner>
<ows:UpperCorner>179.9998849 65.0007535</ows:UpperCorner>
</ows:WGS84BoundingBox>

<Style isDefault="true">
<ows:Title>Default Style</ows:Title>
<ows:Identifier>default</ows:Identifier>
</Style>
<Format>image/png</Format>
<TileMatrixSetLink>
<TileMatrixSet>default028mm</TileMatrixSet>
</TileMatrixSetLink>
<ResourceURL format="image/png" resourceType="tile" template="https://trek.nasa.gov/tiles/Mars/EQ/THEMIS_NightIR_ControlledMosaics_100m_v2_oct2018/1.0.0//{Style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png"/>
</Layer> <!--TileMatrixSet-->
<TileMatrixSet>
<ows:Title>default</ows:Title>
<ows:Abstract>The tile matrix set that has scale values calculated based on the dpi defined by OGC specification (dpi assumes 0.28mm as the physical distance of a pixel).</ows:Abstract>
<ows:Identifier>default028mm</ows:Identifier>
<ows:SupportedCRS>urn:ogc:def:crs:EPSG::104905</ows:SupportedCRS>
<TileMatrix><ows:Identifier>0</ows:Identifier><ScaleDenominator>2.7922763629807472E+08</ScaleDenominator><TopLeftCorner>-180.0 90.0</TopLeftCorner><TileWidth>256</TileWidth><TileHeight>256</TileHeight><MatrixWidth>2.0</MatrixWidth><MatrixHeight>1.0</MatrixHeight></TileMatrix>
<TileMatrix><ows:Identifier>1</ows:Identifier><ScaleDenominator>1.3961381814903736E+08</ScaleDenominator><TopLeftCorner>-180.0 90.0</TopLeftCorner><TileWidth>256</TileWidth><TileHeight>256</TileHeight><MatrixWidth>4.0</MatrixWidth><MatrixHeight>2.0</MatrixHeight></TileMatrix>
<TileMatrix><ows:Identifier>2</ows:Identifier><ScaleDenominator>6.9806909074518681E+07</ScaleDenominator><TopLeftCorner>-180.0 90.0</TopLeftCorner><TileWidth>256</TileWidth><TileHeight>256</TileHeight><MatrixWidth>8.0</MatrixWidth><MatrixHeight>4.0</MatrixHeight></TileMatrix>
<TileMatrix><ows:Identifier>3</ows:Identifier><ScaleDenominator>3.4903454537259340E+07</ScaleDenominator><TopLeftCorner>-180.0 90.0</TopLeftCorner><TileWidth>256</TileWidth><TileHeight>256</TileHeight><MatrixWidth>16.0</MatrixWidth><MatrixHeight>8.0</MatrixHeight></TileMatrix>
<TileMatrix><ows:Identifier>4</ows:Identifier><ScaleDenominator>1.7451727268629670E+07</ScaleDenominator><TopLeftCorner>-180.0 90.0</TopLeftCorner><TileWidth>256</TileWidth><TileHeight>256</TileHeight><MatrixWidth>32.0</MatrixWidth><MatrixHeight>16.0</MatrixHeight></TileMatrix>
<TileMatrix><ows:Identifier>5</ows:Identifier><ScaleDenominator>8.7258636343148351E+06</ScaleDenominator><TopLeftCorner>-180.0 90.0</TopLeftCorner><TileWidth>256</TileWidth><TileHeight>256</TileHeight><MatrixWidth>64.0</MatrixWidth><MatrixHeight>32.0</MatrixHeight></TileMatrix>
<TileMatrix><ows:Identifier>6</ows:Identifier><ScaleDenominator>4.3629318171574175E+06</ScaleDenominator><TopLeftCorner>-180.0 90.0</TopLeftCorner><TileWidth>256</TileWidth><TileHeight>256</TileHeight><MatrixWidth>128.0</MatrixWidth><MatrixHeight>64.0</MatrixHeight></TileMatrix>
<TileMatrix><ows:Identifier>7</ows:Identifier><ScaleDenominator>2.1814659085787088E+06</ScaleDenominator><TopLeftCorner>-180.0 90.0</TopLeftCorner><TileWidth>256</TileWidth><TileHeight>256</TileHeight><MatrixWidth>256.0</MatrixWidth><MatrixHeight>128.0</MatrixHeight></TileMatrix>
<TileMatrix><ows:Identifier>8</ows:Identifier><ScaleDenominator>1.0907329542893544E+06</ScaleDenominator><TopLeftCorner>-180.0 90.0</TopLeftCorner><TileWidth>256</TileWidth><TileHeight>256</TileHeight><MatrixWidth>512.0</MatrixWidth><MatrixHeight>256.0</MatrixHeight></TileMatrix>
<TileMatrix><ows:Identifier>9</ows:Identifier><ScaleDenominator>5.4536647714467719E+05</ScaleDenominator><TopLeftCorner>-180.0 90.0</TopLeftCorner><TileWidth>256</TileWidth><TileHeight>256</TileHeight><MatrixWidth>1024.0</MatrixWidth><MatrixHeight>512.0</MatrixHeight></TileMatrix>

<!--<TileMatrix>
<ows:Identifier>0</ows:Identifier>
<ScaleDenominator>2.3623511904761901E8</ScaleDenominator>
<TopLeftCorner>-180.0 90.0</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>3</MatrixWidth>
<MatrixHeight>2</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>1</ows:Identifier>
<ScaleDenominator>1.1811755952380951E8</ScaleDenominator>
<TopLeftCorner>-180.0 90.0</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>5</MatrixWidth>
<MatrixHeight>3</MatrixHeight>
</TileMatrix>
-->

</TileMatrixSet>
</Contents>
<ServiceMetadataURL xlink:href="https://trek.nasa.gov/tiles/Mars/EQ/THEMIS_NightIR_ControlledMosaics_100m_v2_oct2018/1.0.0/WMTSCapabilities.xml"/>
</Capabilities>
29 changes: 29 additions & 0 deletions autotest/gdrivers/wmts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2002,3 +2002,32 @@ def test_wmts_force_opening_no_match():

drv = gdal.IdentifyDriverEx("data/byte.tif", allowed_drivers=["WMTS"])
assert drv is None


###############################################################################
# Test bug fix for https://github.com/OSGeo/gdal/issues/11387


@pytest.mark.require_proj(9)
@gdaltest.enable_exceptions()
def test_wmts_read_esri_code_disguised_as_epsg_and_wrong_axis_order():

with gdaltest.error_handler():
with gdal.Open(
"data/wmts/WMTSCapabilities_THEMIS_NightIR_ControlledMosaics_100m_v2_oct2018.xml"
) as ds:
assert gdal.GetLastErrorMsg().startswith(
"Auto-correcting wrongly swapped TileMatrix.TopLeftCorner coordinates"
)
assert ds.GetSpatialRef().GetAuthorityName(None) == "ESRI"
assert ds.GetSpatialRef().GetAuthorityCode(None) == "104905"
assert ds.GetGeoTransform() == pytest.approx(
(
-180.0,
0.0013717509172233527,
0.0,
65.00121128452162,
0.0,
-0.0013717509172233527,
)
)
28 changes: 28 additions & 0 deletions autotest/osr/osr_epsg.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,3 +545,31 @@ def test_osr_epsg_EPSGTreatsAsLatLong_for_CompoundCRS():
srs = osr.SpatialReference()
srs.ImportFromEPSG(6697)
assert srs.EPSGTreatsAsLatLong() == 1


###############################################################################
# Test importing a ESRI code as a EPSG code


@pytest.mark.require_proj(9)
def test_osr_epsg_import_esri_code():

srs = osr.SpatialReference()
with gdal.quiet_errors():
srs.ImportFromEPSG(104905)

assert srs.GetAuthorityName(None) == "ESRI"
assert srs.GetAuthorityCode(None) == "104905"


###############################################################################
# Test importing a non-existent ESRI code presented as a EPSG code


def test_osr_epsg_import_invalid_code_that_might_have_been_esri():

srs = osr.SpatialReference()
with pytest.raises(
Exception, match="PROJ: proj_create_from_database: crs not found"
):
srs.ImportFromEPSG(987654)
35 changes: 26 additions & 9 deletions frmts/http/httpdriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* SPDX-License-Identifier: MIT
****************************************************************************/

#include "cpl_error_internal.h"
#include "cpl_string.h"
#include "cpl_http.h"
#include "gdal_frmts.h"
Expand Down Expand Up @@ -133,11 +134,27 @@ static GDALDataset *HTTPOpen(GDALOpenInfo *poOpenInfo)
/* Try opening this result as a gdaldataset. */
/* -------------------------------------------------------------------- */
/* suppress errors as not all drivers support /vsimem */
CPLPushErrorHandler(CPLQuietErrorHandler);
GDALDataset *poDS = (GDALDataset *)GDALOpenEx(
osResultFilename, poOpenInfo->nOpenFlags & ~GDAL_OF_SHARED,
poOpenInfo->papszAllowedDrivers, poOpenInfo->papszOpenOptions, nullptr);
CPLPopErrorHandler();

GDALDataset *poDS;
std::vector<CPLErrorHandlerAccumulatorStruct> aoErrors;
{
CPLErrorStateBackuper oBackuper(CPLQuietErrorHandler);
CPLInstallErrorHandlerAccumulator(aoErrors);
poDS = GDALDataset::Open(osResultFilename,
poOpenInfo->nOpenFlags & ~GDAL_OF_SHARED,
poOpenInfo->papszAllowedDrivers,
poOpenInfo->papszOpenOptions, nullptr);
CPLUninstallErrorHandlerAccumulator();
}

// Re-emit silenced errors if open was successful
if (poDS)
{
for (const auto &oError : aoErrors)
{
CPLError(oError.type, oError.no, "%s", oError.msg.c_str());
}
}

// The JP2OpenJPEG driver may need to reopen the file, hence this special
// behavior
Expand Down Expand Up @@ -171,10 +188,10 @@ static GDALDataset *HTTPOpen(GDALOpenInfo *poOpenInfo)
}
else
{
poDS = (GDALDataset *)GDALOpenEx(
osTempFilename, poOpenInfo->nOpenFlags & ~GDAL_OF_SHARED,
poOpenInfo->papszAllowedDrivers, poOpenInfo->papszOpenOptions,
nullptr);
poDS = GDALDataset::Open(osTempFilename,
poOpenInfo->nOpenFlags & ~GDAL_OF_SHARED,
poOpenInfo->papszAllowedDrivers,
poOpenInfo->papszOpenOptions, nullptr);
if (VSIUnlink(osTempFilename) != 0 && poDS != nullptr)
poDS->MarkSuppressOnClose(); /* VSIUnlink() may not work on
windows */
Expand Down
Loading
Loading