Search in sources :

Example 11 with Gpx

use of com.graphhopper.jackson.Gpx in project graphhopper by graphhopper.

the class MapMatching2Test method testIssue127.

@Test
public void testIssue127() throws IOException {
    GraphHopper hopper = new GraphHopper();
    hopper.setOSMFile("../map-matching/files/map-issue13.osm.gz");
    hopper.setGraphHopperLocation(GH_LOCATION);
    hopper.setProfiles(new Profile("my_profile").setVehicle("car").setWeighting("fastest"));
    hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("my_profile"));
    hopper.importOrLoad();
    MapMatching mapMatching = new MapMatching(hopper, new PMap().putObject("profile", "my_profile"));
    // query with two identical points
    Gpx gpx = xmlMapper.readValue(getClass().getResourceAsStream("/issue-127.gpx"), Gpx.class);
    MatchResult mr = mapMatching.match(GpxConversions.getEntries(gpx.trk.get(0)));
    // make sure no virtual edges are returned
    int edgeCount = hopper.getGraphHopperStorage().getAllEdges().length();
    for (EdgeMatch em : mr.getEdgeMatches()) {
        assertTrue(em.getEdgeState().getEdge() < edgeCount, "result contains virtual edges:" + em.getEdgeState().toString());
        validateEdgeMatch(em);
    }
    assertEquals(0, mr.getMatchMillis(), 50);
}
Also used : MapMatching(com.graphhopper.matching.MapMatching) EdgeMatch(com.graphhopper.matching.EdgeMatch) PMap(com.graphhopper.util.PMap) LMProfile(com.graphhopper.config.LMProfile) GraphHopper(com.graphhopper.GraphHopper) MatchResult(com.graphhopper.matching.MatchResult) Profile(com.graphhopper.config.Profile) LMProfile(com.graphhopper.config.LMProfile) Gpx(com.graphhopper.jackson.Gpx) Test(org.junit.jupiter.api.Test)

Example 12 with Gpx

use of com.graphhopper.jackson.Gpx in project graphhopper by graphhopper.

the class MapMatchingTest method testSmallSeparatedSearchDistance.

/**
 * This test is to check what happens when two GPX entries are on one edge
 * which is longer than 'separatedSearchDistance' - which is always 66m. GPX
 * input:
 * https://graphhopper.com/maps/?point=51.359723%2C12.360108&point=51.358748%2C12.358798&point=51.358001%2C12.357597&point=51.358709%2C12.356511&layer=Lyrk
 */
@ParameterizedTest
@ArgumentsSource(FixtureProvider.class)
public void testSmallSeparatedSearchDistance(PMap hints) throws IOException {
    Gpx gpx = xmlMapper.readValue(getClass().getResourceAsStream("/tour3-with-long-edge.gpx"), Gpx.class);
    MapMatching mapMatching = new MapMatching(graphHopper, hints);
    mapMatching.setMeasurementErrorSigma(20);
    MatchResult mr = mapMatching.match(GpxConversions.getEntries(gpx.trk.get(0)));
    assertEquals(Arrays.asList("Weinligstraße", "Fechnerstraße"), fetchStreets(mr.getEdgeMatches()));
    // TODO: this should be around 300m according to Google ... need to check
    assertEquals(mr.getGpxEntriesLength(), mr.getMatchLength(), 11);
}
Also used : MapMatching(com.graphhopper.matching.MapMatching) MatchResult(com.graphhopper.matching.MatchResult) Gpx(com.graphhopper.jackson.Gpx) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 13 with Gpx

use of com.graphhopper.jackson.Gpx in project graphhopper by graphhopper.

the class MapMatchingTest method testLoop2.

/**
 * This test is to check that loops are maintained. GPX input:
 * https://graphhopper.com/maps/?point=51.342439%2C12.361615&point=51.343719%2C12.362784&point=51.343933%2C12.361781&point=51.342325%2C12.362607&layer=Lyrk
 */
@ParameterizedTest
@ArgumentsSource(FixtureProvider.class)
public void testLoop2(PMap hints) throws IOException {
    MapMatching mapMatching = new MapMatching(graphHopper, hints);
    // TODO smaller sigma like 40m leads to U-turn at Tschaikowskistraße
    mapMatching.setMeasurementErrorSigma(50);
    Gpx gpx = xmlMapper.readValue(getClass().getResourceAsStream("/tour-with-loop.gpx"), Gpx.class);
    MatchResult mr = mapMatching.match(GpxConversions.getEntries(gpx.trk.get(0)));
    assertEquals(Arrays.asList("Jahnallee, B 87, B 181", "Funkenburgstraße", "Gustav-Adolf-Straße", "Tschaikowskistraße", "Jahnallee, B 87, B 181", "Lessingstraße"), fetchStreets(mr.getEdgeMatches()));
}
Also used : MapMatching(com.graphhopper.matching.MapMatching) MatchResult(com.graphhopper.matching.MatchResult) Gpx(com.graphhopper.jackson.Gpx) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 14 with Gpx

use of com.graphhopper.jackson.Gpx in project graphhopper by graphhopper.

the class TrkTest method testNoTrkseg.

@Test
public void testNoTrkseg() throws IOException {
    Gpx gpx = xmlMapper.readValue(getClass().getResourceAsStream("/no_trkseg.gpx"), Gpx.class);
    assertTrue(GpxConversions.getEntries(gpx.trk.get(0)).isEmpty());
}
Also used : Gpx(com.graphhopper.jackson.Gpx) Test(org.junit.jupiter.api.Test)

Aggregations

Gpx (com.graphhopper.jackson.Gpx)14 Test (org.junit.jupiter.api.Test)9 MapMatching (com.graphhopper.matching.MapMatching)8 MatchResult (com.graphhopper.matching.MatchResult)8 GraphHopper (com.graphhopper.GraphHopper)4 Observation (com.graphhopper.matching.Observation)4 PMap (com.graphhopper.util.PMap)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)4 LMProfile (com.graphhopper.config.LMProfile)3 Profile (com.graphhopper.config.Profile)3 EdgeMatch (com.graphhopper.matching.EdgeMatch)3 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)1 GraphHopperConfig (com.graphhopper.GraphHopperConfig)1 ResponsePath (com.graphhopper.ResponsePath)1 GHPoint (com.graphhopper.util.shapes.GHPoint)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1