Last active
August 29, 2015 14:15
-
-
Save andrewgleave/e10faec6ef30aa880b5e to your computer and use it in GitHub Desktop.
Revisions
-
andrewgleave revised this gist
Feb 22, 2015 . 1 changed file with 3 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,4 @@ import ijson from couchdbkit import (Document, Server, StringProperty, DictProperty) @@ -11,7 +10,7 @@ class Route(Document): def main(): unnamed_count = 0 server = Server('https://xxxxxxxxx:xxxxxxxxx@redrobot.iriscouch.com') db = server.get_or_create_db('iom-walking-routes') Route.set_db(db) @@ -25,12 +24,9 @@ def main(): unnamed_count += 1 geometry = { 'type': 'LineString', 'coordinates': [[float(y) for y in x if y != 0.0] for x in route['geometry']['coordinates'][0]] } route = Route(id=name, geometry=geometry, properties=route['properties']) route.save() -
andrewgleave renamed this gist
Feb 22, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
andrewgleave created this gist
Feb 22, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ import ijson import html2text from couchdbkit import (Document, Server, StringProperty, DictProperty) class Route(Document): id = StringProperty() geometry = DictProperty() properties = DictProperty() def main(): unnamed_count = 0 server = Server('https://xxxxxxxxxxx:[email protected]') db = server.get_or_create_db('iom-walking-routes') Route.set_db(db) with open('routes.json') as file: for feature_list in ijson.items(file, 'features'): for route in feature_list: name = route['properties'].get('Name') if name in (None, 'NULL'): name = 'Unnamed Route %d' % (unnamed_count,) unnamed_count += 1 geometry = { 'type': 'LineString', 'coordinates': route['geometry']['coordinates'][0] } properties = route['properties']; properties['Description'] = html2text.html2text(route['properties'].get('Description', '')) route = Route(id=name, geometry=geometry, properties=properties) route.save() if __name__ == '__main__': main()