Skip to content

Commit 3734918

Browse files
author
Marco Mancini
committed
Add OGC API item and map
1 parent 710bfd8 commit 3734918

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

executor/app/main.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def persist_datacube(
110110
kube._properties["history"] = get_history_message()
111111
if isinstance(message.content, GeoQuery):
112112
format = message.content.format
113+
format_args = message.content.format_args
113114
else:
114115
format = "netcdf"
115116
match format:
@@ -119,6 +120,12 @@ def persist_datacube(
119120
case "geojson":
120121
full_path = os.path.join(base_path, f"{path}.json")
121122
kube.to_geojson(full_path)
123+
case "png":
124+
full_path = os.path.join(base_path, f"{path}.png")
125+
kube.to_image(full_path, **format_args)
126+
case "jpeg":
127+
full_path = os.path.join(base_path, f"{path}.jpg")
128+
kube.to_image(full_path, **format_args)
122129
case _:
123130
raise ValueError(f"format `{format}` is not supported")
124131
return full_path
@@ -132,7 +139,9 @@ def persist_dataset(
132139
def _get_attr_comb(dataframe_item, attrs):
133140
return "_".join([dataframe_item[attr_name] for attr_name in attrs])
134141

135-
def _persist_single_datacube(dataframe_item, base_path, format):
142+
def _persist_single_datacube(dataframe_item, base_path, format, format_args=None):
143+
if not format_args:
144+
format_args = {}
136145
dcube = dataframe_item[dset.DATACUBE_COL]
137146
if isinstance(dcube, Delayed):
138147
dcube = dcube.compute()
@@ -169,14 +178,21 @@ def _persist_single_datacube(dataframe_item, base_path, format):
169178
case "geojson":
170179
full_path = os.path.join(base_path, f"{path}.json")
171180
dcube.to_geojson(full_path)
181+
case "png":
182+
full_path = os.path.join(base_path, f"{path}.png")
183+
dcube.to_image(full_path, **format_args)
184+
case "jpeg":
185+
full_path = os.path.join(base_path, f"{path}.jpg")
186+
dcube.to_image(full_path, **format_args)
172187
return full_path
173188

174189
if isinstance(message.content, GeoQuery):
175190
format = message.content.format
191+
format_args = message.content.format_args
176192
else:
177193
format = "netcdf"
178194
datacubes_paths = dset.data.apply(
179-
_persist_single_datacube, base_path=base_path, format=format, axis=1
195+
_persist_single_datacube, base_path=base_path, format=format, format_args=format_args, axis=1
180196
)
181197
paths = datacubes_paths[~datacubes_paths.isna()]
182198
if len(paths) == 0:

0 commit comments

Comments
 (0)