Skip to content

Instantly share code, notes, and snippets.

@nmxcgeo
Last active September 8, 2020 02:58
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmxcgeo/739e87333f61234aff5a32bbf735cef7 to your computer and use it in GitHub Desktop.
Save nmxcgeo/739e87333f61234aff5a32bbf735cef7 to your computer and use it in GitHub Desktop.
Convert Openstreetmap Geojson to CSV for https://github.com/rkistner/chinese-postman
import json
import geopy.distance
with open('test.json') as f:
data = json.load(f)
allnodes = {}
for feature in data['elements']:
if feature['type'] == 'node':
allnodes[feature['id']] = (feature['lat'], feature['lon'])
/*Split all ways into ways with just two nodes and output csv format described in https://github.com/rkistner/chinese-postman#command-line-usage */
for feature in data['elements']:
if feature['type'] == 'way':
for node in range(0, len(feature['nodes'])-1):
print str(feature['nodes'][node])+','+str(feature['nodes'][node+1])+','+str(geopy.distance.distance(allnodes[feature['nodes'][node]], allnodes[feature['nodes'][node+1]]).km*1000)+','+str(feature['nodes'][node])+'_'+str(feature['nodes'][node+1])+','+str(allnodes[feature['nodes'][node]][1])+','+str(allnodes[feature['nodes'][node]][0])+','+str(allnodes[feature['nodes'][node+1]][1])+','+str(allnodes[feature['nodes'][node+1]][0])
First try to create GPX-routes for Mapillary drives to cover a whole area:
Overpass-Turbo Query:
[out:json][timeout:25];
// gather results
(
way["highway"="residential"]({{bbox}});
way["highway"="unclassified"]({{bbox}});
way["highway"="tertiary"]({{bbox}});
way["highway"="secondary"]({{bbox}});
way["highway"="primary"]({{bbox}});
way["highway"="living_street"]({{bbox}});
way["highway"="trunk"]({{bbox}});
way["highway"="motorway"]({{bbox}});
way["highway"="motorway_link"]({{bbox}});
way["highway"="road"]({{bbox}});
)->.streets;
(
way["access"="no"]({{bbox}});
way["access"="private"]({{bbox}});
way["access"="customers"]({{bbox}});
way["access"="destination"]({{bbox}});
way["motor_vehicle"="no"]({{bbox}});
way["motor_vehicle"="private"]({{bbox}});
way["motor_vehicle"="customers"]({{bbox}});
way["motor_vehicle"="destination"]({{bbox}});
)->.restricted_access;
(
way.streets["motor_vehicle"="yes"]({{bbox}});
way.streets["motor_vehicle"="permissive"]({{bbox}});
way.streets["motor_vehicle"="designated"]({{bbox}});
way.streets["motor_vehicle"="public"]({{bbox}});
)->.motor_granted;
((.streets; - .restricted_access;); .motor_granted;);
// print results
/*added by auto repair*/
(._;>;);
/*end of auto repair*/
out;
$python convert.py | python chinese-postman/postman.py --csv path.csv --gpx path.gpx /dev/stdin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment