Search in sources :

Example 6 with Observation

use of com.graphhopper.matching.Observation in project graphhopper by graphhopper.

the class TrkTest method test2NoMillis.

@Test
public void test2NoMillis() throws IOException {
    Gpx gpx = xmlMapper.readValue(getClass().getResourceAsStream("/test2_no_millis.gpx"), Gpx.class);
    List<Observation> gpxEntries = GpxConversions.getEntries(gpx.trk.get(0));
    assertEquals(3, gpxEntries.size());
    assertEquals(51.377719, gpxEntries.get(0).getPoint().lat, 0.0);
    assertEquals(12.338217, gpxEntries.get(0).getPoint().lon, 0.0);
}
Also used : Observation(com.graphhopper.matching.Observation) Gpx(com.graphhopper.jackson.Gpx) Test(org.junit.jupiter.api.Test)

Example 7 with Observation

use of com.graphhopper.matching.Observation in project graphhopper by graphhopper.

the class ExtendedJsonResponseTest method getGpxExtension.

private List<State> getGpxExtension() {
    List<State> list = new ArrayList<>();
    Snap snap1 = new Snap(-3.4445, -38.9990) {

        @Override
        public GHPoint3D getSnappedPoint() {
            return new GHPoint3D(-3.4446, -38.9996, 0);
        }
    };
    Snap snap2 = new Snap(-3.4445, -38.9990) {

        @Override
        public GHPoint3D getSnappedPoint() {
            return new GHPoint3D(-3.4449, -38.9999, 0);
        }
    };
    list.add(new State(new Observation(new GHPoint(-3.4446, -38.9996)), snap1));
    list.add(new State(new Observation(new GHPoint(-3.4448, -38.9999)), snap2));
    return list;
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) State(com.graphhopper.matching.State) VirtualEdgeIteratorState(com.graphhopper.routing.querygraph.VirtualEdgeIteratorState) GHPoint3D(com.graphhopper.util.shapes.GHPoint3D) ArrayList(java.util.ArrayList) Observation(com.graphhopper.matching.Observation) Snap(com.graphhopper.storage.index.Snap) GHPoint(com.graphhopper.util.shapes.GHPoint)

Example 8 with Observation

use of com.graphhopper.matching.Observation in project graphhopper by graphhopper.

the class MapMatchingTest method testClosePoints.

/**
 * This test is to check behavior over short tracks. GPX input:
 * https://graphhopper.com/maps/?point=51.342422%2C12.3613358&point=51.3423281%2C12.3613358&layer=Lyrk
 */
@ParameterizedTest
@ArgumentsSource(FixtureProvider.class)
public void testClosePoints(PMap hints) {
    MapMatching mapMatching = new MapMatching(graphHopper, hints);
    ResponsePath route = graphHopper.route(new GHRequest(new GHPoint(51.342422, 12.3613358), new GHPoint(51.342328, 12.3613358)).setProfile("my_profile")).getBest();
    List<Observation> inputGPXEntries = createRandomGPXEntriesAlongRoute(route);
    MatchResult mr = mapMatching.match(inputGPXEntries);
    assertFalse(mr.getEdgeMatches().isEmpty());
    assertEquals(3, mr.getMatchLength(), 1);
    // GraphHopper travel times aren't exactly additive
    assertThat(Math.abs(route.getTime() - mr.getMatchMillis()), is(lessThan(1000L)));
}
Also used : MapMatching(com.graphhopper.matching.MapMatching) ResponsePath(com.graphhopper.ResponsePath) GHRequest(com.graphhopper.GHRequest) Observation(com.graphhopper.matching.Observation) GHPoint(com.graphhopper.util.shapes.GHPoint) MatchResult(com.graphhopper.matching.MatchResult) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Aggregations

Observation (com.graphhopper.matching.Observation)8 GHPoint (com.graphhopper.util.shapes.GHPoint)5 ResponsePath (com.graphhopper.ResponsePath)4 Gpx (com.graphhopper.jackson.Gpx)4 MapMatching (com.graphhopper.matching.MapMatching)4 MatchResult (com.graphhopper.matching.MatchResult)4 GHRequest (com.graphhopper.GHRequest)3 Test (org.junit.jupiter.api.Test)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)3 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)1 GraphHopper (com.graphhopper.GraphHopper)1 GraphHopperConfig (com.graphhopper.GraphHopperConfig)1 EdgeMatch (com.graphhopper.matching.EdgeMatch)1 State (com.graphhopper.matching.State)1 VirtualEdgeIteratorState (com.graphhopper.routing.querygraph.VirtualEdgeIteratorState)1 Snap (com.graphhopper.storage.index.Snap)1 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)1 PMap (com.graphhopper.util.PMap)1 GHPoint3D (com.graphhopper.util.shapes.GHPoint3D)1