38 lines
986 B
Text
38 lines
986 B
Text
import 'package:gpx/gpx.dart';
|
|
import 'package:latlong2/latlong.dart';
|
|
import 'package:aves/model/activity/activity_track.dart';
|
|
import 'gps_smoothing.dart';
|
|
|
|
class GpxActivityParser {
|
|
static ActivityTrack parse(String xml, {required String fileName}) {
|
|
final gpx = GpxReader().fromString(xml);
|
|
|
|
final points = <LatLng>[];
|
|
final elevations = <double?>[];
|
|
final times = <DateTime?>[];
|
|
|
|
for (final trk in gpx.trks) {
|
|
for (final seg in trk.trksegs) {
|
|
for (final p in seg.trkpts) {
|
|
points.add(LatLng(p.lat!, p.lon!));
|
|
elevations.add(p.ele);
|
|
times.add(p.time);
|
|
}
|
|
}
|
|
}
|
|
|
|
final smoothed = GpsSmoothing.douglasPeucker(points, 5.0);
|
|
|
|
return ActivityTrack(
|
|
name: fileName,
|
|
format: 'GPX',
|
|
tracks: {smoothed},
|
|
pointCount: smoothed.length,
|
|
distanceMeters: null,
|
|
elevationGainMeters: null,
|
|
duration: null,
|
|
startTime: times.first,
|
|
sport: null,
|
|
);
|
|
}
|
|
}
|