Skip to content

Commit

Permalink
EP-3827 add band metadata to asset if available
Browse files Browse the repository at this point in the history
  • Loading branch information
jdries committed Apr 8, 2021
1 parent 4f4cc9d commit d640ec5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion openeo_driver/save_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from openeo_driver.utils import replace_nan_values, EvalEnv
from shapely.geometry import GeometryCollection, mapping

from openeo.metadata import CollectionMetadata


class SaveResult(ABC):
"""
Expand Down Expand Up @@ -115,12 +117,13 @@ class AggregatePolygonResult(JSONResult):
"""

def __init__(self, timeseries: dict, regions: GeometryCollection):
def __init__(self, timeseries: dict, regions: GeometryCollection, metadata:CollectionMetadata=None):
super().__init__(data=timeseries)
if not isinstance(regions, GeometryCollection):
# TODO: raise exception instead of warning?
warnings.warn("AggregatePolygonResult: GeometryCollection expected but got {t}".format(t=type(regions)))
self._regions = regions
self._metadata = metadata

def get_data(self):
if self.format in ('covjson', 'coveragejson'):
Expand Down Expand Up @@ -154,6 +157,10 @@ def write_assets(self, directory:str) -> Dict:
with open(filename, 'w') as f:
json.dump(self.prepare_for_json(), f)
asset["href"] = filename
if self._metadata is not None and self._metadata.has_band_dimension():
bands = [b._asdict() for b in self._metadata.bands]
asset["bands"] = bands

return {str(Path(filename).name): asset}

def create_flask_response(self):
Expand Down

0 comments on commit d640ec5

Please sign in to comment.