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

Support optional schema properties for writing shapefiles #702

Open
klinden opened this issue Dec 27, 2018 · 3 comments
Open

Support optional schema properties for writing shapefiles #702

klinden opened this issue Dec 27, 2018 · 3 comments

Comments

@klinden
Copy link

klinden commented Dec 27, 2018

Expected behavior and actual behavior.

Desired: Given the following schema: [ 'ID', 'Name', 'Description'], a record { 'id': 1, 'Name': 'John Doe' } should successfully write to the shapefile either with an empty value for Description or possibly a pre-defined default value.

Actual: "ValueError: Record does not match collection schema" is raised.

Operating system

Mac OS X 10.14.2.

Fiona and GDAL version and provenance

Fiona 1.8.4 MacOS wheel installed with pip 18.1, Python 3.7.2
GDAL 2.3.1 installed via Homebrew

@klinden
Copy link
Author

klinden commented Dec 28, 2018

Not sure if the comment about defaultdict got deleted or something else happened. I did try using a defaultdict, but unfortunately that did not work either.

Could there possibly be an optional "strict" vs. "loose" schema validation that defaults to "strict" to prevent users from accidentally doing something they don't want to?

@sgillies
Copy link
Member

@klinden defaultdict almost works, but Fiona compares schema and feature properties keys and that's where defaultdict fails.

This is a reasonable feature request and related to others. In my mind, it's a bit blocked by discussion about the future of Fiona's schema system and properties validation, and will have to wait for a while.

I've got a stopgap solution, which you may have already considered, in which case I apologize. You always know the properties schema for a Collection opened in any mode. If your features are coming from another system that doesn't know this schema or only has a partial view of it, you can overlay those feature properties on default values using the standard behavior of Python's dict type:

feat['properties'] = dict(
    {k: None for k in collection.schema['properties'].keys()},
    **feat['properties']
)

@klinden
Copy link
Author

klinden commented Dec 28, 2018

No worries that makes sense. I did something similar to that and it is working well.

@sgillies sgillies added the schema label Jan 1, 2019
@sgillies sgillies added this to the 2.0 milestone Jul 4, 2020
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

2 participants