This repository has been archived on 2022-04-22. You can view files and clone it, but cannot push or open issues or pull requests.
GPXprocessor/keep.py

36 lines
1009 B
Python
Raw Normal View History

2021-12-25 23:05:03 +08:00
import os
import gpxpy
import gpxpy.gpx
from ChangeCoordinate import ChangeCoord
def process(file):
gpx_file = open('./keep/'+file, 'r', encoding='utf-8')
gpx = gpxpy.parse(gpx_file)
ngpx = gpxpy.gpx.GPX()
gpx_track = gpxpy.gpx.GPXTrack()
ngpx.tracks.append(gpx_track)
gpx_segment = gpxpy.gpx.GPXTrackSegment()
gpx_track.segments.append(gpx_segment)
p = None
for track in gpx.tracks:
for segment in track.segments:
for point in segment.points:
if p and point.latitude == p.latitude and point.longitude == p.longitude:
continue
lon, lat = coord.gcj02_to_wgs84(point.longitude, point.latitude)
gpx_segment.points.append(gpxpy.gpx.GPXTrackPoint(lat, lon, time=point.time))
p = point
with open('./new/'+file, 'w', encoding='utf-8') as f:
f.write(ngpx.to_xml())
coord = ChangeCoord()
files = os.listdir('./keep')
for file in files:
process(file)