Skip to content
Open
Changes from all commits
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
61 changes: 43 additions & 18 deletions src/actinia_processing_lib/ephemeral_processing_with_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@
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
Expand All @@ -231,6 +235,10 @@
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

Check failure on line 238 in src/actinia_processing_lib/ephemeral_processing_with_export.py

View workflow job for this annotation

GitHub Actions / lint / ruff

Ruff (E501)

src/actinia_processing_lib/ephemeral_processing_with_export.py:238:80: E501 Line too long (80 > 79)
zip. Default is True. For ESRI Shapefile the
output will always be compressed, because of
multiple files.
additional_options (list): Unused

Returns:
Expand All @@ -257,7 +265,7 @@

# 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)
Expand Down Expand Up @@ -285,26 +293,39 @@
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=[]
Expand Down Expand Up @@ -470,9 +491,13 @@
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" % (
Expand Down
Loading