CityofSantaMonica / mds-provider

Python tools for working with MDS Provider data
https://github.com/openmobilityfoundation/mobility-data-specification
MIT License
18 stars 20 forks source link

Resolve key error and generate valid geoJSON #68

Closed rgangopadhya closed 5 years ago

rgangopadhya commented 5 years ago

From @genhernandez in https://github.com/CityofSantaMonica/mds-provider/pull/63 (which is included in this PR, with some modifications to generate valid geoJSON):

According to http://geojson.org/, the Feature geojson expects that coordinates be nested under geometry. to_feature was originally creating objects where the coordinates were not nested, leading to KeyErrors when extract_point is called.

Before this change:

import shapely
from mds.json import parse_boundary, to_feature, extract_point
from mds.fake import geometry
boundary = parse_boundary('https://gist.githubusercontent.com/rgangopadhya/6b38d2a7af5c75ebda68ce2aa7393f79/raw/be047c39d4e11454fda58abc747aeba30bf88a8c/sm.geojson')
point = geometry.point_within(boundary)
feature = to_feature(point, properties=dict())
extract_point(feature)

Results in:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/raja/dev/external/mds-provider/mds/json.py", line 44, in extract_point
    coords = feature["geometry"]["coordinates"]

In addition, the resulting feature was invalid geoJSON: type needs to be at the top level as Feature AND in geometry as whatever it needs to be.

After this change:

<shapely.geometry.point.Point object at 0x121005208>
rgangopadhya commented 5 years ago

@thekaveman I believe this blocks all users from using this (at least, it did for me) so would be great to get a look over this. It's possible that the simpler fix is to pin a version of shapely.

thekaveman commented 5 years ago

This looks good pending that minor quotes change. Thanks for the catch, and the patience in awaiting review.

rgangopadhya commented 5 years ago

Thanks @thekaveman, done!