Skip to content

Commit

Permalink
support "proj:code" in addition to "proj:epsg"
Browse files Browse the repository at this point in the history
  • Loading branch information
bossie committed Feb 6, 2025
1 parent 2c8bf16 commit 4903041
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion openeogeotrellis/load_stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,16 @@ def get_proj_metadata(itm: pystac.Item, asst: pystac.Asset) -> (Optional[int],
Optional[Tuple[float, float, float, float]],
Optional[Tuple[int, int]]):
"""Returns EPSG code, bbox (in that EPSG) and number of pixels (rows, cols), if available."""
epsg = asst.extra_fields.get("proj:epsg") or itm.properties.get("proj:epsg")

def to_epsg(proj_code: Optional[str]) -> Optional[int]:
prefix = "EPSG:"
return int(proj_code[len(prefix):]) if proj_code.upper().startswith(prefix) else None

code = asst.extra_fields.get("proj:code") or itm.properties.get("proj:code")
epsg = to_epsg(code) or asst.extra_fields.get("proj:epsg") or itm.properties.get("proj:epsg")
bbox = asst.extra_fields.get("proj:bbox") or itm.properties.get("proj:bbox")
shape = asst.extra_fields.get("proj:shape") or itm.properties.get("proj:shape")

return (epsg,
tuple(map(float, bbox)) if bbox else None,
tuple(shape) if shape else None)
Expand Down

0 comments on commit 4903041

Please sign in to comment.