diff options
| author | typebrook <typebrook@gmail.com> | 2020-02-27 16:32:37 +0800 |
|---|---|---|
| committer | typebrook <typebrook@gmail.com> | 2020-02-27 16:32:37 +0800 |
| commit | 00b136155183ae522ca458e540a8cf29bf525e74 (patch) | |
| tree | c6e9d20d5021c95afc7149456d57eb435d808150 /scripts/gpx | |
| parent | 3fa79eb14a4c0244fb2dc4a5b805b7cffaa63770 (diff) | |
update
Diffstat (limited to 'scripts/gpx')
| -rw-r--r-- | scripts/gpx/footer | 1 | ||||
| -rwxr-xr-x | scripts/gpx/gpx.check.py | 85 | ||||
| -rwxr-xr-x | scripts/gpx/gpx.merge_gpx.sh | 5 | ||||
| -rwxr-xr-x | scripts/gpx/gpx.merge_trk.sh | 4 | ||||
| -rw-r--r-- | scripts/gpx/header | 10 |
5 files changed, 0 insertions, 105 deletions
diff --git a/scripts/gpx/footer b/scripts/gpx/footer deleted file mode 100644 index d0759c0..0000000 --- a/scripts/gpx/footer +++ /dev/null | |||
| @@ -1 +0,0 @@ | |||
| 1 | </gpx> | ||
diff --git a/scripts/gpx/gpx.check.py b/scripts/gpx/gpx.check.py deleted file mode 100755 index 10be97c..0000000 --- a/scripts/gpx/gpx.check.py +++ /dev/null | |||
| @@ -1,85 +0,0 @@ | |||
| 1 | #!/usr/bin/env python3 | ||
| 2 | |||
| 3 | import sys | ||
| 4 | import os | ||
| 5 | import argparse | ||
| 6 | import copy | ||
| 7 | import fileinput | ||
| 8 | from osgeo import ogr | ||
| 9 | import osr | ||
| 10 | import urllib.parse | ||
| 11 | |||
| 12 | def rewrite_gpx(filename): | ||
| 13 | for line in fileinput.input(filename, inplace=True): | ||
| 14 | if fileinput.isfirstline() and "'" in line: | ||
| 15 | line = '<?xml version="1.0" encoding="UTF-8"?>' | ||
| 16 | if fileinput.filelineno() == 2 and "version" not in line: | ||
| 17 | line = line.replace('<gpx', '<gpx version="1.1"') | ||
| 18 | print(line.rstrip('\n')) | ||
| 19 | |||
| 20 | def check_valid(filename, threshold, add_prefix): | ||
| 21 | rewrite_gpx(filename) | ||
| 22 | |||
| 23 | driver = ogr.GetDriverByName('GPX') | ||
| 24 | try: | ||
| 25 | dataSource = driver.Open(filename) | ||
| 26 | except Exception: | ||
| 27 | pass | ||
| 28 | if dataSource is None: | ||
| 29 | print("could not open") | ||
| 30 | sys.exit(1) | ||
| 31 | |||
| 32 | inSpatialRef = osr.SpatialReference() | ||
| 33 | inSpatialRef.ImportFromEPSG(4326) | ||
| 34 | outSpatialRef = osr.SpatialReference() | ||
| 35 | outSpatialRef.ImportFromEPSG(3857) | ||
| 36 | to3857 = osr.CoordinateTransformation(inSpatialRef, outSpatialRef) | ||
| 37 | to4326 = osr.CoordinateTransformation(outSpatialRef, inSpatialRef) | ||
| 38 | |||
| 39 | trkLayer = dataSource.GetLayer(4) | ||
| 40 | trkpt = trkLayer.GetNextFeature() | ||
| 41 | flag = False | ||
| 42 | while trkpt: | ||
| 43 | nextTrkpt = trkLayer.GetNextFeature() | ||
| 44 | if nextTrkpt: | ||
| 45 | geom1 = trkpt.GetGeometryRef() | ||
| 46 | geom1.Transform(to3857) | ||
| 47 | geom2 = nextTrkpt.GetGeometryRef() | ||
| 48 | geom2.Transform(to3857) | ||
| 49 | distance = geom1.Distance(geom2) | ||
| 50 | |||
| 51 | geom1.Transform(to4326) | ||
| 52 | geom2.Transform(to4326) | ||
| 53 | if distance >= threshold: | ||
| 54 | if not flag: | ||
| 55 | print(f'{filename} has problem, the following urls shows the points with distance far from {threshold}m:') | ||
| 56 | print() | ||
| 57 | flag = True | ||
| 58 | if add_prefix: | ||
| 59 | dir = os.path.dirname(filename) | ||
| 60 | if dir: | ||
| 61 | dir += '/' | ||
| 62 | os.rename(filename, f'{dir}invalid_{os.path.basename(filename)}') | ||
| 63 | |||
| 64 | geojson = '{{"type": "LineString", "coordinates": [[{}, {}], [{}, {}]]}}'.format( | ||
| 65 | geom1.GetX(), geom1.GetY(), | ||
| 66 | geom2.GetX(), geom2.GetY() | ||
| 67 | ) | ||
| 68 | encoded = urllib.parse.quote(geojson) | ||
| 69 | print('http://geojson.io/#data=data:application/json,{}'.format(encoded)) | ||
| 70 | print() | ||
| 71 | else: | ||
| 72 | break | ||
| 73 | trkpt = nextTrkpt | ||
| 74 | |||
| 75 | def main(argv): | ||
| 76 | parser = argparse.ArgumentParser() | ||
| 77 | parser.add_argument('file', help="you can add multiple gpx files at the same time", nargs='+') | ||
| 78 | parser.add_argument("-i", help="add prefix to invalid files", action="store_true") | ||
| 79 | parser.add_argument("-d", help="distance of tolerance(m), 100 by default", dest="distance", default=100) | ||
| 80 | args = parser.parse_args() | ||
| 81 | for file in args.file: | ||
| 82 | check_valid(file, float(args.distance), args.i) | ||
| 83 | |||
| 84 | if __name__ == '__main__': | ||
| 85 | main(sys.argv) | ||
diff --git a/scripts/gpx/gpx.merge_gpx.sh b/scripts/gpx/gpx.merge_gpx.sh deleted file mode 100755 index 4b024a7..0000000 --- a/scripts/gpx/gpx.merge_gpx.sh +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | GPX_DIR=$(dirname $0) | ||
| 4 | |||
| 5 | sed '/<trk/,/<\/trk>/ p' -nr | cat $GPX_DIR/header - $GPX_DIR/footer | ||
diff --git a/scripts/gpx/gpx.merge_trk.sh b/scripts/gpx/gpx.merge_trk.sh deleted file mode 100755 index c3a72d4..0000000 --- a/scripts/gpx/gpx.merge_trk.sh +++ /dev/null | |||
| @@ -1,4 +0,0 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | sed '/<trk>/,/<\/name>/ d; /<\/trk>/ d; /<\/gpx>/ i \ \ <\/trk>' |\ | ||
| 4 | awk '/<trkseg>/ && !x {print " <trk>\n <name>combined_trk</name>"; x=1} 1' | ||
diff --git a/scripts/gpx/header b/scripts/gpx/header deleted file mode 100644 index 1912e8b..0000000 --- a/scripts/gpx/header +++ /dev/null | |||
| @@ -1,10 +0,0 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8" standalone="no" ?> | ||
| 2 | <gpx xmlns="http://www.topografix.com/GPX/1/1" creator="MapSource 6.10.2" 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"> | ||
| 3 | |||
| 4 | <metadata> | ||
| 5 | <link href="http://www.garmin.com"> | ||
| 6 | <text>Garmin International</text> | ||
| 7 | </link> | ||
| 8 | <time>2019-12-18T06:17:16Z</time> | ||
| 9 | <bounds maxlat="24.554773" maxlon="121.293261" minlat="24.534487" minlon="121.284309"/> | ||
| 10 | </metadata> | ||