Skip to content

Commit b8853d3

Browse files
author
Jon Duckworth
authored
Merge pull request #557 from duckontheweb/add/gh-262-epsg-migration
Add migration for eo:epsg to proj:epsg
2 parents 660fd9a + 097f4b5 commit b8853d3

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- Migration for `sar:type` -> `sar:product_type` and `sar:polarization` ->
1212
`sar:polarizations` for pre-0.9 catalogs
1313
([#556](https://github.com/stac-utils/pystac/pull/556))
14+
- Migration from `eo:epsg` -> `proj:epsg` for pre-0.9 catalogs ([#557](https://github.com/stac-utils/pystac/pull/557))
1415
- Collection summaries for Point Cloud Extension ([#558](https://github.com/stac-utils/pystac/pull/558))
1516
- `PhenomenologyType` enum for recommended values of `pc:type` & `SchemaType` enum for
1617
valid values of `type` in [Point Cloud Schema

pystac/extensions/eo.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
SummariesExtension,
2525
)
2626
from pystac.extensions.hooks import ExtensionHooks
27-
from pystac.extensions import view
27+
from pystac.extensions import view, projection
2828
from pystac.serialization.identify import STACJSONDescription, STACVersionID
2929
from pystac.utils import get_required, map_opt
3030

@@ -557,6 +557,22 @@ def migrate(
557557
]
558558
del obj["properties"]["eo:{}".format(field)]
559559

560+
# eo:epsg became proj:epsg
561+
eo_epsg = PREFIX + "epsg"
562+
proj_epsg = projection.PREFIX + "epsg"
563+
if eo_epsg in obj["properties"] and proj_epsg not in obj["properties"]:
564+
obj["properties"][proj_epsg] = obj["properties"].pop(eo_epsg)
565+
obj["stac_extensions"] = obj.get("stac_extensions", [])
566+
if (
567+
projection.ProjectionExtension.get_schema_uri()
568+
not in obj["stac_extensions"]
569+
):
570+
obj["stac_extensions"].append(
571+
projection.ProjectionExtension.get_schema_uri()
572+
)
573+
if not any(prop.startswith(PREFIX) for prop in obj["properties"]):
574+
obj["stac_extensions"].remove(EOExtension.get_schema_uri())
575+
560576
if version < "1.0.0-beta.1" and info.object_type == pystac.STACObjectType.ITEM:
561577
# gsd moved from eo to common metadata
562578
if "eo:gsd" in obj["properties"]:

tests/extensions/test_eo.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from pystac.summaries import RangeSummary
77
from pystac.utils import get_opt
88
from pystac.extensions.eo import EOExtension, Band
9+
from pystac.extensions.projection import ProjectionExtension
910
from tests.utils import TestCases, assert_to_from_dict
1011

1112

@@ -325,3 +326,23 @@ def test_should_raise_exception_when_passing_invalid_extension_object(
325326
EOExtension.ext,
326327
object(),
327328
)
329+
330+
331+
class EOMigrationTest(unittest.TestCase):
332+
def setUp(self) -> None:
333+
self.maxDiff = None
334+
self.item_0_8_path = TestCases.get_path(
335+
"data-files/examples/0.8.1/item-spec/examples/sentinel2-sample.json"
336+
)
337+
338+
def test_migration(self) -> None:
339+
with open(self.item_0_8_path) as src:
340+
item_dict = json.load(src)
341+
342+
self.assertIn("eo:epsg", item_dict["properties"])
343+
344+
item = Item.from_file(self.item_0_8_path)
345+
346+
self.assertNotIn("eo:epsg", item.properties)
347+
self.assertIn("proj:epsg", item.properties)
348+
self.assertIn(ProjectionExtension.get_schema_uri(), item.stac_extensions)

0 commit comments

Comments
 (0)