Gis export functions not working in tauw_legger_tool

Which tool versions are you using?

tauw_legger_tool

SDK: v13.6.0
Platform: v2023.07.0
Python: v3.10
Isolation mode: venv

Current Behavior

Exporting to shapefile or geopackage gives errors. Something because of fiona

Expected Behavior

Export to shapefile or geopackage used to work. But now all the export functions have to stopped working.

Context (optional, but preferred)

A project in the tauw_legger_tool has to be renewed. But the export functions have stopped working. The logging says that something is wrong with Fiona. Could it be that Fiona or Gdal have been updated recently on the viktor servers? Because I think Fiona is dependent on Gdal which might be the case.

Traceback for Geopackage:
Traceback (most recent call last):
File “fiona/_shim.pyx”, line 110, in fiona._shim.gdal_create
File “fiona/_err.pyx”, line 291, in fiona._err.exc_wrap_pointer
fiona._err.CPLE_OpenFailedError: sqlite3_open(temp3.gpkg) failed: unable to open database file
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “viktor_connector/connector.pyx”, line 295, in connector.Job.execute
File “viktor/core.pyx”, line 1837, in viktor.core._handle_job
File “viktor/core.pyx”, line 1803, in viktor.core._handle_job._handle_button
File “/home/user/src/app/legger_design/controller.py”, line 203, in download_gis_file
output_file = GisExporter(driver=driver).create_gis_file(trajectory_line=trajectory_linestring,
File “/home/user/src/app/legger_design/gis_exporter.py”, line 230, in create_gis_file
self._write_trajectory_line(trajectory_line, file_name=file_name, layer_name=“Trajectlijn”)
File “/home/user/src/app/legger_design/gis_exporter.py”, line 41, in _write_trajectory_line
with fiona.open(file_name, ‘w’, driver=self.driver, crs=self.crs, schema=trajectory_line_schema,
File “/usr/local/lib/python3.10/site-packages/fiona/env.py”, line 417, in wrapper
return f(*args, **kwargs)
File “/usr/local/lib/python3.10/site-packages/fiona/init.py”, line 280, in open
c = Collection(path, mode, crs=crs, driver=driver, schema=this_schema,
File “/usr/local/lib/python3.10/site-packages/fiona/collection.py”, line 165, in init
self.session.start(self, **kwargs)
File “fiona/ogrext.pyx”, line 1010, in fiona.ogrext.WritingSession.start
File “fiona/ogrext.pyx”, line 1011, in fiona.ogrext.WritingSession.start
File “fiona/_shim.pyx”, line 114, in fiona._shim.gdal_create
fiona.errors.DriverError: sqlite3_open(temp3.gpkg) failed: unable to open database file

Traceback for shapefiles:
Traceback (most recent call last):
File “fiona/ogrext.pyx”, line 1133, in fiona.ogrext.WritingSession.start
File “fiona/_err.pyx”, line 291, in fiona._err.exc_wrap_pointer
fiona._err.CPLE_AppDefinedError: Failed to create file Trajectlijn.shp: Permission denied
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “viktor_connector/connector.pyx”, line 295, in connector.Job.execute
File “viktor/core.pyx”, line 1837, in viktor.core._handle_job
File “viktor/core.pyx”, line 1803, in viktor.core._handle_job._handle_button
File “/home/user/src/app/legger_design/controller.py”, line 203, in download_gis_file
output_file = GisExporter(driver=driver).create_gis_file(trajectory_line=trajectory_linestring,
File “/home/user/src/app/legger_design/gis_exporter.py”, line 252, in create_gis_file
self._write_trajectory_line(trajectory_line, file_name=f"Trajectlijn{extension}")
File “/home/user/src/app/legger_design/gis_exporter.py”, line 41, in _write_trajectory_line
with fiona.open(file_name, ‘w’, driver=self.driver, crs=self.crs, schema=trajectory_line_schema,
File “/usr/local/lib/python3.10/site-packages/fiona/env.py”, line 417, in wrapper
return f(*args, **kwargs)
File “/usr/local/lib/python3.10/site-packages/fiona/init.py”, line 280, in open
c = Collection(path, mode, crs=crs, driver=driver, schema=this_schema,
File “/usr/local/lib/python3.10/site-packages/fiona/collection.py”, line 165, in init
self.session.start(self, **kwargs)
File “fiona/ogrext.pyx”, line 1141, in fiona.ogrext.WritingSession.start
fiona.errors.DriverIOError: Failed to create file Trajectlijn.shp: Permission denied

Hi Sjoerd,

Thanks for raising this. For me to check whether this is indeed a bug on our side, or some other change that may have affected your code, is it possible to provide a snippet of code from which I can work? Feel free to strip any sensitive information from the code, as long as the snippet is clear.

Also, did you obtain the traceback from your local terminal during development, or from the reported error that was sent via email when the error was reported in production?

Hi Marcel,

Here is the gis_exporter script in which we use fiona. Hopefully you can find something about it.

gis_exporter copy.py (3.2 KB)

@mslootweg Is it possible to read what goes wrong in the logging of the App? Maybe that gives us an idea of what is happening. Hope to hear from you soon!

Hi Sjoerd,

I have not had time yet to look at the python script you sent (thanks for that, by the way!). If you would like to inspect what is going wrong with an app in production, the platform provides the functionality of reporting a problem. When it breaks at an unexpected line in the code, a error message appears that states something in the lines of “Something went wrong”. This error is presented together with a “Report problem” button. If pressed, this will send an email to the maintainer(s) of that app. Here you as maintainer will be able to inspect the stack trace error, as well as the parameters that were used for that case.

Resolved the issue offline:

If the fiona.open() function is called with a filename (string), fiona generates files on the local disk.

it is better to handle everything in memory:

def some_function(...)->File:
    output_file = File()
    with output_file.open_binary() as fp:
        with fiona.open(fp, ....) as record:
            record.write(.....)
    
    return output_file
2 Likes