Skip to content
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

added projjson if epsg not available #41

Merged
merged 7 commits into from
Oct 20, 2022
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 CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
## 0.6.0 (TBD)

* remove python 3.7 support (https://github.com/developmentseed/rio-stac/pull/42)
* add `projjson` representation of the dataset CRS if available (author @clausmichele, https://github.com/developmentseed/rio-stac/pull/41)

## 0.5.0 (2022-09-05)

Expand Down
14 changes: 10 additions & 4 deletions rio_stac/stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ def get_projection_info(
see: https://github.com/stac-extensions/projection/#item-properties-or-asset-fields

"""
try:
epsg = src_dst.crs.to_epsg() or None
except AttributeError:
epsg = None
projjson = None
epsg = None
if src_dst.crs is not None:
epsg = src_dst.crs.to_epsg() if src_dst.crs.is_epsg_code else None
try:
projjson = src_dst.crs.to_dict(projjson=True)
except (AttributeError, TypeError):
pass

meta = {
"epsg": epsg,
Expand All @@ -79,6 +83,8 @@ def get_projection_info(
"shape": [src_dst.height, src_dst.width],
"transform": list(src_dst.transform),
}
if projjson is not None:
meta["projjson"] = projjson
# rasterio can't reproduce wkt2
# ref: https://github.com/mapbox/rasterio/issues/2044
# if epsg is None:
Expand Down
Binary file added tests/fixtures/dataset_nocrs.tif
Binary file not shown.
21 changes: 21 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,24 @@ def test_rio_stac_cli(runner):
assert "datetime" in stac_item["properties"]
assert "proj:epsg" in stac_item["properties"]
assert "raster:bands" in stac_item["assets"]["asset"]

with runner.isolated_filesystem():
src_path = os.path.join(PREFIX, "dataset_nocrs.tif")
result = runner.invoke(stac, [src_path])
assert not result.exception
assert result.exit_code == 0
stac_item = json.loads(result.output)
assert stac_item["type"] == "Feature"
assert stac_item["assets"]["asset"]
assert stac_item["assets"]["asset"]["href"] == src_path
assert stac_item["links"] == []
assert stac_item["stac_extensions"] == [
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://stac-extensions.github.io/raster/v1.1.0/schema.json",
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
]
assert "datetime" in stac_item["properties"]
assert "proj:epsg" in stac_item["properties"]
assert "proj:projjson" in stac_item["properties"]
assert "raster:bands" in stac_item["assets"]["asset"]
assert "eo:bands" in stac_item["assets"]["asset"]