Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for STRDS export #236

Merged
merged 4 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/actinia_core/models/process_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ class OutputParameter(IOParameterBase):
'properties': {
'format': {
'type': 'string',
'description': 'The format of the output file in case of raster layer, '
'description': 'The format of the output file in case of raster, strds, '
'vector layer or text file export. Raster layer export '
'support only GeoTiff format, all other formats are '
'supports only GeoTiff and COG format, STRDS layer export '
'supports only GTiff format and all other formats are '
'vector layer export formats. If the *PostgeSQL* format '
'was chosen, a postgis database string *dbstring* '
'must be provided so that the GRASS GIS module '
Expand All @@ -207,7 +208,7 @@ class OutputParameter(IOParameterBase):
'that was generated by a GRASS GIS module. Exported '
'text and vector files will always be compressed '
'with zip.',
'enum': ['raster', 'vector', 'file']
'enum': ['raster', 'vector', 'file', 'strds']
},
'dbstring': {
'type': 'string',
Expand Down
54 changes: 53 additions & 1 deletion src/actinia_core/rest/ephemeral_processing_with_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,51 @@ def _export_raster(self, raster_name,

return file_name, output_path

def _export_strds(self, strds_name, format="GTiff"):
"""Export a specific strds layer with t.rast.export.

The result is stored in a temporary directory
that is located in the temporary grass database.

Args:
strds_name (str): The name of the strds layer
format (str): GTiff (only option)

Returns:
tuple: A tuple (file_name, output_path)

"""
suffix = ".tar.bzip2"
file_name = strds_name.split("@")[0] + suffix
output_path = os.path.join(self.temp_file_path, file_name)

if format != 'GTiff':
format = 'GTiff'
self.message_logger.info("Only GTiff driver is supported for STRDS export.")

module_name = "t.rast.export"
args = [
"input=%s" % strds_name,
"format=%s" % format,
"output=%s" % output_path,
"compression=%s" % "bzip2"
]
# optimized for GTiff
create_opts = "createopt=BIGTIFF=YES,COMPRESS=LZW,TILED=YES"
args.append(create_opts)
os.environ['COMPRESS_OVERVIEW'] = "LZW"

p = Process(exec_type="grass",
executable=module_name,
executable_params=args,
id=f"exporter_strds_{strds_name}",
stdin_source=None)

self._update_num_of_steps(1)
self._run_module(p)

return file_name, output_path

def _export_vector(self, vector_name,
format="GPKG",
additional_options=[]):
Expand Down Expand Up @@ -471,7 +516,7 @@ def _export_resources(self, use_raster_region=False):
"Resource export was terminated by user request")

# Raster export
if resource["export"]["type"] in ["raster", "vector", "file"]:
if resource["export"]["type"] in ["raster", "vector", "file", "strds"]:

output_type = resource["export"]["type"]
output_path = None
Expand Down Expand Up @@ -516,6 +561,13 @@ def _export_resources(self, use_raster_region=False):
tmp_file = resource["tmp_file"]
output_name, output_path = self._export_file(
tmp_file=tmp_file, file_name=file_name)
elif output_type == "strds":
message = "Export strds layer <%s> with format %s" % (
file_name, resource["export"]["format"])
self._send_resource_update(message)
output_name, output_path = self._export_strds(
strds_name=file_name,
format=resource["export"]["format"])
else:
raise AsyncProcessTermination(
"Unknown export format %s" % output_type)
Expand Down