Skip to content
This repository was archived by the owner on Mar 1, 2021. It is now read-only.

Commit 3eea6a5

Browse files
committed
Use same logic for time and validation in cli as in web
1 parent d828985 commit 3eea6a5

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

matching-web-bundle/src/main/java/com/graphhopper/matching/http/MapMatchingResource.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ public Response match(
9090
if (gpx.trk == null) {
9191
throw new IllegalArgumentException("No tracks found in GPX document. Are you using waypoints or routes instead?");
9292
}
93+
if (gpx.trk.size() > 1) {
94+
throw new IllegalArgumentException("GPX documents with multiple tracks not supported yet.");
95+
}
9396

9497
instructions = writeGPX || instructions;
9598

matching-web/src/main/java/com/graphhopper/matching/cli/MatchCommand.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,19 @@ public void run(Bootstrap bootstrap, Namespace args) {
8888
try {
8989
importSW.start();
9090
Gpx gpx = xmlMapper.readValue(gpxFile, Gpx.class);
91-
List<GPXEntry> inputGPXEntries = gpx.trk.get(0).getEntries();
91+
if (gpx.trk == null) {
92+
throw new IllegalArgumentException("No tracks found in GPX document. Are you using waypoints or routes instead?");
93+
}
94+
if (gpx.trk.size() > 1) {
95+
throw new IllegalArgumentException("GPX documents with multiple tracks not supported yet.");
96+
}
97+
List<GPXEntry> measurements = gpx.trk.get(0).getEntries();
9298
importSW.stop();
9399
matchSW.start();
94-
MatchResult mr = mapMatching.doWork(inputGPXEntries);
100+
MatchResult mr = mapMatching.doWork(measurements);
95101
matchSW.stop();
96102
System.out.println(gpxFile);
97-
System.out.println("\tmatches:\t" + mr.getEdgeMatches().size() + ", gps entries:" + inputGPXEntries.size());
103+
System.out.println("\tmatches:\t" + mr.getEdgeMatches().size() + ", gps entries:" + measurements.size());
98104
System.out.println("\tgpx length:\t" + (float) mr.getGpxEntriesLength() + " vs " + (float) mr.getMatchLength());
99105
System.out.println("\tgpx time:\t" + mr.getGpxEntriesMillis() / 1000f + " vs " + mr.getMatchMillis() / 1000f);
100106

@@ -104,7 +110,11 @@ public void run(Bootstrap bootstrap, Namespace args) {
104110
PathWrapper pathWrapper = new PathWrapper();
105111
new PathMerger().doWork(pathWrapper, Collections.singletonList(mr.getMergedPath()), tr);
106112
try (BufferedWriter writer = new BufferedWriter(new FileWriter(outFile))) {
107-
writer.append(pathWrapper.getInstructions().createGPX(gpx.trk.get(0).name != null ? gpx.trk.get(0).name : "", 0, hopper.hasElevation(), withRoute, true, false, Constants.VERSION));
113+
long time = System.currentTimeMillis();
114+
if (!measurements.isEmpty()) {
115+
time = measurements.get(0).getTime();
116+
}
117+
writer.append(pathWrapper.getInstructions().createGPX(gpx.trk.get(0).name != null ? gpx.trk.get(0).name : "", time, hopper.hasElevation(), withRoute, true, false, Constants.VERSION));
108118
}
109119
} catch (Exception ex) {
110120
importSW.stop();

0 commit comments

Comments
 (0)