private GpxType recycleGpxType(GpxRoute route) { GpxType gpxType = route.getOrigin(GpxType.class); if (gpxType != null) { gpxType.getRte().clear(); gpxType.getTrk().clear(); gpxType.getWpt().clear(); } return gpxType; }
private GpxRoute extractWayPoints( GpxType gpxType, boolean hasSpeedInMeterPerSecondInsteadOfKilometerPerHour) { String name = gpxType.getMetadata() != null ? gpxType.getMetadata().getName() : null; String desc = gpxType.getMetadata() != null ? gpxType.getMetadata().getDesc() : null; List<String> descriptions = asDescription(desc); List<GpxPosition> positions = extractWayPoints(gpxType.getWpt(), hasSpeedInMeterPerSecondInsteadOfKilometerPerHour); return positions.size() == 0 ? null : new GpxRoute(this, Waypoints, name, descriptions, positions, gpxType); }
void process(GpxType gpxType, ParserContext<GpxRoute> context) { if (gpxType == null || !VERSION.equals(gpxType.getVersion())) return; boolean hasSpeedInMeterPerSecondInsteadOfKilometerPerHour = gpxType.getCreator() != null && ("GPSTracker".equals(gpxType.getCreator()) || "nl.sogeti.android.gpstracker".equals(gpxType.getCreator()) || gpxType.getCreator().contains("TrekBuddy") || gpxType.getCreator().contains("BikeNav")); GpxRoute wayPointsAsRoute = extractWayPoints(gpxType, hasSpeedInMeterPerSecondInsteadOfKilometerPerHour); if (wayPointsAsRoute != null) context.appendRoute(wayPointsAsRoute); context.appendRoutes(extractRoutes(gpxType, hasSpeedInMeterPerSecondInsteadOfKilometerPerHour)); context.appendRoutes(extractTracks(gpxType, hasSpeedInMeterPerSecondInsteadOfKilometerPerHour)); }
private GpxType createGpxType(List<GpxRoute> routes) { ObjectFactory objectFactory = new ObjectFactory(); GpxType gpxType = null; for (GpxRoute route : routes) { gpxType = recycleGpxType(route); if (gpxType != null) break; } if (gpxType == null) gpxType = objectFactory.createGpxType(); gpxType.setCreator(GENERATED_BY); gpxType.setVersion(VERSION); for (GpxRoute route : routes) { switch (route.getCharacteristics()) { case Waypoints: gpxType.setMetadata(createMetaData(route, gpxType)); gpxType.getWpt().addAll(createWayPoints(route, 0, route.getPositionCount())); break; case Route: gpxType.getRte().addAll(createRoute(route, 0, route.getPositionCount())); break; case Track: gpxType.getTrk().addAll(createTrack(route, 0, route.getPositionCount())); break; default: throw new IllegalArgumentException( "Unknown RouteCharacteristics " + route.getCharacteristics()); } } return gpxType; }
private MetadataType createMetaData(GpxRoute route, GpxType gpxType) { ObjectFactory objectFactory = new ObjectFactory(); MetadataType metadataType = gpxType.getMetadata(); if (metadataType == null) metadataType = objectFactory.createMetadataType(); if (isWriteName()) { metadataType.setName(asRouteName(route.getName())); metadataType.setDesc(asDescription(route.getDescription())); } return metadataType; }
private List<GpxRoute> extractTracks( GpxType gpxType, boolean hasSpeedInMeterPerSecondInsteadOfKilometerPerHour) { List<GpxRoute> result = new ArrayList<GpxRoute>(); for (TrkType trkType : gpxType.getTrk()) { String name = trkType.getName(); String desc = trkType.getDesc(); List<String> descriptions = asDescription(desc); List<GpxPosition> positions = extractTrack(trkType, hasSpeedInMeterPerSecondInsteadOfKilometerPerHour); result.add(new GpxRoute(this, Track, name, descriptions, positions, gpxType, trkType)); } return result; }
private GpxType createGpxType(GpxRoute route, int startIndex, int endIndex) { ObjectFactory objectFactory = new ObjectFactory(); GpxType gpxType = recycleGpxType(route); if (gpxType == null) gpxType = objectFactory.createGpxType(); gpxType.setCreator(GENERATED_BY); gpxType.setVersion(VERSION); if (route.getCharacteristics().equals(Waypoints)) gpxType.setMetadata(createMetaData(route, gpxType)); gpxType.getWpt().addAll(createWayPoints(route, startIndex, endIndex)); gpxType.getRte().addAll(createRoute(route, startIndex, endIndex)); gpxType.getTrk().addAll(createTrack(route, startIndex, endIndex)); return gpxType; }
private List<GpxRoute> extractRoutes( GpxType gpxType, boolean hasSpeedInMeterPerSecondInsteadOfKilometerPerHour) { List<GpxRoute> result = new ArrayList<GpxRoute>(); for (RteType rteType : gpxType.getRte()) { String name = rteType.getName(); String desc = rteType.getDesc(); List<String> descriptions = asDescription(desc); List<GpxPosition> positions = extractRoute(rteType, hasSpeedInMeterPerSecondInsteadOfKilometerPerHour); result.add(new GpxRoute(this, Route, name, descriptions, positions, gpxType, rteType)); // Garmin Extensions v3 if (rteType.getExtensions() != null && rteType.getExtensions().getAny().size() > 0) { List<GpxPosition> extendedPositions = extractRouteWithGarminExtensions( rteType, hasSpeedInMeterPerSecondInsteadOfKilometerPerHour); result.add( new GpxRoute(this, Track, name, descriptions, extendedPositions, gpxType, rteType)); } } return result; }