Skip to content

Commit

Permalink
fix: fall back to epsg (#1505)
Browse files Browse the repository at this point in the history
* fix: fall back to epsg

* chore: update changelog
  • Loading branch information
gadomski authored Jan 24, 2025
1 parent 7ac7560 commit 21a0bbb
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 23 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Fixed

- Fall back to `epsg` when `code` is not present in the Projection extension ([#1505](https://github.com/stac-utils/pystac/pull/1505))

## [v1.12.0]

### Added
Expand Down
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 21a0bbb

Please sign in to comment.