Skip to content

Commit 21a0bbb

Browse files
authored
fix: fall back to epsg (#1505)
* fix: fall back to epsg * chore: update changelog
1 parent 7ac7560 commit 21a0bbb

File tree

4 files changed

+40
-23
lines changed

4 files changed

+40
-23
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
### Fixed
6+
7+
- Fall back to `epsg` when `code` is not present in the Projection extension ([#1505](https://github.com/stac-utils/pystac/pull/1505))
8+
59
## [v1.12.0]
610

711
### Added

pystac/extensions/projection.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ def epsg(self) -> int | None:
136136
"""
137137
if self.code is not None and self.code.startswith("EPSG:"):
138138
return int(self.code.replace("EPSG:", ""))
139+
elif epsg := self._get_property(
140+
EPSG_PROP, int
141+
): # In case the dictionary was not migrated
142+
return epsg
139143
return None
140144

141145
@epsg.setter

tests/extensions/test_projection.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,3 +647,12 @@ def test_ext_syntax_remove(projection_landsat8_item: pystac.Item) -> None:
647647
def test_ext_syntax_add(item: pystac.Item) -> None:
648648
item.ext.add("proj")
649649
assert isinstance(item.ext.proj, ProjectionExtension)
650+
651+
652+
def test_v1_from_dict() -> None:
653+
with open(
654+
TestCases.get_path("data-files/projection/example-with-version-1.1.json")
655+
) as f:
656+
data = json.load(f)
657+
item = pystac.Item.from_dict(data, migrate=False)
658+
assert item.ext.proj.epsg is not None

uv.lock

Lines changed: 23 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)