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

KeyError when trying to export layer with malformed geometry #48

Open
jacklinke opened this issue May 28, 2022 · 0 comments
Open

KeyError when trying to export layer with malformed geometry #48

jacklinke opened this issue May 28, 2022 · 0 comments

Comments

@jacklinke
Copy link

In cases where the geometry of a feature in a layer is incorrectly formed at (0, 0) the package in unable to build a shapefile.

Example feature:

{
  "type": "Feature",
  "id": 388,
  "geometry": {
    "type": "Point",
    "coordinates": [
      0,
      0
    ]
  },
  "properties": {
    "ObjectId": 3828,
    "globalid": "0f06bbf2-2ca6-4c49-9dcb-14185a826128",
    "CreationDate": 1648586723788,
    "field_1": 1647889200000,
    "field_6": null,
    "facility_type": "other",
    "facility_location_": null,
    "notes": null,
    "property_name": "Wash fan at walters camp",
    "observation_notes": null,
    "email": null,
    "email_report_to_inspector": null,
  }
}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/watervize/river_trip_2022_map_wfl1/venv/lib/python3.9/site-packages/restapi/common_types.py", line 335, in exportFeatureSet_os
    w.add_row(feat.getGeometry().asShape(), *row)
  File "/home/watervize/river_trip_2022_map_wfl1/venv/lib/python3.9/site-packages/restapi/open_restapi.py", line 368, in asShape
    return shapefile.Shape._from_geojson(self._native_json)
  File "/home/watervize/river_trip_2022_map_wfl1/venv/lib/python3.9/site-packages/restapi/shapefile.py", line 269, in _from_geojson
    geojType = geoj["type"] if geoj else "Null"
KeyError: 'type'

Updating line 269 of shapefile.py corrects the issue by setting features with malformed geometry to "Null"

from

geojType = geoj["type"] if geoj else "Null"

to

geojType = geoj.get("type", "Null") if geoj else "Null"
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