Skip to content

Commit

Permalink
#1: Add tracksegment splitter example.
Browse files Browse the repository at this point in the history
  • Loading branch information
jenetics committed Jul 12, 2022
1 parent e6447d7 commit 77e9caf
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions jpx/src/test/java/io/jenetics/jpx/tool/TrackSegments.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import static java.lang.String.format;

import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import io.jenetics.jpx.GPX;
import io.jenetics.jpx.Track;
import io.jenetics.jpx.TrackSegment;
import io.jenetics.jpx.WayPoint;

Expand Down Expand Up @@ -93,4 +97,15 @@ private static List<TrackSegment> toTrackSegments(
return segments;
}

public static void main(String[] args) throws IOException {
final GPX gpx = GPX.Reader.DEFAULT.read("some_file.gpx");

final Stream<WayPoint> points = gpx.tracks()
.flatMap(Track::segments)
.flatMap(TrackSegment::points);

final List<TrackSegment> segments = points
.collect(toTrackSegments(Duration.ofMinutes(1), 10));
}

}

0 comments on commit 77e9caf

Please sign in to comment.