diff --git a/src/actinia_processing_lib/ephemeral_processing_with_export.py b/src/actinia_processing_lib/ephemeral_processing_with_export.py index deff8d0..23bbda9 100644 --- a/src/actinia_processing_lib/ephemeral_processing_with_export.py +++ b/src/actinia_processing_lib/ephemeral_processing_with_export.py @@ -216,7 +216,11 @@ def _export_strds(self, strds_name, format="GTiff"): return file_name, output_path def _export_vector( - self, vector_name, format="GPKG", additional_options=[] + self, + vector_name, + format="GPKG", + compressed="True", + additional_options=[], ): """ Export a specific vector layer with v.out.ogr using a specific output @@ -231,6 +235,10 @@ def _export_vector( vector_name (str): The name of the raster layer format (str): GPKG (default), GML, GeoJSON, ESRI_Shapefile, SQLite, CSV + compressed (str): Whether the output file should be compressed using + zip. Default is True. For ESRI Shapefile the + output will always be compressed, because of + multiple files. additional_options (list): Unused Returns: @@ -257,7 +265,7 @@ def _export_vector( # Remove a potential mapset file_name = vector_name.split("@")[0] + prefix - archive_name = file_name + ".zip" + # switch into the temporary working directory to use relative path for # zip os.chdir(self.temp_file_path) @@ -285,26 +293,39 @@ def _export_vector( self._update_num_of_steps(1) self._run_module(p) - # Compression - compressed_output_path = os.path.join( - self.temp_file_path, archive_name - ) + # ESRI Shapefiles need to be compressed due to multiple files + if format == "ESRI_Shapefile" or compressed == "True": - executable = "/usr/bin/zip" - args = ["-r", archive_name, file_name] + archive_name = file_name + ".zip" - p = Process( - exec_type="exec", - executable=executable, - executable_params=args, - id=f"exporter_zip_{vector_name}", - stdin_source=None, - ) + # Compression + compressed_output_path = os.path.join( + self.temp_file_path, archive_name + ) - self._update_num_of_steps(1) - self._run_process(p) + executable = "/usr/bin/zip" + args = ["-r", archive_name, file_name] + + p = Process( + exec_type="exec", + executable=executable, + executable_params=args, + id=f"exporter_zip_{vector_name}", + stdin_source=None, + ) + + self._update_num_of_steps(1) + self._run_process(p) - return archive_name, compressed_output_path + return archive_name, compressed_output_path + + # all other formats are exported as single files and can be directly + # exported + + # Save the file in the temporary directory of the temporary gisdb + output_path = os.path.join(self.temp_file_path, file_name) + + return file_name, output_path def _export_postgis( self, vector_name, dbstring, output_layer=None, additional_options=[] @@ -470,9 +491,13 @@ def _export_resources(self, use_raster_region=False): resource["export"]["format"], ) self._send_resource_update(message) + # set compressed to True by defalt _, output_path = self._export_vector( vector_name=file_name, format=resource["export"]["format"], + compressed=( + resource["export"].get("compressed", "True") + ), ) elif output_type == "file": message = "Export file <%s> with format %s" % (