Skip to content

Commit 897f3cb

Browse files
authored
Projection extension: migrate Assets on Items (#1549)
* Migrate projection extension on assets * Add migrate test for collection item-assets * Add 1549 to changelog * Fix asset+item_asset migration handling
1 parent 9351385 commit 897f3cb

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Added
66

7+
- Projection extension: migrate Assets and Item-Assets ([#1549](https://github.com/stac-utils/pystac/pull/1549))
78
- `Collection.from_items` for creating a `pystac.Collection` from an `ItemCollection` ([#1522](https://github.com/stac-utils/pystac/pull/1522))
89
- `extensions.mlm` for supporting the [MLM](https://github.com/stac-extensions/mlm) extension ([#1542](https://github.com/stac-utils/pystac/pull/1542))
910

pystac/extensions/projection.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,11 @@ def migrate(
480480
if epsg := obj["properties"].pop("proj:epsg", None):
481481
obj["properties"]["proj:code"] = f"EPSG:{epsg}"
482482

483+
for key in ["assets", "item_assets"]:
484+
for asset in obj.get(key, {}).values():
485+
if epsg := asset.pop("proj:epsg", None):
486+
asset["proj:code"] = f"EPSG:{epsg}"
487+
483488
super().migrate(obj, version, info)
484489

485490

tests/data-files/projection/collection-with-summaries.json

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,35 @@
2020
"type": "application/json"
2121
}
2222
],
23+
"item_assets": {
24+
"analytic": {
25+
"type": "image/tiff; application=geotiff; profile=cloud-optimized",
26+
"title": "4-Band Analytic",
27+
"roles": [
28+
"data"
29+
],
30+
"gsd": 0.66,
31+
"proj:code": "EPSG:32659",
32+
"proj:shape": [
33+
5558,
34+
9559
35+
],
36+
"proj:transform": [
37+
0.5,
38+
0,
39+
712710,
40+
0,
41+
-0.5,
42+
151406,
43+
0,
44+
0,
45+
1
46+
]
47+
}
48+
},
2349
"stac_extensions": [
24-
"https://stac-extensions.github.io/projection/v2.0.0/schema.json"
50+
"https://stac-extensions.github.io/projection/v2.0.0/schema.json",
51+
"https://stac-extensions.github.io/item-assets/v1.0.0/schema.json"
2552
],
2653
"summaries": {
2754
"proj:code": [

tests/extensions/test_projection.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ def test_get_set_code(projection_landsat8_item: Item) -> None:
574574
assert proj_item.properties["proj:code"] == "IAU_2015:30100"
575575

576576

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

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

590+
assert item.assets["B1"].ext.proj.epsg == 32614
591+
assert item.assets["B1"].ext.proj.code == "EPSG:32614"
592+
593+
assert item.assets["B8"].ext.proj.epsg == 9999
594+
assert item.assets["B8"].ext.proj.code == "EPSG:9999"
595+
596+
597+
def test_migrate_collection_item_assets() -> None:
598+
old = "https://stac-extensions.github.io/projection/v1.1.0/schema.json"
599+
current = "https://stac-extensions.github.io/projection/v2.0.0/schema.json"
600+
601+
path = TestCases.get_path("data-files/projection/collection-with-summaries.json")
602+
collection = pystac.Collection.from_file(path)
603+
604+
assert old not in collection.stac_extensions
605+
assert current in collection.stac_extensions
606+
607+
for item_asset in collection.item_assets.values():
608+
assert item_asset.ext.proj.epsg == 32659
609+
assert item_asset.ext.proj.code == "EPSG:32659"
610+
590611

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

0 commit comments

Comments
 (0)