36 lines
1009 B
Python
36 lines
1009 B
Python
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)
|