@@ -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 ("\t matches:\t " + mr .getEdgeMatches ().size () + ", gps entries:" + inputGPXEntries .size ());
103+ System .out .println ("\t matches:\t " + mr .getEdgeMatches ().size () + ", gps entries:" + measurements .size ());
98104 System .out .println ("\t gpx length:\t " + (float ) mr .getGpxEntriesLength () + " vs " + (float ) mr .getMatchLength ());
99105 System .out .println ("\t gpx 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