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

Better handling writing from drivers without geometry #1188

Open
mwtoews opened this issue Jan 29, 2023 · 0 comments
Open

Better handling writing from drivers without geometry #1188

mwtoews opened this issue Jan 29, 2023 · 0 comments
Milestone

Comments

@mwtoews
Copy link
Member

mwtoews commented Jan 29, 2023

Not all OGR drivers write geometries, e.g. CSV. This can cause a supprise while writing:

import fiona

schema = {"geometry": "Point", "properties": {"zero": "int"}}
feature = {
    "geometry": {"type": "Point", "coordinates": (0, 0)},
    "properties": {"zero": "0"},
}

with fiona.open("test.csv", "w", driver="CSV", schema=schema) as ds:
    ds.write(feature)

raises

Traceback (most recent call last):

  Cell In[274], line 5
    collection.write(feature)

  File ~\AppData\Local\miniforge3\envs\pyforge\lib\site-packages\fiona\collection.py:367 in write
    self.writerecords([record])

  File ~\AppData\Local\miniforge3\envs\pyforge\lib\site-packages\fiona\collection.py:361 in writerecords
    self.session.writerecs(records, self)

  File fiona\ogrext.pyx:1291 in fiona.ogrext.WritingSession.writerecs

  File fiona\ogrext.pyx:354 in fiona.ogrext.OGRFeatureBuilder.build

  File fiona\_err.pyx:269 in fiona._err.exc_wrap_int

FionaCPLError: The wrapped function returned an error code, but no error message was set.

which originates from: https://github.com/Toblerity/Fiona/blob/1.8.22/fiona/ogrext.pyx#L351-L354

The driver can be modified to enable a geometry with GEOMETRY="AS_WKT" added to the fiona.open example above to allow it to work as expected. A better handling would not try to write the geometry for the features.

This demo is with Fiona 1.8.22 from conda-forge on Windows, but similar happens with Linux too.

@mwtoews mwtoews added this to the 2.0 milestone Jan 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant