Skip to content

Projection extension: migrate Assets on Items #1549

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

Merged
merged 4 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Added

- Projection extension: migrate Assets and Item-Assets ([#1549](https://github.com/stac-utils/pystac/pull/1549))
- `Collection.from_items` for creating a `pystac.Collection` from an `ItemCollection` ([#1522](https://github.com/stac-utils/pystac/pull/1522))

### Fixed
Expand Down
5 changes: 5 additions & 0 deletions pystac/extensions/projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,11 @@ def migrate(
if epsg := obj["properties"].pop("proj:epsg", None):
obj["properties"]["proj:code"] = f"EPSG:{epsg}"

for key in ["assets", "item_assets"]:
for asset in obj.get(key, {}).values():
if epsg := asset.pop("proj:epsg", None):
asset["proj:code"] = f"EPSG:{epsg}"

super().migrate(obj, version, info)


Expand Down
29 changes: 28 additions & 1 deletion tests/data-files/projection/collection-with-summaries.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,35 @@
"type": "application/json"
}
],
"item_assets": {
"analytic": {
"type": "image/tiff; application=geotiff; profile=cloud-optimized",
"title": "4-Band Analytic",
"roles": [
"data"
],
"gsd": 0.66,
"proj:code": "EPSG:32659",
"proj:shape": [
5558,
9559
],
"proj:transform": [
0.5,
0,
712710,
0,
-0.5,
151406,
0,
0,
1
]
}
},
"stac_extensions": [
"https://stac-extensions.github.io/projection/v2.0.0/schema.json"
"https://stac-extensions.github.io/projection/v2.0.0/schema.json",
"https://stac-extensions.github.io/item-assets/v1.0.0/schema.json"
],
"summaries": {
"proj:code": [
Expand Down
23 changes: 22 additions & 1 deletion tests/extensions/test_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ def test_get_set_code(projection_landsat8_item: Item) -> None:
assert proj_item.properties["proj:code"] == "IAU_2015:30100"


def test_migrate() -> None:
def test_migrate_item() -> None:
old = "https://stac-extensions.github.io/projection/v1.1.0/schema.json"
current = "https://stac-extensions.github.io/projection/v2.0.0/schema.json"

Expand All @@ -587,6 +587,27 @@ def test_migrate() -> None:
assert item.ext.proj.epsg == 32614
assert item.ext.proj.code == "EPSG:32614"

assert item.assets["B1"].ext.proj.epsg == 32614
assert item.assets["B1"].ext.proj.code == "EPSG:32614"

assert item.assets["B8"].ext.proj.epsg == 9999
assert item.assets["B8"].ext.proj.code == "EPSG:9999"


def test_migrate_collection_item_assets() -> None:
old = "https://stac-extensions.github.io/projection/v1.1.0/schema.json"
current = "https://stac-extensions.github.io/projection/v2.0.0/schema.json"

path = TestCases.get_path("data-files/projection/collection-with-summaries.json")
collection = pystac.Collection.from_file(path)

assert old not in collection.stac_extensions
assert current in collection.stac_extensions

for item_asset in collection.item_assets.values():
assert item_asset.ext.proj.epsg == 32659
assert item_asset.ext.proj.code == "EPSG:32659"


def test_older_extension_version(projection_landsat8_item: Item) -> None:
old = "https://stac-extensions.github.io/projection/v1.0.0/schema.json"
Expand Down