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

STACIT: STAC 1.1 support #10773

Closed
wants to merge 3 commits into from
Closed
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
69 changes: 42 additions & 27 deletions frmts/stacit/stacitdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct AssetSetByProjection
struct Asset
{
std::string osName{};
CPLJSONArray eoBands{};
CPLJSONArray bands{};
std::map<std::string, AssetSetByProjection> assets{};
};

Expand Down Expand Up @@ -140,7 +140,8 @@ int STACITDataset::Identify(GDALOpenInfo *poOpenInfo)
}

if (strstr(pszHeader, "\"stac_version\"") != nullptr &&
strstr(pszHeader, "\"proj:transform\"") != nullptr)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is proj:transform checked for? It could appear both in properties or assets so it seems like this check may lead to false results.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The driver requires the projection extension to be there, hence checking for it. And as Identify() needs to be quick (it only has a subset of the JSON and can't use a JSON parser), it doesn't get into the details to figure out where the element is present

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, now I remember what strstr does. I'll revert, thanks.

Copy link
Contributor Author

@m-mohr m-mohr Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs two out of the three proj: properties and transform is one them. So just checking proj:transform seems to exclude cases where proj:bbox and proj:shape are set. Should we update this to check whether one of proj:transform or proj:bbox is present? That should capture all three cases.

fields currently new
transform + shape accepted accepted
transform + bbox accepted accepted
bbox + shape rejected accepted

Maybe worth a separate small PR though, it's unrelated to the STAC 1.1 updates.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth a separate small PR though, it's unrelated to the STAC 1.1 updates.

yes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

taken into account per 8dd8c81

(strstr(pszHeader, "\"proj:transform\"") != nullptr ||
strstr(pszHeader, "\"proj:bbox\"") != nullptr))
{
return true;
}
Expand Down Expand Up @@ -234,34 +235,43 @@ static void ParseAsset(const CPLJSONObject &jAsset,
return oProperties[pszName];
};

auto oProjEPSG = GetAssetOrFeatureProperty("proj:epsg");
std::string osProjUserString;
if (oProjEPSG.IsValid() && oProjEPSG.GetType() != CPLJSONObject::Type::Null)
auto oProjCode = GetAssetOrFeatureProperty("proj:code");
if (oProjCode.IsValid() && oProjCode.GetType() != CPLJSONObject::Type::Null)
{
osProjUserString = "EPSG:" + oProjEPSG.ToString();
osProjUserString = oProjCode.ToString();
}
else
{
auto oProjWKT2 = GetAssetOrFeatureProperty("proj:wkt2");
if (oProjWKT2.IsValid() &&
oProjWKT2.GetType() == CPLJSONObject::Type::String)
auto oProjEPSG = GetAssetOrFeatureProperty("proj:epsg");
if (oProjEPSG.IsValid() &&
oProjEPSG.GetType() != CPLJSONObject::Type::Null)
{
osProjUserString = oProjWKT2.ToString();
osProjUserString = "EPSG:" + oProjEPSG.ToString();
}
else
{
auto oProjPROJJSON = GetAssetOrFeatureProperty("proj:projjson");
if (oProjPROJJSON.IsValid() &&
oProjPROJJSON.GetType() == CPLJSONObject::Type::Object)
auto oProjWKT2 = GetAssetOrFeatureProperty("proj:wkt2");
if (oProjWKT2.IsValid() &&
oProjWKT2.GetType() == CPLJSONObject::Type::String)
{
osProjUserString = oProjPROJJSON.ToString();
osProjUserString = oProjWKT2.ToString();
}
else
{
CPLDebug("STACIT",
"Skipping asset %s that lacks a valid CRS member",
osAssetName.c_str());
return;
auto oProjPROJJSON = GetAssetOrFeatureProperty("proj:projjson");
if (oProjPROJJSON.IsValid() &&
oProjPROJJSON.GetType() == CPLJSONObject::Type::Object)
{
osProjUserString = oProjPROJJSON.ToString();
}
else
{
CPLDebug("STACIT",
"Skipping asset %s that lacks a valid CRS member",
osAssetName.c_str());
return;
}
}
}
}
Expand Down Expand Up @@ -396,7 +406,9 @@ static void ParseAsset(const CPLJSONObject &jAsset,
{
Asset asset;
asset.osName = osAssetName;
asset.eoBands = jAsset.GetArray("eo:bands");
asset.bands = jAsset.GetArray("bands");
if (!asset.bands.IsValid())
asset.bands = jAsset.GetArray("eo:bands");

collection.assets[osAssetName] = std::move(asset);
}
Expand Down Expand Up @@ -594,17 +606,19 @@ bool STACITDataset::SetupDataset(
poVRTBand->SetColorInterpretation(eInterp);

// Set band properties
if (asset.eoBands.IsValid() &&
asset.eoBands.Size() == poItemDS->GetRasterCount())
if (asset.bands.IsValid() &&
asset.bands.Size() == poItemDS->GetRasterCount())
{
const auto &eoBand = asset.eoBands[i];
const auto osBandName = eoBand["name"].ToString();
const auto &band = asset.bands[i];
const auto osBandName = band["name"].ToString();
if (!osBandName.empty())
poVRTBand->SetDescription(osBandName.c_str());

if (eInterp != GCI_Undefined)
{
const auto osCommonName = eoBand["common_name"].ToString();
auto osCommonName = band["eo:common_name"].ToString();
if (osCommonName.empty())
osCommonName = band["common_name"].ToString();
if (osCommonName == "red")
poVRTBand->SetColorInterpretation(GCI_RedBand);
else if (osCommonName == "green")
Expand All @@ -615,13 +629,14 @@ bool STACITDataset::SetupDataset(
poVRTBand->SetColorInterpretation(GCI_AlphaBand);
}

for (const auto &eoBandChild : eoBand.GetChildren())
for (const auto &bandChild : band.GetChildren())
{
const auto osChildName = eoBandChild.GetName();
if (osChildName != "name" && osChildName != "common_name")
const auto osChildName = bandChild.GetName();
if (osChildName != "name" && osChildName != "common_name" &&
osChildName != "eo:common_name")
{
poVRTBand->SetMetadataItem(osChildName.c_str(),
eoBandChild.ToString().c_str());
bandChild.ToString().c_str());
}
}
}
Expand Down
Loading