Skip to content

Commit

Permalink
S102: make sure to report a subdataset for the bathymetry coverage wh…
Browse files Browse the repository at this point in the history
…en we expose one for the georeferenced metadata
  • Loading branch information
rouault committed Mar 18, 2024
1 parent 3206df7 commit 830a7f6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
15 changes: 14 additions & 1 deletion autotest/gdrivers/s102.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,31 @@ def test_s102_QualityOfSurvey():

ds = gdal.Open("data/s102/test_s102_v2.2_with_QualityOfSurvey.h5")
assert ds.GetSubDatasets() == [
(
'S102:"data/s102/test_s102_v2.2_with_QualityOfSurvey.h5":BathymetryCoverage',
"Bathymetric gridded data",
),
(
'S102:"data/s102/test_s102_v2.2_with_QualityOfSurvey.h5":QualityOfSurvey',
"Georeferenced metadata QualityOfSurvey",
)
),
]

with pytest.raises(Exception, match="Unsupported subdataset component"):
gdal.Open('S102:"data/s102/test_s102_v2.2_with_QualityOfSurvey.h5":invalid')

ds = gdal.Open(
'S102:"data/s102/test_s102_v2.2_with_QualityOfSurvey.h5":BathymetryCoverage'
)
assert len(ds.GetSubDatasets()) == 0
assert ds.RasterCount == 2
assert ds.RasterXSize == 3
assert ds.RasterYSize == 2

ds = gdal.Open(
'S102:"data/s102/test_s102_v2.2_with_QualityOfSurvey.h5":QualityOfSurvey'
)
assert len(ds.GetSubDatasets()) == 0
assert ds.RasterCount == 1
assert ds.RasterXSize == 3
assert ds.RasterYSize == 2
Expand Down
20 changes: 17 additions & 3 deletions frmts/hdf5/s102dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ GDALDataset *S102Dataset::Open(GDALOpenInfo *poOpenInfo)
}

std::string osFilename(poOpenInfo->pszFilename);
bool bIsSubdataset = false;
bool bIsQualityOfSurvey = false;
if (STARTS_WITH(poOpenInfo->pszFilename, "S102:"))
{
Expand All @@ -180,8 +181,13 @@ GDALDataset *S102Dataset::Open(GDALOpenInfo *poOpenInfo)
}
else if (aosTokens.size() == 3)
{
bIsSubdataset = true;
osFilename = aosTokens[1];
if (EQUAL(aosTokens[2], "QualityOfSurvey"))
if (EQUAL(aosTokens[2], "BathymetryCoverage"))
{
// Default dataset
}
else if (EQUAL(aosTokens[2], "QualityOfSurvey"))
{
bIsQualityOfSurvey = true;
}
Expand Down Expand Up @@ -370,18 +376,26 @@ GDALDataset *S102Dataset::Open(GDALOpenInfo *poOpenInfo)
poDS->GDALDataset::SetMetadataItem(GDALMD_AREA_OR_POINT, GDALMD_AOP_POINT);

auto poGroupQualityOfSurvey = poRootGroup->OpenGroup("QualityOfSurvey");
if (poGroupQualityOfSurvey)
if (!bIsSubdataset && poGroupQualityOfSurvey)
{
auto poGroupQualityOfSurvey01 =
poGroupQualityOfSurvey->OpenGroup("QualityOfSurvey.01");
if (poGroupQualityOfSurvey01)
{
poDS->GDALDataset::SetMetadataItem(
"SUBDATASET_1_NAME",
CPLSPrintf("S102:\"%s\":BathymetryCoverage",
osFilename.c_str()),
"SUBDATASETS");
poDS->GDALDataset::SetMetadataItem(
"SUBDATASET_1_DESC", "Bathymetric gridded data", "SUBDATASETS");

poDS->GDALDataset::SetMetadataItem(
"SUBDATASET_2_NAME",
CPLSPrintf("S102:\"%s\":QualityOfSurvey", osFilename.c_str()),
"SUBDATASETS");
poDS->GDALDataset::SetMetadataItem(
"SUBDATASET_1_DESC", "Georeferenced metadata QualityOfSurvey",
"SUBDATASET_2_DESC", "Georeferenced metadata QualityOfSurvey",
"SUBDATASETS");
}
}
Expand Down

0 comments on commit 830a7f6

Please sign in to comment.