Skip to content

Commit 6e8eb22

Browse files
Add projection v1.2.0 to the list of schema URIs in projection.py (#1590)
* Add projection v1.2.0 to the list schema URIs in projection.py The migration of projection to latest version systematically pops the field epsg. If extension URI is pointing to versions 1.0.0 or 1.1.0, it is also changed to point to version 2.0.0. However, if schema URI is v1.2.0 the extension schema URI is not changed. I propose to change it as well in that case so that the change is explicit for all versions < 2.0.0. That would help finding out that a change occurred. * Add test, migration for proj v1.2.0 --------- Co-authored-by: Julia Signell <[email protected]>
1 parent 065a631 commit 6e8eb22

File tree

3 files changed

+476
-3
lines changed

3 files changed

+476
-3
lines changed

pystac/extensions/projection.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
SCHEMA_URIS: list[str] = [
3131
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
3232
"https://stac-extensions.github.io/projection/v1.1.0/schema.json",
33+
"https://stac-extensions.github.io/projection/v1.2.0/schema.json",
3334
SCHEMA_URI,
3435
]
3536
PREFIX: str = "proj:"
@@ -467,6 +468,7 @@ class ProjectionExtensionHooks(ExtensionHooks):
467468
"projection",
468469
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
469470
"https://stac-extensions.github.io/projection/v1.1.0/schema.json",
471+
"https://stac-extensions.github.io/projection/v1.2.0/schema.json",
470472
}
471473
stac_object_types = {pystac.STACObjectType.ITEM}
472474

@@ -478,12 +480,27 @@ def migrate(
478480

479481
# proj:epsg moved to proj:code
480482
if epsg := obj["properties"].pop("proj:epsg", None):
481-
obj["properties"]["proj:code"] = f"EPSG:{epsg}"
483+
if obj["properties"].get("proj:code", None) is None:
484+
obj["properties"]["proj:code"] = f"EPSG:{epsg}"
485+
elif not obj["properties"]["proj:code"] == f"EPSG:{epsg}":
486+
warnings.warn(
487+
"Both proj:code and proj:epsg are specified and they have "
488+
"conflicting values. This might lead to surprising behavior.",
489+
UserWarning,
490+
)
482491

483492
for key in ["assets", "item_assets"]:
484493
for asset in obj.get(key, {}).values():
485494
if epsg := asset.pop("proj:epsg", None):
486-
asset["proj:code"] = f"EPSG:{epsg}"
495+
if asset.get("proj:code", None) is None:
496+
asset["proj:code"] = f"EPSG:{epsg}"
497+
elif not asset["proj:code"] == f"EPSG:{epsg}":
498+
warnings.warn(
499+
"Both proj:code and proj:epsg are specified and they "
500+
"have conflicting values. This might lead to surprising "
501+
"behavior.",
502+
UserWarning,
503+
)
487504

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

0 commit comments

Comments
 (0)