Skip to content

Commit

Permalink
Merge pull request #10185 from rouault/identify_allowed_drivers
Browse files Browse the repository at this point in the history
Multiple drivers: relax identification checks
  • Loading branch information
rouault committed Jun 18, 2024
2 parents 0decb44 + a3eeabf commit 8979e64
Show file tree
Hide file tree
Showing 90 changed files with 1,674 additions and 457 deletions.
20 changes: 20 additions & 0 deletions autotest/gdrivers/bag.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,3 +1193,23 @@ def test_bag_write_values_at_nodata():
ds = None

gdal.Unlink(tmpfilename)


###############################################################################
# Test force opening


def test_bag_force_opening():

drv = gdal.IdentifyDriverEx("data/netcdf/trmm-nc4.nc", allowed_drivers=["BAG"])
assert drv.GetDescription() == "BAG"


###############################################################################
# Test force opening, but provided file is still not recognized (for good reasons)


def test_bag_force_opening_no_match():

drv = gdal.IdentifyDriverEx("data/byte.tif", allowed_drivers=["BAG"])
assert drv is None
215 changes: 215 additions & 0 deletions autotest/gdrivers/data/wms/demo_mapserver_org.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
<?xml version='1.0' encoding="UTF-8" standalone="no" ?>
<WMS_Capabilities version="1.3.0" xmlns="http://www.opengis.net/wms" xmlns:sld="http://www.opengis.net/sld" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ms="http://mapserver.gis.umn.edu/mapserver" xsi:schemaLocation="http://www.opengis.net/wms http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/sld_capabilities.xsd http://mapserver.gis.umn.edu/mapserver https://demo.mapserver.org/cgi-bin/wms?service=WMS&amp;version=1.3.0&amp;request=GetSchemaExtension">
<Service>
<Name>WMS</Name>
<Title>WMS Demo Server for MapServer</Title>
<Abstract>This demonstration server showcases MapServer (www.mapserver.org) and its OGC support</Abstract>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://demo.mapserver.org/cgi-bin/wms?"/>
<ContactInformation>
<ContactPersonPrimary>
<ContactPerson>Jeff McKenna</ContactPerson>
<ContactOrganization>GatewayGeo</ContactOrganization>
</ContactPersonPrimary>
<ContactPosition>Director</ContactPosition>
<ContactElectronicMailAddress>info@gatewaygeomatics.com</ContactElectronicMailAddress>
</ContactInformation>
<MaxWidth>4096</MaxWidth>
<MaxHeight>4096</MaxHeight>
</Service>

<Capability>
<Request>
<GetCapabilities>
<Format>text/xml</Format>
<DCPType>
<HTTP>
<Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://demo.mapserver.org/cgi-bin/wms?"/></Get>
<Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://demo.mapserver.org/cgi-bin/wms?"/></Post>
</HTTP>
</DCPType>
</GetCapabilities>
<GetMap>
<Format>image/png</Format>
<Format>image/jpeg</Format>
<Format>image/png; mode=8bit</Format>
<Format>image/vnd.jpeg-png</Format>
<Format>image/vnd.jpeg-png8</Format>
<Format>application/x-pdf</Format>
<Format>image/svg+xml</Format>
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<Format>application/vnd.mapbox-vector-tile</Format>
<Format>application/x-protobuf</Format>
<Format>application/json</Format>
<DCPType>
<HTTP>
<Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://demo.mapserver.org/cgi-bin/wms?"/></Get>
<Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://demo.mapserver.org/cgi-bin/wms?"/></Post>
</HTTP>
</DCPType>
</GetMap>
<GetFeatureInfo>
<Format>text/html</Format>
<Format>application/vnd.ogc.gml</Format>
<Format>text/plain</Format>
<DCPType>
<HTTP>
<Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://demo.mapserver.org/cgi-bin/wms?"/></Get>
<Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://demo.mapserver.org/cgi-bin/wms?"/></Post>
</HTTP>
</DCPType>
</GetFeatureInfo>
<sld:DescribeLayer>
<Format>text/xml</Format>
<DCPType>
<HTTP>
<Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://demo.mapserver.org/cgi-bin/wms?"/></Get>
<Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://demo.mapserver.org/cgi-bin/wms?"/></Post>
</HTTP>
</DCPType>
</sld:DescribeLayer>
<sld:GetLegendGraphic>
<Format>image/png</Format>
<Format>image/jpeg</Format>
<Format>image/png; mode=8bit</Format>
<Format>image/vnd.jpeg-png</Format>
<Format>image/vnd.jpeg-png8</Format>
<DCPType>
<HTTP>
<Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://demo.mapserver.org/cgi-bin/wms?"/></Get>
<Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://demo.mapserver.org/cgi-bin/wms?"/></Post>
</HTTP>
</DCPType>
</sld:GetLegendGraphic>
<ms:GetStyles>
<Format>text/xml</Format>
<DCPType>
<HTTP>
<Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://demo.mapserver.org/cgi-bin/wms?"/></Get>
<Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://demo.mapserver.org/cgi-bin/wms?"/></Post>
</HTTP>
</DCPType>
</ms:GetStyles>
</Request>
<Exception>
<Format>XML</Format>
<Format>INIMAGE</Format>
<Format>BLANK</Format>
</Exception>
<sld:UserDefinedSymbolization SupportSLD="1" UserLayer="0" UserStyle="1" RemoteWFS="0" InlineFeature="0" RemoteWCS="0"/>
<Layer queryable="1">
<Name>WMS_server</Name>
<Title>WMS Demo Server for MapServer</Title>
<Abstract>This demonstration server showcases MapServer (www.mapserver.org) and its OGC support</Abstract>
<CRS>EPSG:4326</CRS>
<CRS>EPSG:4269</CRS>
<CRS>EPSG:3978</CRS>
<CRS>EPSG:3857</CRS>
<EX_GeographicBoundingBox>
<westBoundLongitude>-180.000000</westBoundLongitude>
<eastBoundLongitude>180.000000</eastBoundLongitude>
<southBoundLatitude>-90.000000</southBoundLatitude>
<northBoundLatitude>90.000000</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox CRS="EPSG:4326"
minx="-90.000000" miny="-180.000000" maxx="90.000000" maxy="180.000000" />
<Layer queryable="0" opaque="0" cascaded="0">
<Name>bluemarble</Name>
<Title>Blue Marble World Elevation and Bathymetry Raster</Title>
<CRS>EPSG:4326</CRS>
<EX_GeographicBoundingBox>
<westBoundLongitude>-180.000000</westBoundLongitude>
<eastBoundLongitude>180.000000</eastBoundLongitude>
<southBoundLatitude>-90.000000</southBoundLatitude>
<northBoundLatitude>90.000000</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox CRS="EPSG:4326"
minx="-90.000000" miny="-180.000000" maxx="90.000000" maxy="180.000000" />
<Attribution>
<Title>NASA Blue Marble</Title>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://earthobservatory.nasa.gov/Features/BlueMarble/"/>
</Attribution>
<MetadataURL type="TC211">
<Format>text/xml</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="https://demo.mapserver.org/cgi-bin/wms?request=GetMetadata&amp;layer=bluemarble"/>
</MetadataURL>
</Layer>
<Layer queryable="0" opaque="0" cascaded="0">
<Name>continents</Name>
<Title>World continents</Title>
<CRS>EPSG:4326</CRS>
<EX_GeographicBoundingBox>
<westBoundLongitude>-180.000000</westBoundLongitude>
<eastBoundLongitude>180.000000</eastBoundLongitude>
<southBoundLatitude>-90.000000</southBoundLatitude>
<northBoundLatitude>83.627419</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox CRS="EPSG:4326"
minx="-90.000000" miny="-180.000000" maxx="83.627419" maxy="180.000000" />
<MetadataURL type="TC211">
<Format>text/xml</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="https://demo.mapserver.org/cgi-bin/wms?request=GetMetadata&amp;layer=continents"/>
</MetadataURL>
<Style>
<Name>default</Name>
<Title>default</Title>
<LegendURL width="121" height="112">
<Format>image/png</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="https://demo.mapserver.org/cgi-bin/wms?version=1.3.0&amp;service=WMS&amp;request=GetLegendGraphic&amp;sld_version=1.1.0&amp;layer=continents&amp;format=image/png&amp;STYLE=default"/>
</LegendURL>
</Style>
</Layer>
<Layer queryable="0" opaque="0" cascaded="0">
<Name>country_bounds</Name>
<Title>World country boundaries</Title>
<CRS>EPSG:4326</CRS>
<EX_GeographicBoundingBox>
<westBoundLongitude>-180.000000</westBoundLongitude>
<eastBoundLongitude>180.000000</eastBoundLongitude>
<southBoundLatitude>-90.000000</southBoundLatitude>
<northBoundLatitude>83.627419</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox CRS="EPSG:4326"
minx="-90.000000" miny="-180.000000" maxx="83.627419" maxy="180.000000" />
<MetadataURL type="TC211">
<Format>text/xml</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="https://demo.mapserver.org/cgi-bin/wms?request=GetMetadata&amp;layer=country_bounds"/>
</MetadataURL>
<Style>
<Name>default</Name>
<Title>default</Title>
<LegendURL width="142" height="23">
<Format>image/png</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="https://demo.mapserver.org/cgi-bin/wms?version=1.3.0&amp;service=WMS&amp;request=GetLegendGraphic&amp;sld_version=1.1.0&amp;layer=country_bounds&amp;format=image/png&amp;STYLE=default"/>
</LegendURL>
</Style>
</Layer>
<Layer queryable="1" opaque="0" cascaded="0">
<Name>cities</Name>
<Title>World cities</Title>
<CRS>EPSG:4326</CRS>
<EX_GeographicBoundingBox>
<westBoundLongitude>-178.166667</westBoundLongitude>
<eastBoundLongitude>179.383333</eastBoundLongitude>
<southBoundLatitude>-54.800000</southBoundLatitude>
<northBoundLatitude>78.933333</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox CRS="EPSG:4326"
minx="-54.800000" miny="-178.166667" maxx="78.933333" maxy="179.383333" />
<MetadataURL type="TC211">
<Format>text/xml</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="https://demo.mapserver.org/cgi-bin/wms?request=GetMetadata&amp;layer=cities"/>
</MetadataURL>
<Style>
<Name>default</Name>
<Title>default</Title>
<LegendURL width="192" height="41">
<Format>image/png</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="https://demo.mapserver.org/cgi-bin/wms?version=1.3.0&amp;service=WMS&amp;request=GetLegendGraphic&amp;sld_version=1.1.0&amp;layer=cities&amp;format=image/png&amp;STYLE=default"/>
</LegendURL>
</Style>
</Layer>
</Layer>
</Capability>
</WMS_Capabilities>
8 changes: 6 additions & 2 deletions autotest/gdrivers/gti.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,17 @@ def check_basic(

def test_gti_no_metadata(tmp_vsimem):

index_filename = str(tmp_vsimem / "index.gti.gpkg")
index_filename = str(tmp_vsimem / "index.gpkg")

src_ds = gdal.Open(os.path.join(os.getcwd(), "data", "byte.tif"))
index_ds, _ = create_basic_tileindex(index_filename, src_ds)
del index_ds

vrt_ds = gdal.Open(index_filename)
with pytest.raises(Exception):
gdal.Open(index_filename)

vrt_ds = gdal.OpenEx(index_filename, allowed_drivers=["GTI"])
assert vrt_ds.GetDriver().GetDescription() == "GTI"
check_basic(vrt_ds, src_ds)
assert (
vrt_ds.GetMetadataItem("SCANNED_ONE_FEATURE_AT_OPENING", "__DEBUG__") == "YES"
Expand Down
25 changes: 25 additions & 0 deletions autotest/gdrivers/hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -1608,3 +1608,28 @@ def test_hdf5_read_netcdf_nodata_scale_offset():
assert band.GetNoDataValue() == pytest.approx(9.96921e36, rel=1e-7)
assert band.GetOffset() == 1.5
assert band.GetScale() == 0.01


###############################################################################
# Test force opening a netCDF file with HDF5 driver


def test_hdf5_force_opening_netcdf_file():

ds = gdal.OpenEx("data/netcdf/trmm-nc4.nc", allowed_drivers=["HDF5"])
assert ds.GetDriver().GetDescription() == "HDF5Image"

ds = gdal.OpenEx(
"data/netcdf/byte_hdf5_starting_at_offset_1024.nc", allowed_drivers=["HDF5"]
)
assert ds.GetDriver().GetDescription() == "HDF5Image"


###############################################################################
# Test force opening, but provided file is still not recognized (for good reasons)


def test_hdf5_force_opening_no_match():

drv = gdal.IdentifyDriverEx("data/byte.tif", allowed_drivers=["HDF5"])
assert drv is None
23 changes: 23 additions & 0 deletions autotest/gdrivers/netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6524,3 +6524,26 @@ def test_netcdf_create_metadata_with_equal_sign(tmp_path):

ds = gdal.Open(fname)
assert ds.GetRasterBand(1).GetMetadataItem("long_name") == value


###############################################################################
# Test force opening a HDF55 file with netCDF driver


def test_netcdf_force_opening_hdf5_file(tmp_vsimem):

ds = gdal.OpenEx("data/hdf5/groups.h5", allowed_drivers=["netCDF"])
assert ds.GetDriver().GetDescription() == "netCDF"

ds = gdal.Open(ds.GetSubDatasets()[0][0])
assert ds.GetDriver().GetDescription() == "netCDF"


###############################################################################
# Test force opening, but provided file is still not recognized (for good reasons)


def test_netcdf_force_opening_no_match():

drv = gdal.IdentifyDriverEx("data/byte.tif", allowed_drivers=["netCDF"])
assert drv is None
3 changes: 2 additions & 1 deletion autotest/gdrivers/ogcapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,14 +455,15 @@ def test_ogc_api_raster_tiles():
def test_ogc_api_raster_tiles_format(image_format, raster_count, statistics):

ds = gdal.OpenEx(
f"OGCAPI:http://127.0.0.1:{gdaltest.webserver_port}/fakeogcapi/collections/blueMarble",
f"http://127.0.0.1:{gdaltest.webserver_port}/fakeogcapi/collections/blueMarble",
gdal.OF_RASTER,
open_options=[
"API=TILES",
"CACHE=NO",
"TILEMATRIXSET=WorldMercatorWGS84Quad",
f"IMAGE_FORMAT={image_format}",
],
allowed_drivers=["OGCAPI"],
)

assert ds is not None
Expand Down
20 changes: 20 additions & 0 deletions autotest/gdrivers/s102.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,23 @@ def test_s102_QualityOfSurvey_multidim():
x_data = struct.unpack("d" * x.GetDimensions()[0].GetSize(), x.Read())
assert x_data[0] == 2.0
assert x_data[-1] == 2.8


###############################################################################
# Test force opening


def test_s102_force_opening():

drv = gdal.IdentifyDriverEx("data/hdf5/groups.h5", allowed_drivers=["S102"])
assert drv.GetDescription() == "S102"


###############################################################################
# Test force opening, but provided file is still not recognized (for good reasons)


def test_s102_force_opening_no_match():

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

0 comments on commit 8979e64

Please sign in to comment.