Skip to content

Commit

Permalink
fix: fall back to epsg
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski committed Jan 24, 2025
1 parent 7ac7560 commit 79e62fd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 23 deletions.
4 changes: 4 additions & 0 deletions pystac/extensions/projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ def epsg(self) -> int | None:
"""
if self.code is not None and self.code.startswith("EPSG:"):
return int(self.code.replace("EPSG:", ""))
elif epsg := self._get_property(
EPSG_PROP, int
): # In case the dictionary was not migrated
return epsg
return None

@epsg.setter
Expand Down
9 changes: 9 additions & 0 deletions tests/extensions/test_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,3 +647,12 @@ def test_ext_syntax_remove(projection_landsat8_item: pystac.Item) -> None:
def test_ext_syntax_add(item: pystac.Item) -> None:
item.ext.add("proj")
assert isinstance(item.ext.proj, ProjectionExtension)


def test_v1_from_dict() -> None:
with open(
TestCases.get_path("data-files/projection/example-with-version-1.1.json")
) as f:
data = json.load(f)
item = pystac.Item.from_dict(data, migrate=False)
assert item.ext.proj.epsg is not None
46 changes: 23 additions & 23 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 79e62fd

Please sign in to comment.