Skip to content

Commit 14a4626

Browse files
authored
fix: fall back to epsg in crs_string, too (#1510)
* fix: fall back to epsg in crs_string, too * chore: update changelog
1 parent 21a0bbb commit 14a4626

File tree

4 files changed

+106
-1
lines changed

4 files changed

+106
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### Fixed
66

7-
- Fall back to `epsg` when `code` is not present in the Projection extension ([#1505](https://github.com/stac-utils/pystac/pull/1505))
7+
- 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))
88

99
## [v1.12.0]
1010

pystac/extensions/projection.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ def crs_string(self) -> str | None:
218218
"""
219219
if self.code:
220220
return self.code
221+
elif self.epsg:
222+
return f"EPSG:{self.epsg}"
221223
elif self.wkt2:
222224
return self.wkt2
223225
elif self.projjson:
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
{
2+
"stac_version": "0.9.0",
3+
"stac_extensions": [
4+
"https://stac-extensions.github.io/file/v2.1.0/schema.json",
5+
"https://stac-extensions.github.io/projection/v1.1.0/schema.json"
6+
],
7+
"type": "Feature",
8+
"id": "JQT-123456789",
9+
"bbox": [-81.3085227080129, 32.10817938759764, -78.81735409341113, 34.22870275071835],
10+
"geometry": {
11+
"type": "Polygon",
12+
"coordinates": [
13+
[
14+
[
15+
-81.3085227080129,
16+
32.10817938759764
17+
],
18+
[
19+
-78.81735409341113,
20+
32.10817938759764
21+
],
22+
[
23+
-78.81735409341113,
24+
34.22870275071835
25+
],
26+
[
27+
-81.3085227080129,
28+
34.22870275071835
29+
],
30+
[
31+
-81.3085227080129,
32+
32.10817938759764
33+
]
34+
]
35+
]
36+
},
37+
"properties": {
38+
"proj:epsg": 32617,
39+
"proj:shape": [
40+
259,
41+
255
42+
],
43+
"proj:transform": [
44+
900.0,
45+
0.0,
46+
471585.0,
47+
0.0,
48+
-900.0,
49+
3787515.0,
50+
0.0,
51+
0.0,
52+
1.0
53+
],
54+
"datetime": "2016-05-03T13:21:30.040Z",
55+
"collection": "JQT"
56+
},
57+
"links": [
58+
{
59+
"rel": "self",
60+
"href": "http://cool-sat.com/catalog/JQT/a-fake-item.json"
61+
},
62+
{
63+
"rel": "collection",
64+
"href": "http://cool-sat.com/catalog.json"
65+
}
66+
],
67+
"assets": {
68+
"red": {
69+
"href": "http://somewhere-over-the-rainbow.io/red.tif",
70+
"title": "red",
71+
"file:header_size": 16384
72+
},
73+
"green": {
74+
"href": "http://somewhere-over-the-rainbow.io/green.tif",
75+
"title": "green",
76+
"file:header_size": 30000
77+
},
78+
"blue": {
79+
"href": "http://somewhere-over-the-rainbow.io/blue.tif",
80+
"title": "blue",
81+
"file:header_size": 20000
82+
},
83+
"lowres": {
84+
"href": "http://somewhere-over-the-rainbow.io/lowres.tif",
85+
"title": "lowres"
86+
},
87+
"thumbnail": {
88+
"href": "http://cool-sat.com/catalog/a-fake-item/thumbnail.png",
89+
"title": "Thumbnail",
90+
"type": "image/png",
91+
"roles": [ "thumbnail" ]
92+
}
93+
}
94+
}

tests/extensions/test_projection.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,3 +656,12 @@ def test_v1_from_dict() -> None:
656656
data = json.load(f)
657657
item = pystac.Item.from_dict(data, migrate=False)
658658
assert item.ext.proj.epsg is not None
659+
assert item.ext.proj.crs_string is not None
660+
661+
662+
def test_v1_crs_string() -> None:
663+
with open(TestCases.get_path("data-files/projection/another-1.1.json")) as f:
664+
data = json.load(f)
665+
item = pystac.Item.from_dict(data, migrate=False)
666+
assert item.ext.proj.epsg is not None
667+
assert item.ext.proj.crs_string == "EPSG:32617"

0 commit comments

Comments
 (0)