Skip to content

Commit

Permalink
Merge pull request #13 from m-mohr/main
Browse files Browse the repository at this point in the history
Cater for optional fields #12
  • Loading branch information
Tom Augspurger committed Jul 12, 2023
2 parents 1fc0a4d + 84a916c commit 8009fb0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion stac_geoparquet/pgstac_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ def make_pgstac_items(
item["bbox"] = list(geom.bounds)

item["assets"] = content["assets"]
item["stac_extensions"] = content["stac_extensions"]
if "stac_extensions" in content:
item["stac_extensions"] = content["stac_extensions"]
item["properties"] = content["properties"]

pypgstac.hydration.hydrate(base_item, item)
Expand Down
8 changes: 7 additions & 1 deletion stac_geoparquet/stac_geoparquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,15 @@ def to_geodataframe(items: Sequence[dict[str, Any]]) -> geopandas.GeoDataFrame:
"assets",
"collection",
]
opt_columns = ["stac_extensions", "collection"]
for col in opt_columns:
if col not in gdf.columns:
columns.remove(col)

gdf = pd.concat([gdf[columns], gdf.drop(columns=columns)], axis="columns")
for k in ["type", "stac_version", "id", "collection"]:
gdf[k] = gdf[k].astype("string")
if k in gdf:
gdf[k] = gdf[k].astype("string")

return gdf

Expand Down
11 changes: 9 additions & 2 deletions tests/test_stac_geoparquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_assert_equal():
"https://planetarycomputer.microsoft.com/api/stac/v1/collections/sentinel-2-l2a/items/S2B_MSIL2A_20220612T182919_R027_T24XWR_20220613T123251" # noqa: E501
)
b = pystac.read_file(
"https://planetarycomputer.microsoft.com/api/stac/v1/collections/landsat-8-c2-l2/items/LC08_L2SP_202033_20220327_02_T1" # noqa: E501
"https://planetarycomputer.microsoft.com/api/stac/v1/collections/landsat-c2-l2/items/LC08_L2SP_202033_20220327_02_T1" # noqa: E501
)
with pytest.raises(AssertionError):
assert_equal(a, b)
Expand Down Expand Up @@ -233,7 +233,8 @@ def test_to_geodataframe():
}
)
for k in ["type", "stac_version", "id", "collection"]:
expected[k] = expected[k].astype("string")
if k in expected:
expected[k] = expected[k].astype("string")

pandas.testing.assert_frame_equal(result, expected)

Expand All @@ -247,6 +248,12 @@ def test_s1_grd():
item = requests.get(
"https://planetarycomputer.microsoft.com/api/stac/v1/collections/sentinel-1-grd/items/S1A_EW_GRDM_1SSH_20150129T081916_20150129T081938_004383_005598" # noqa: E501
).json()

# pystac migrates EO extension to latest version, but PC is still on 1.0.0
for i, ext in enumerate(item["stac_extensions"]):
if ext == "https://stac-extensions.github.io/eo/v1.0.0/schema.json":
item["stac_extensions"][i] = "https://stac-extensions.github.io/eo/v1.1.0/schema.json"

item["geometry"] = fix_empty_multipolygon(item["geometry"]).__geo_interface__
df = stac_geoparquet.to_geodataframe([item])

Expand Down

0 comments on commit 8009fb0

Please sign in to comment.