Skip to content

Commit

Permalink
Merge pull request #69 from digitalearthpacific/stac-raster-extension
Browse files Browse the repository at this point in the history
working version, needs cleanup
  • Loading branch information
jessjaco authored Oct 13, 2024
2 parents 2e272f7 + b340fed commit 0d51912
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions dep_tools/stac_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import numpy as np
from pandas import DataFrame
from pystac import Asset, Item, MediaType
from rio_stac.stac import create_stac_item
import rasterio
from rio_stac.stac import create_stac_item, get_raster_info
from urlpath import URL
from xarray import DataArray, Dataset

Expand Down Expand Up @@ -84,14 +85,20 @@ def get_stac_item(

paths = [itempath.path(item_id, variable) for variable in data]

assets = {
variable: Asset(
assets = {}
for variable, path in zip(data, paths):
raster_info = {}
full_path = str(prefix / path)
if "with_raster" in kwargs.keys() and kwargs["with_raster"]:
with rasterio.open(full_path) as src_dst:
raster_info = {"raster:bands": get_raster_info(src_dst, max_size=1024)}

assets[variable] = Asset(
media_type=MediaType.COG,
href=str(prefix / path),
href=full_path,
roles=["data"],
extra_fields={**raster_info},
)
for variable, path in zip(data, paths)
}
stac_id = itempath.basename(item_id)
collection = itempath.item_prefix
collection_url = f"{collection_url_root}/{collection}"
Expand Down

0 comments on commit 0d51912

Please sign in to comment.