Skip to content

Commit

Permalink
add GPX export to pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
bdgrichards committed Jul 1, 2024
1 parent 0902ce6 commit be9615c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 48 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ jobs:
echo "These outputs are missing: $GONE"
exit 1
fi
- name: create GPX from KML
run: python3 ./scripts/kml_to_gpx.py --fname_in ./outputs/plateau.kml --fname_out ./outputs/plateau.gpx
#=========================== PROCESS OUTPUT ===========================#
- name: Compress PDFs
run: |
Expand Down Expand Up @@ -168,3 +170,4 @@ jobs:
./outputs/*.pdf
./outputs/*.svg
./outputs/*.kml
./outputs/*.gpx
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,14 @@ You can download the following artifacts:

All surveyed and GPS logged entrances in the area surrounding the system.

Uploading the KML file into Google My Maps (or Google Earth) and then syncing to your phone allows for navigation of the plateau without a club GPS. KML files can easily be converted online into GPX files for use with Garmins etc.
Uploading the KML or GPX files into Google My Maps, Google Earth, OsmAnd etc. allows for navigation of the plateau without a club GPS.

Many of the GPS coordinates are very inaccurate and are currently being renewed as part of the [surface atlas project](https://github.com/iccaving/migovec-survey-data/blob/master/data/GPS/surface_atlas.md).

- 3D Model
[3D](https://github.com/iccaving/migovec-survey-data/releases/download/latest/plateau.3d)
- KML (Google Maps)
[KML](https://github.com/iccaving/migovec-survey-data/releases/download/latest/plateau.kml)
- Coordinate maps
[GPX](https://github.com/iccaving/migovec-survey-data/releases/download/latest/plateau.gpx) | [KML](https://github.com/iccaving/migovec-survey-data/releases/download/latest/plateau.kml)

## Prerequisites

Expand Down
45 changes: 0 additions & 45 deletions data/GPS/kml_to_gpx.py

This file was deleted.

58 changes: 58 additions & 0 deletions scripts/kml_to_gpx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import argparse

class Point():
name: str
lat: float
lon: float
elevation: float

def __init__(self, name, lat, lon, elevation):
self.name = name
self.lat = lat
self.lon = lon
self.elevation = elevation

# hacky way to convert the KML file into a useable GPX file
# pls tidy this up if you come across it and are suitably shocked
def get_gpx_from_kml(fname_in: str, fname_out: str = '../../outputs/plateau.gpx'):
# open KML file
with open(fname_in) as kml_file:
# get data from KML file
kml_points = kml_file.read().split("<Placemark>")[1:]
gpx_points = []
for point in kml_points:
point[1:]
name = point.split('<name><![CDATA[')[1].split(']')[0]
position = point.split("<Point>\n<coordinates>")[1].split(
"</coordinates>")[0]
lon = position.split(",")[0]
lat = position.split(",")[1]
ele = position.split(",")[2]

gpx_point = Point(name=name, lat=lat, lon=lon, elevation=ele)
gpx_points.append(gpx_point)

gpx_start_text = '<?xml version="1.0" encoding="UTF-8" standalone="no" ?><gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3" xmlns:wptx1="http://www.garmin.com/xmlschemas/WaypointExtension/v1" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" creator="eTrex 22x" version="1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www8.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/TrackStatsExtension/v1 http://www8.garmin.com/xmlschemas/TrackStatsExtension.xsd http://www.garmin.com/xmlschemas/WaypointExtension/v1 http://www8.garmin.com/xmlschemas/WaypointExtensionv1.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd"><metadata><link href="http://www.garmin.com"><text>Garmin International</text></link><time>2023-07-17T11:12:53Z</time></metadata>'
gpx_end_text = "</gpx>"

# create the GPX file contents
gpx_contents = gpx_start_text
for p in gpx_points:
gpx_wpt = f'<wpt lat="{p.lat}" lon="{p.lon}"><ele>{p.elevation}</ele><name>{p.name}</name><sym>Flag, Blue</sym></wpt>'
gpx_contents += gpx_wpt
gpx_contents += gpx_end_text

with open(fname_out, "x") as gpx_file:
# write gpx contents to new file
gpx_file.write(gpx_contents)

def parse_args():
parser = argparse.ArgumentParser(description="Create a GPX for from a text or KML file input")
parser.add_argument("--fname_in", type = str, help = "Input file name in same directory")
parser.add_argument("--fname_out", type = str, help = "Output file name in same directory", default = "out.gpx")
parser.add_argument("--ftype_in", type = str, help = "Type of file to convert. Options are \'txt\' or \'kml\'", default = "txt")
return parser.parse_args()

if __name__ == "__main__":
args = parse_args()
get_gpx_from_kml(args.fname_in, args.fname_out)

0 comments on commit be9615c

Please sign in to comment.