Search in sources :

Example 66 with GHPoint

use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.

the class QueryGraphTest method testOneVirtualNode.

@Test
public void testOneVirtualNode() {
    initGraph(g);
    EdgeExplorer expl = g.createEdgeExplorer();
    // snap directly to tower node => pointList could get of size 1?!?      
    // a)
    EdgeIterator iter = expl.setBaseNode(2);
    iter.next();
    QueryGraph queryGraph = new QueryGraph(g);
    QueryResult res = createLocationResult(1, -1, iter, 0, TOWER);
    queryGraph.lookup(Arrays.asList(res));
    assertEquals(new GHPoint(0, 0), res.getSnappedPoint());
    // b)
    res = createLocationResult(1, -1, iter, 1, TOWER);
    queryGraph = new QueryGraph(g);
    queryGraph.lookup(Arrays.asList(res));
    assertEquals(new GHPoint(1, 0), res.getSnappedPoint());
    // c)
    iter = expl.setBaseNode(1);
    iter.next();
    res = createLocationResult(1.2, 2.7, iter, 0, TOWER);
    queryGraph = new QueryGraph(g);
    queryGraph.lookup(Arrays.asList(res));
    assertEquals(new GHPoint(1, 2.5), res.getSnappedPoint());
    // node number stays
    assertEquals(3, queryGraph.getNodes());
    // snap directly to pillar node
    queryGraph = new QueryGraph(g);
    iter = expl.setBaseNode(1);
    iter.next();
    res = createLocationResult(2, 1.5, iter, 1, PILLAR);
    queryGraph.lookup(Arrays.asList(res));
    assertEquals(new GHPoint(1.5, 1.5), res.getSnappedPoint());
    assertEquals(3, res.getClosestNode());
    assertEquals(4, getPoints(queryGraph, 0, 3).getSize());
    assertEquals(2, getPoints(queryGraph, 3, 1).getSize());
    queryGraph = new QueryGraph(g);
    res = createLocationResult(2, 1.7, iter, 1, PILLAR);
    queryGraph.lookup(Arrays.asList(res));
    assertEquals(new GHPoint(1.5, 1.5), res.getSnappedPoint());
    assertEquals(3, res.getClosestNode());
    assertEquals(4, getPoints(queryGraph, 0, 3).getSize());
    assertEquals(2, getPoints(queryGraph, 3, 1).getSize());
    // snap to edge which has pillar nodes        
    queryGraph = new QueryGraph(g);
    res = createLocationResult(1.5, 2, iter, 0, EDGE);
    queryGraph.lookup(Arrays.asList(res));
    assertEquals(new GHPoint(1.300019, 1.899962), res.getSnappedPoint());
    assertEquals(3, res.getClosestNode());
    assertEquals(4, getPoints(queryGraph, 0, 3).getSize());
    assertEquals(2, getPoints(queryGraph, 3, 1).getSize());
    // snap to edge which has no pillar nodes
    queryGraph = new QueryGraph(g);
    iter = expl.setBaseNode(2);
    iter.next();
    res = createLocationResult(0.5, 0.1, iter, 0, EDGE);
    queryGraph.lookup(Arrays.asList(res));
    assertEquals(new GHPoint(0.5, 0), res.getSnappedPoint());
    assertEquals(3, res.getClosestNode());
    assertEquals(2, getPoints(queryGraph, 0, 3).getSize());
    assertEquals(2, getPoints(queryGraph, 3, 2).getSize());
}
Also used : QueryResult(com.graphhopper.storage.index.QueryResult) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 67 with GHPoint

use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.

the class QueryGraphTest method testMultipleVirtualNodes.

@Test
public void testMultipleVirtualNodes() {
    initGraph(g);
    // snap to edge which has pillar nodes        
    EdgeIterator iter = g.createEdgeExplorer().setBaseNode(1);
    iter.next();
    QueryResult res1 = createLocationResult(2, 1.7, iter, 1, PILLAR);
    QueryGraph queryGraph = new QueryGraph(g);
    queryGraph.lookup(Arrays.asList(res1));
    assertEquals(new GHPoint(1.5, 1.5), res1.getSnappedPoint());
    assertEquals(3, res1.getClosestNode());
    assertEquals(4, getPoints(queryGraph, 0, 3).getSize());
    PointList pl = getPoints(queryGraph, 3, 1);
    assertEquals(2, pl.getSize());
    assertEquals(new GHPoint(1.5, 1.5), pl.toGHPoint(0));
    assertEquals(new GHPoint(1, 2.5), pl.toGHPoint(1));
    EdgeIteratorState edge = GHUtility.getEdge(queryGraph, 3, 1);
    assertNotNull(queryGraph.getEdgeIteratorState(edge.getEdge(), 3));
    assertNotNull(queryGraph.getEdgeIteratorState(edge.getEdge(), 1));
    edge = GHUtility.getEdge(queryGraph, 3, 0);
    assertNotNull(queryGraph.getEdgeIteratorState(edge.getEdge(), 3));
    assertNotNull(queryGraph.getEdgeIteratorState(edge.getEdge(), 0));
    // snap again => new virtual node on same edge!
    iter = g.createEdgeExplorer().setBaseNode(1);
    iter.next();
    res1 = createLocationResult(2, 1.7, iter, 1, PILLAR);
    QueryResult res2 = createLocationResult(1.5, 2, iter, 0, EDGE);
    queryGraph = new QueryGraph(g);
    queryGraph.lookup(Arrays.asList(res1, res2));
    assertEquals(4, res2.getClosestNode());
    assertEquals(new GHPoint(1.300019, 1.899962), res2.getSnappedPoint());
    assertEquals(3, res1.getClosestNode());
    assertEquals(new GHPoint(1.5, 1.5), res1.getSnappedPoint());
    assertEquals(4, getPoints(queryGraph, 3, 0).getSize());
    assertEquals(2, getPoints(queryGraph, 3, 4).getSize());
    assertEquals(2, getPoints(queryGraph, 4, 1).getSize());
    assertNull(GHUtility.getEdge(queryGraph, 4, 0));
    assertNull(GHUtility.getEdge(queryGraph, 3, 1));
}
Also used : QueryResult(com.graphhopper.storage.index.QueryResult) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 68 with GHPoint

use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.

the class QueryGraphTest method testOneWay.

@Test
public void testOneWay() {
    NodeAccess na = g.getNodeAccess();
    na.setNode(0, 0, 0);
    na.setNode(1, 0, 1);
    g.edge(0, 1, 10, false);
    EdgeIteratorState edge = GHUtility.getEdge(g, 0, 1);
    QueryResult res1 = createLocationResult(0.1, 0.1, edge, 0, EDGE);
    QueryResult res2 = createLocationResult(0.1, 0.9, edge, 0, EDGE);
    QueryGraph queryGraph = new QueryGraph(g);
    queryGraph.lookup(Arrays.asList(res2, res1));
    assertEquals(2, res1.getClosestNode());
    assertEquals(new GHPoint(0, 0.1), res1.getSnappedPoint());
    assertEquals(3, res2.getClosestNode());
    assertEquals(new GHPoint(0, 0.9), res2.getSnappedPoint());
    assertEquals(2, getPoints(queryGraph, 0, 2).getSize());
    assertEquals(2, getPoints(queryGraph, 2, 3).getSize());
    assertEquals(2, getPoints(queryGraph, 3, 1).getSize());
    assertNull(GHUtility.getEdge(queryGraph, 3, 0));
    assertNull(GHUtility.getEdge(queryGraph, 2, 1));
}
Also used : QueryResult(com.graphhopper.storage.index.QueryResult) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 69 with GHPoint

use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.

the class DataFlagEncoderTest method testSpatialId.

@Test
public void testSpatialId() {
    List<SpatialRule> rules = Collections.<SpatialRule>singletonList(new GermanySpatialRule());
    final BBox bbox = new BBox(0, 1, 0, 1);
    JsonFeatureCollection jsonFeatures = new JsonFeatureCollection() {

        @Override
        public List<JsonFeature> getFeatures() {
            Geometry geometry = new GeoJsonPolygon().addPolygon(new Polygon(new double[] { 0, 0, 1, 1 }, new double[] { 0, 1, 1, 0 }));
            Map<String, Object> properties = new HashMap<>();
            properties.put("ISO_A3", "DEU");
            return Collections.singletonList(new JsonFeature("x", "Polygon", bbox, geometry, properties));
        }
    };
    SpatialRuleLookup index = new SpatialRuleLookupBuilder().build(rules, jsonFeatures, bbox, 1, false);
    DataFlagEncoder encoder = new DataFlagEncoder(new PMap().put("spatial_rules", index.size()));
    encoder.setSpatialRuleLookup(index);
    EncodingManager em = new EncodingManager(encoder);
    ReaderWay way = new ReaderWay(27l);
    way.setTag("highway", "track");
    way.setTag("estimated_center", new GHPoint(0.005, 0.005));
    ReaderWay way2 = new ReaderWay(28l);
    way2.setTag("highway", "track");
    way2.setTag("estimated_center", new GHPoint(-0.005, -0.005));
    ReaderWay livingStreet = new ReaderWay(29l);
    livingStreet.setTag("highway", "living_street");
    livingStreet.setTag("estimated_center", new GHPoint(0.005, 0.005));
    ReaderWay livingStreet2 = new ReaderWay(30l);
    livingStreet2.setTag("highway", "living_street");
    livingStreet2.setTag("estimated_center", new GHPoint(-0.005, -0.005));
    Graph graph = new GraphBuilder(em).create();
    EdgeIteratorState e1 = graph.edge(0, 1, 1, true);
    EdgeIteratorState e2 = graph.edge(0, 2, 1, true);
    EdgeIteratorState e3 = graph.edge(0, 3, 1, true);
    EdgeIteratorState e4 = graph.edge(0, 4, 1, true);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 0, 0.00, 0.00);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 1, 0.01, 0.01);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 2, -0.01, -0.01);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 3, 0.01, 0.01);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 4, -0.01, -0.01);
    e1.setFlags(encoder.handleWayTags(way, 1, 0));
    e2.setFlags(encoder.handleWayTags(way2, 1, 0));
    e3.setFlags(encoder.handleWayTags(livingStreet, 1, 0));
    e4.setFlags(encoder.handleWayTags(livingStreet2, 1, 0));
    assertEquals(index.getSpatialId(new GermanySpatialRule()), encoder.getSpatialId(e1.getFlags()));
    assertEquals(index.getSpatialId(SpatialRule.EMPTY), encoder.getSpatialId(e2.getFlags()));
    assertEquals(AccessValue.EVENTUALLY_ACCESSIBLE, encoder.getAccessValue(e1.getFlags()));
    assertEquals(AccessValue.ACCESSIBLE, encoder.getAccessValue(e2.getFlags()));
    assertEquals(5, encoder.getMaxspeed(e3, -1, false), .1);
    assertEquals(-1, encoder.getMaxspeed(e4, -1, false), .1);
}
Also used : GeoJsonPolygon(com.graphhopper.json.geo.GeoJsonPolygon) GermanySpatialRule(com.graphhopper.routing.util.spatialrules.countries.GermanySpatialRule) ReaderWay(com.graphhopper.reader.ReaderWay) JsonFeature(com.graphhopper.json.geo.JsonFeature) Geometry(com.graphhopper.json.geo.Geometry) Graph(com.graphhopper.storage.Graph) BBox(com.graphhopper.util.shapes.BBox) JsonFeatureCollection(com.graphhopper.json.geo.JsonFeatureCollection) GraphBuilder(com.graphhopper.storage.GraphBuilder) GeoJsonPolygon(com.graphhopper.json.geo.GeoJsonPolygon) GHPoint(com.graphhopper.util.shapes.GHPoint) GermanySpatialRule(com.graphhopper.routing.util.spatialrules.countries.GermanySpatialRule) Test(org.junit.Test)

Aggregations

GHPoint (com.graphhopper.util.shapes.GHPoint)69 Test (org.junit.Test)34 QueryResult (com.graphhopper.storage.index.QueryResult)15 GHRequest (com.graphhopper.GHRequest)10 GHResponse (com.graphhopper.GHResponse)10 PathWrapper (com.graphhopper.PathWrapper)6 DistanceCalcEarth (com.graphhopper.util.DistanceCalcEarth)5 PointList (com.graphhopper.util.PointList)3 PointNotFoundException (com.graphhopper.util.exceptions.PointNotFoundException)3 BBox (com.graphhopper.util.shapes.BBox)3 GHPoint3D (com.graphhopper.util.shapes.GHPoint3D)3 Random (java.util.Random)3 JSONObject (org.json.JSONObject)3 IntArrayList (com.carrotsearch.hppc.IntArrayList)2 ReaderWay (com.graphhopper.reader.ReaderWay)2 EdgeFilter (com.graphhopper.routing.util.EdgeFilter)2 SpatialRule (com.graphhopper.routing.util.spatialrules.SpatialRule)2 Graph (com.graphhopper.storage.Graph)2 VLongStorage (com.graphhopper.storage.VLongStorage)2 PointDistanceExceededException (com.graphhopper.util.exceptions.PointDistanceExceededException)2