Created
September 12, 2016 14:49
-
-
Save paregorios/a9c5c5ac56879b3334ef4a8356ca510b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from shapely.geometry import MultiPoint, MultiPolygon, Point, Polygon, shape | |
with open(args.placefile, 'r') as f: | |
pj = json.load(f) | |
places = [] | |
for i, pd in enumerate(pj['@graph']): | |
try: | |
if i >= limit: | |
break | |
except TypeError: | |
pass | |
locations = [] | |
for f in pd['features']: | |
l = { | |
'geometry': shape(f['geometry']), | |
'id': f['id'], | |
'title': f['properties']['title'], | |
'description': f['properties']['description'], | |
'uri': f['properties']['link'], | |
'precision': f['properties']['location_precision'], | |
} | |
ll = [z for z in pd['locations'] if z['id'] == l['id']][0] | |
l['time-periods'] = [z['timePeriod'] for z in ll['attestations']] | |
locations.append(l) | |
points = [] | |
for l in locations: | |
g = l['geometry'] | |
if type(g) == Point: | |
points.append(g) | |
elif type(g) == Polygon: | |
points.extend( | |
[Point(coord) for coord in g.boundary._get_coords()]) | |
else: | |
raise Exception('boom') | |
points = MultiPoint(points) | |
places.append({ | |
'locations': locations, | |
'id': pd['id'], | |
'title': pd['title'], | |
'description': pd['description'], | |
'representative-point': Point(pd['reprPoint']), | |
'types': pd['placeTypes'], | |
'connects-with': pd['connectsWith'], | |
'uri': pd['uri'], | |
'convex-hull': points.convex_hull, | |
'envelope': points.envelope, | |
'type': 'feature' | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment