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

Converting property values using json.loads #113

Open
lyralemos opened this issue Nov 10, 2021 · 0 comments
Open

Converting property values using json.loads #113

lyralemos opened this issue Nov 10, 2021 · 0 comments

Comments

@lyralemos
Copy link

I have a small problem with feature properties from imported shapes.

The from_shapefile function tries to use json.loads to append the property value and fallback to the actual value in case of failure.

for feature in shape:
properties = {}
for prop, value in feature.get('properties', {}).items():
try:
properties[prop] = json.loads(value)
except (json.JSONDecodeError, TypeError):
properties[prop] = value

This is fine except that, if have a string property with only numbers json.loads will change it to integer as this example:

>>> a = '123'
>>> type(json.loads(a))
<class 'int'>

I guess this is not ideal for cases that depend o the property type to be precise, as mine is.

Wouldn't be a better approach to store properties as they came from fiona?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant