Skip to content

Commit

Permalink
lint and test
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago committed Dec 8, 2023
1 parent f7eecce commit 85f50da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 12 additions & 6 deletions rio_stac/stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ def get_projection_info(
src_dst: Union[DatasetReader, DatasetWriter, WarpedVRT, MemoryFile]
) -> Dict:
"""Get projection metadata.
The STAC projection extension allows for three different ways to describe the coordinate reference system
associated with a raster :
associated with a raster :
- EPSG code
- WKT2
- PROJJSON
All are optional, and they can be provided altogether as well. Therefore, as long as one can be obtained from
the data, we add it to the returned dictionary.
the data, we add it to the returned dictionary.
see: https://github.com/stac-extensions/projection
Expand All @@ -103,13 +103,17 @@ def get_projection_info(
wkt2 = None
epsg = None
if src_dst.crs is not None:
# EPSG
epsg = src_dst.crs.to_epsg() if src_dst.crs.is_epsg_code else None

# PROJJSON
try:
projjson = src_dst.crs.to_dict(projjson=True)
except (AttributeError, TypeError) as ex:
warnings.warn(f"Could not get PROJJSON from dataset : {ex}")
pass


# WKT2
try:
wkt2 = src_dst.crs.to_wkt()
except Exception as ex:
Expand All @@ -123,11 +127,13 @@ def get_projection_info(
"shape": [src_dst.height, src_dst.width],
"transform": list(src_dst.transform),
}

if projjson is not None:
meta["projjson"] = projjson

if wkt2 is not None:
meta["wkt2"] = wkt2

return meta


Expand Down
2 changes: 2 additions & 0 deletions tests/test_create_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def test_create_item_options():
]
assert "datetime" in item_dict["properties"]
assert "proj:epsg" in item_dict["properties"]
assert "proj:wkt2" in item_dict["properties"]
assert "proj:projjson" in item_dict["properties"]
assert "sci:citation" in item_dict["properties"]

# external assets
Expand Down

0 comments on commit 85f50da

Please sign in to comment.