routeName = '%s_%s-%s_%s' % (route['locations'][0]['street'], route['locations'][0]['adminArea5'],route['locations'][-1]['street'], route['locations'][-1]['adminArea5']) json.dump(r.json(), open('%s_route.json' % routeName, 'w')) json.dump(r2.json(), open('%s_elevation.json' % routeName, 'w')) elResp = r2.json() distances = [] height = [] speedlimits = [] for i in range(0, len(elResp['elevationProfile']) - 1): p = elResp['elevationProfile'][i] distances.append(round(p['distance'] * 1000)) height.append(p['height']) lat1, lon1 = elResp['shapePoints'][2*i:2*i + 2] lat2, lon2 = elResp['shapePoints'][2*i + 2:2*i + 4] curSpeed = maxspeed(lon1, lat1, lon2, lat2) if curSpeed >= 0: speedlimits.append(curSpeed) elif i >= 1: print('No maxspeed information') speedlimits.append(speedlimits[i - 1]) else: print('No maxspeed information') speedlimits.append(0) with open('%s.csv' % routeName, 'w') as f: writer = csv.writer(f, delimiter=';') for i in range(0, len(distances)): writer.writerow([distances[i], height[i], speedlimits[i]])
import srtm import gpxpy import requests import sys from common import maxspeed if len(sys.argv) < 2: print("Provide a .gpx file to convert") exit(1) gpx = gpxpy.parse(open(sys.argv[1])) elevation_data = srtm.get_data() elevation_data.add_elevations(gpx) #, smooth=True) lastPoint = gpx.tracks[0].segments[0].points[0] distance = 0 i = 0 with open(sys.argv[1][:-4] + '.csv', 'w') as f: for track in gpx.tracks: for segment in track.segments: for point in segment.points: distance += math.sqrt(math.pow(point.latitude-lastPoint.latitude, 2)+math.pow(point.longitude-lastPoint.longitude, 2)) speed = maxspeed(point.longitude, point.latitude, lastPoint.longitude, lastPoint.latitude) lastPoint = point f.write("%d;%f;%f\n" % (distance*100000, point.elevation, speed)) progress = i/len(segment.points) print '\r[{0}] {1}%'.format('#'*(progress/10), progress), i += 1