Skip to content

Commit

Permalink
fix: Use GeoJSON media type for item links TDE-1254 (#1086)
Browse files Browse the repository at this point in the history
### Motivation


https://github.com/radiantearth/stac-spec/blob/master/commons/links.md#stac-media-types

### Modifications

Change item links from media type `application/json` to
`application/geo+json`.

### Verification

`pytest`
  • Loading branch information
l0b0 committed Sep 27, 2024
1 parent 0208450 commit 1889402
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion scripts/stac/imagery/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def add_item(self, item: dict[Any, Any]) -> None:
Link(
path=item_self_link["href"],
rel=Relation.ITEM,
media_type=StacMediaType.JSON,
media_type=StacMediaType.GEOJSON,
file_content=dict_to_json_bytes(item),
).stac
)
Expand Down
7 changes: 6 additions & 1 deletion scripts/stac/imagery/create_stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ def create_item(
start_datetime = min(start_datetime, derived_stac["properties"]["start_datetime"])
end_datetime = max(end_datetime, derived_stac["properties"]["end_datetime"])
item.add_link(
Link(path=derived, rel=Relation.DERIVED_FROM, media_type=StacMediaType.JSON, file_content=derived_item_content)
Link(
path=derived,
rel=Relation.DERIVED_FROM,
media_type=StacMediaType.GEOJSON,
file_content=derived_item_content,
)
)

item.update_datetime(start_datetime, end_datetime)
Expand Down
2 changes: 1 addition & 1 deletion scripts/stac/imagery/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, id_: str, file: str, now: Callable[[], datetime]) -> None:
"type": "Feature",
"stac_version": STAC_VERSION,
"id": id_,
"links": [Link(path=f"./{id_}.json", rel=Relation.SELF, media_type=StacMediaType.JSON).stac],
"links": [Link(path=f"./{id_}.json", rel=Relation.SELF, media_type=StacMediaType.GEOJSON).stac],
"assets": {
"visual": {
"href": os.path.join(".", os.path.basename(file)),
Expand Down
2 changes: 1 addition & 1 deletion scripts/stac/imagery/tests/collection_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def test_add_item(metadata: CollectionMetadata, subtests: SubTests) -> None:
with subtests.test(msg="Main links content"):
assert [
{"href": "./collection.json", "rel": "self", "type": "application/json"},
{"rel": "item", "href": "./BR34_5000_0304.json", "type": "application/json"},
{"rel": "item", "href": "./BR34_5000_0304.json", "type": "application/geo+json"},
] == links

with subtests.test():
Expand Down
2 changes: 1 addition & 1 deletion scripts/stac/imagery/tests/create_stac_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_create_item_with_derived_from(tmp_path: Path) -> None:
assert {
"href": derived_from_path.as_posix(),
"rel": "derived_from",
"type": "application/json",
"type": "application/geo+json",
"file:checksum": "12209c3d50f21fdd739de5c76b3c7ca60ee7f5cf69c2cf92b1d0136308cf63d9c5d5",
} in item.stac["links"]

Expand Down
2 changes: 1 addition & 1 deletion scripts/stac/imagery/tests/item_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_imagery_stac_item(mocker: MockerFixture, subtests: SubTests) -> None:
)

with subtests.test():
assert {"rel": "self", "href": f"./{id_}.json", "type": "application/json"} in item.stac["links"]
assert {"rel": "self", "href": f"./{id_}.json", "type": "application/geo+json"} in item.stac["links"]


# pylint: disable=duplicate-code
Expand Down

0 comments on commit 1889402

Please sign in to comment.