Skip to content

Commit

Permalink
Merge pull request #10695 from rouault/stacit_single_feature
Browse files Browse the repository at this point in the history
STACIT: support top-level Feature in addition to FeatureCollection
  • Loading branch information
rouault authored Sep 7, 2024
2 parents 072db35 + 267a190 commit f65642c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
17 changes: 17 additions & 0 deletions autotest/gdrivers/stacit.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,20 @@ def test_stacit_force_opening_no_match():

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


###############################################################################
# Test opening a top-level Feature


def test_stacit_single_feature(tmp_vsimem):

j = json.loads(open("data/stacit/test.json", "rb").read())
j = j["features"][0]

filename = str(tmp_vsimem / "feature.json")
with gdaltest.tempfile(filename, json.dumps(j)):
ds = gdal.Open(filename)
assert ds is not None
assert ds.RasterXSize == 20
assert ds.GetRasterBand(1).Checksum() == 4672
14 changes: 11 additions & 3 deletions frmts/stacit/stacitdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,11 +852,19 @@ bool STACITDataset::Open(GDALOpenInfo *poOpenInfo)
return false;
}
const auto oRoot = oDoc.GetRoot();
const auto oFeatures = oRoot.GetArray("features");
auto oFeatures = oRoot.GetArray("features");
if (!oFeatures.IsValid())
{
CPLError(CE_Failure, CPLE_AppDefined, "Missing features");
return false;
if (oRoot.GetString("type") == "Feature")
{
oFeatures = CPLJSONArray();
oFeatures.Add(oRoot);
}
else
{
CPLError(CE_Failure, CPLE_AppDefined, "Missing features");
return false;
}
}
for (const auto &oFeature : oFeatures)
{
Expand Down

0 comments on commit f65642c

Please sign in to comment.