Created
June 7, 2022 20:52
-
-
Save ExtReMLapin/06c370deb280138391ebc6dbc17f9ac9 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
#faire payer 40€ pour des GPX = gros chien de la casse | |
import json | |
import gpxpy | |
import gpxpy.gpx | |
# F12 + onglet network sur la page helloways et recuperer le endpoint du type https://www.helloways.com/api/tracks/5fa70d12b3963833d2cef03e | |
json_path = "input.json" | |
parsed_json = json.load(open(json_path)) | |
gpx = gpxpy.gpx.GPX() | |
# Create first track in our GPX: | |
gpx_track = gpxpy.gpx.GPXTrack() | |
gpx.tracks.append(gpx_track) | |
# Create first segment in our GPX track: | |
gpx_segment = gpxpy.gpx.GPXTrackSegment() | |
gpx_track.segments.append(gpx_segment) | |
# Create points: | |
for segment in parsed_json["path"]["features"][0]["geometry"]["coordinates"]: | |
gpx_segment.points.append(gpxpy.gpx.GPXTrackPoint(segment[1], segment[0], elevation=segment[2])) | |
i = 0 | |
for waypoint in parsed_json["waypoints"]: | |
if "coordinates" in waypoint: | |
gpx_wps = gpxpy.gpx.GPXWaypoint(waypoint["coordinates"][1], waypoint["coordinates"][0]) | |
gpx_wps.name = str(i) | |
gpx_wps.description = waypoint["waypoint"] | |
i = i + 1 | |
gpx.waypoints.append(gpx_wps) | |
# You can add routes and waypoints, too... | |
gpx_xml = gpx.to_xml() | |
with open("output.gpx", "w") as f: | |
f.write(gpx_xml) | |
print("wrote to output.gpx") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment