Skip to content

Add migration for eo:epsg to proj:epsg #557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Migration for `sar:type` -> `sar:product_type` and `sar:polarization` ->
`sar:polarizations` for pre-0.9 catalogs
([#556](https://github.com/stac-utils/pystac/pull/556))
- Migration from `eo:epsg` -> `proj:epsg` for pre-0.9 catalogs ([#557](https://github.com/stac-utils/pystac/pull/557))
- Collection summaries for Point Cloud Extension ([#558](https://github.com/stac-utils/pystac/pull/558))
- `PhenomenologyType` enum for recommended values of `pc:type` & `SchemaType` enum for
valid values of `type` in [Point Cloud Schema
Expand Down
18 changes: 17 additions & 1 deletion pystac/extensions/eo.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
SummariesExtension,
)
from pystac.extensions.hooks import ExtensionHooks
from pystac.extensions import view
from pystac.extensions import view, projection
from pystac.serialization.identify import STACJSONDescription, STACVersionID
from pystac.utils import get_required, map_opt

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

# eo:epsg became proj:epsg
eo_epsg = PREFIX + "epsg"
proj_epsg = projection.PREFIX + "epsg"
if eo_epsg in obj["properties"] and proj_epsg not in obj["properties"]:
obj["properties"][proj_epsg] = obj["properties"].pop(eo_epsg)
obj["stac_extensions"] = obj.get("stac_extensions", [])
if (
projection.ProjectionExtension.get_schema_uri()
not in obj["stac_extensions"]
):
obj["stac_extensions"].append(
projection.ProjectionExtension.get_schema_uri()
)
if not any(prop.startswith(PREFIX) for prop in obj["properties"]):
obj["stac_extensions"].remove(EOExtension.get_schema_uri())

if version < "1.0.0-beta.1" and info.object_type == pystac.STACObjectType.ITEM:
# gsd moved from eo to common metadata
if "eo:gsd" in obj["properties"]:
Expand Down
21 changes: 21 additions & 0 deletions tests/extensions/test_eo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pystac.summaries import RangeSummary
from pystac.utils import get_opt
from pystac.extensions.eo import EOExtension, Band
from pystac.extensions.projection import ProjectionExtension
from tests.utils import TestCases, assert_to_from_dict


Expand Down Expand Up @@ -325,3 +326,23 @@ def test_should_raise_exception_when_passing_invalid_extension_object(
EOExtension.ext,
object(),
)


class EOMigrationTest(unittest.TestCase):
def setUp(self) -> None:
self.maxDiff = None
self.item_0_8_path = TestCases.get_path(
"data-files/examples/0.8.1/item-spec/examples/sentinel2-sample.json"
)

def test_migration(self) -> None:
with open(self.item_0_8_path) as src:
item_dict = json.load(src)

self.assertIn("eo:epsg", item_dict["properties"])

item = Item.from_file(self.item_0_8_path)

self.assertNotIn("eo:epsg", item.properties)
self.assertIn("proj:epsg", item.properties)
self.assertIn(ProjectionExtension.get_schema_uri(), item.stac_extensions)