Skip to content

Commit

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

* chore: update changelog
  • Loading branch information
gadomski authored Jan 27, 2025
1 parent 21a0bbb commit 14a4626
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Fixed

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

## [v1.12.0]

Expand Down
2 changes: 2 additions & 0 deletions pystac/extensions/projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ def crs_string(self) -> str | None:
"""
if self.code:
return self.code
elif self.epsg:
return f"EPSG:{self.epsg}"
elif self.wkt2:
return self.wkt2
elif self.projjson:
Expand Down
94 changes: 94 additions & 0 deletions tests/data-files/projection/another-1.1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"stac_version": "0.9.0",
"stac_extensions": [
"https://stac-extensions.github.io/file/v2.1.0/schema.json",
"https://stac-extensions.github.io/projection/v1.1.0/schema.json"
],
"type": "Feature",
"id": "JQT-123456789",
"bbox": [-81.3085227080129, 32.10817938759764, -78.81735409341113, 34.22870275071835],
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-81.3085227080129,
32.10817938759764
],
[
-78.81735409341113,
32.10817938759764
],
[
-78.81735409341113,
34.22870275071835
],
[
-81.3085227080129,
34.22870275071835
],
[
-81.3085227080129,
32.10817938759764
]
]
]
},
"properties": {
"proj:epsg": 32617,
"proj:shape": [
259,
255
],
"proj:transform": [
900.0,
0.0,
471585.0,
0.0,
-900.0,
3787515.0,
0.0,
0.0,
1.0
],
"datetime": "2016-05-03T13:21:30.040Z",
"collection": "JQT"
},
"links": [
{
"rel": "self",
"href": "http://cool-sat.com/catalog/JQT/a-fake-item.json"
},
{
"rel": "collection",
"href": "http://cool-sat.com/catalog.json"
}
],
"assets": {
"red": {
"href": "http://somewhere-over-the-rainbow.io/red.tif",
"title": "red",
"file:header_size": 16384
},
"green": {
"href": "http://somewhere-over-the-rainbow.io/green.tif",
"title": "green",
"file:header_size": 30000
},
"blue": {
"href": "http://somewhere-over-the-rainbow.io/blue.tif",
"title": "blue",
"file:header_size": 20000
},
"lowres": {
"href": "http://somewhere-over-the-rainbow.io/lowres.tif",
"title": "lowres"
},
"thumbnail": {
"href": "http://cool-sat.com/catalog/a-fake-item/thumbnail.png",
"title": "Thumbnail",
"type": "image/png",
"roles": [ "thumbnail" ]
}
}
}
9 changes: 9 additions & 0 deletions tests/extensions/test_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,3 +656,12 @@ def test_v1_from_dict() -> None:
data = json.load(f)
item = pystac.Item.from_dict(data, migrate=False)
assert item.ext.proj.epsg is not None
assert item.ext.proj.crs_string is not None


def test_v1_crs_string() -> None:
with open(TestCases.get_path("data-files/projection/another-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
assert item.ext.proj.crs_string == "EPSG:32617"

0 comments on commit 14a4626

Please sign in to comment.