Skip to content
Open
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
21 changes: 19 additions & 2 deletions pystac/extensions/projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
SCHEMA_URIS: list[str] = [
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.1.0/schema.json",
"https://stac-extensions.github.io/projection/v1.2.0/schema.json",
SCHEMA_URI,
]
PREFIX: str = "proj:"
Expand Down Expand Up @@ -467,6 +468,7 @@ class ProjectionExtensionHooks(ExtensionHooks):
"projection",
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.1.0/schema.json",
"https://stac-extensions.github.io/projection/v1.2.0/schema.json",
}
stac_object_types = {pystac.STACObjectType.ITEM}

Expand All @@ -478,12 +480,27 @@ def migrate(

# proj:epsg moved to proj:code
if epsg := obj["properties"].pop("proj:epsg", None):
obj["properties"]["proj:code"] = f"EPSG:{epsg}"
if obj["properties"].get("proj:code", None) is None:
obj["properties"]["proj:code"] = f"EPSG:{epsg}"
elif not obj["properties"]["proj:code"] == f"EPSG:{epsg}":
warnings.warn(
"Both proj:code and proj:epsg are specified and they have "
"conflicting values. This might lead to surprising behavior.",
UserWarning,
)

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}"
if asset.get("proj:code", None) is None:
asset["proj:code"] = f"EPSG:{epsg}"
elif not asset["proj:code"] == f"EPSG:{epsg}":
warnings.warn(
"Both proj:code and proj:epsg are specified and they "
"have conflicting values. This might lead to surprising "
"behavior.",
UserWarning,
)

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

Expand Down
Loading