}
return rtes;
}
private List<Gpx.Trk> createTrack(GpxRoute route, int startIndex, int endIndex) {
ObjectFactory objectFactory = new ObjectFactory();
List<Gpx.Trk> trks = new ArrayList<Gpx.Trk>();
Gpx.Trk trk = route.getOrigin(Gpx.Trk.class);
if (trk != null && reuseReadObjectsForWriting)
trk.getTrkseg().clear();
else
trk = objectFactory.createGpxTrk();
if (isWriteMetaData()) {
trk.setName(asRouteName(route.getName()));
trk.setDesc(asDescription(route.getDescription()));
}
trks.add(trk);
Gpx.Trk.Trkseg trkseg = objectFactory.createGpxTrkTrkseg();
List<GpxPosition> positions = route.getPositions();
for (int i = startIndex; i < endIndex; i++) {
GpxPosition position = positions.get(i);
BigDecimal latitude = formatPosition(position.getLatitude());
BigDecimal longitude = formatPosition(position.getLongitude());
if(latitude == null || longitude == null)
continue;
Gpx.Trk.Trkseg.Trkpt trkpt = position.getOrigin(Gpx.Trk.Trkseg.Trkpt.class);
if (trkpt == null || !reuseReadObjectsForWriting)
trkpt = objectFactory.createGpxTrkTrksegTrkpt();
trkpt.setLat(latitude);
trkpt.setLon(longitude);
trkpt.setTime(isWriteTime() ? formatTime(position.getTime()) : null);
trkpt.setEle(isWriteElevation() ? formatElevation(position.getElevation()) : null);
trkpt.setCourse(isWriteHeading() ? formatHeading(position.getHeading()) : null);