Skip to content

Instantly share code, notes, and snippets.

@andrewgleave
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save andrewgleave/e10faec6ef30aa880b5e to your computer and use it in GitHub Desktop.

Select an option

Save andrewgleave/e10faec6ef30aa880b5e to your computer and use it in GitHub Desktop.

Revisions

  1. andrewgleave revised this gist Feb 22, 2015. 1 changed file with 3 additions and 7 deletions.
    10 changes: 3 additions & 7 deletions GeoJSON2Couch.py
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    import ijson
    import html2text
    from couchdbkit import (Document, Server, StringProperty, DictProperty)


    @@ -11,7 +10,7 @@ class Route(Document):

    def main():
    unnamed_count = 0
    server = Server('https://xxxxxxxxxxx:xxxxxxxxxxx@redrobot.iriscouch.com')
    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': route['geometry']['coordinates'][0]
    'coordinates': [[float(y) for y in x if y != 0.0] for x in route['geometry']['coordinates'][0]]
    }
    properties = route['properties'];
    properties['Description'] = html2text.html2text(route['properties'].get('Description', ''))

    route = Route(id=name, geometry=geometry, properties=properties)
    route = Route(id=name, geometry=geometry, properties=route['properties'])
    route.save()


  2. andrewgleave renamed this gist Feb 22, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. andrewgleave created this gist Feb 22, 2015.
    38 changes: 38 additions & 0 deletions GeoJSON2Couch
    Original 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()