Search in sources :

Example 1 with ReaderNode

use of com.graphhopper.reader.ReaderNode in project graphhopper by graphhopper.

the class OSMReaderTest method testEstimatedCenter.

@Test
public void testEstimatedCenter() {
    final CarFlagEncoder encoder = new CarFlagEncoder() {

        private EncodedValue objectEncoder;

        @Override
        public int defineNodeBits(int index, int shift) {
            shift = super.defineNodeBits(index, shift);
            objectEncoder = new EncodedValue("oEnc", shift, 2, 1, 0, 3, true);
            return shift + 2;
        }

        @Override
        public long handleNodeTags(ReaderNode node) {
            if (node.hasTag("test", "now"))
                return -objectEncoder.setValue(0, 1);
            return 0;
        }
    };
    EncodingManager manager = new EncodingManager(encoder);
    GraphHopperStorage ghStorage = newGraph(dir, manager, false, false);
    final Map<Integer, Double> latMap = new HashMap<Integer, Double>();
    final Map<Integer, Double> lonMap = new HashMap<Integer, Double>();
    latMap.put(1, 1.1d);
    latMap.put(2, 1.2d);
    lonMap.put(1, 1.0d);
    lonMap.put(2, 1.0d);
    OSMReader osmreader = new OSMReader(ghStorage) {

        // mock data access
        @Override
        double getTmpLatitude(int id) {
            return latMap.get(id);
        }

        @Override
        double getTmpLongitude(int id) {
            return lonMap.get(id);
        }

        @Override
        Collection<EdgeIteratorState> addOSMWay(LongIndexedContainer osmNodeIds, long wayFlags, long osmId) {
            return Collections.emptyList();
        }
    };
    // save some node tags for first node
    ReaderNode osmNode = new ReaderNode(1, 1.1d, 1.0d);
    osmNode.setTag("test", "now");
    osmreader.getNodeFlagsMap().put(1, encoder.handleNodeTags(osmNode));
    ReaderWay way = new ReaderWay(1L);
    way.getNodes().add(1);
    way.getNodes().add(2);
    way.setTag("highway", "motorway");
    osmreader.getNodeMap().put(1, 1);
    osmreader.getNodeMap().put(2, 2);
    osmreader.processWay(way);
    GHPoint p = way.getTag("estimated_center", null);
    assertEquals(1.15, p.lat, 1e-3);
    assertEquals(1.0, p.lon, 1e-3);
    Double d = way.getTag("estimated_distance", null);
    assertEquals(11119.5, d, 1e-1);
}
Also used : LongIndexedContainer(com.carrotsearch.hppc.LongIndexedContainer) ReaderNode(com.graphhopper.reader.ReaderNode) ReaderWay(com.graphhopper.reader.ReaderWay) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 2 with ReaderNode

use of com.graphhopper.reader.ReaderNode in project graphhopper by graphhopper.

the class OSMReaderTest method testWithBounds.

@Test
public void testWithBounds() {
    GraphHopper hopper = new GraphHopperFacade(file1) {

        @Override
        protected DataReader createReader(GraphHopperStorage tmpGraph) {
            return new OSMReader(tmpGraph) {

                @Override
                public boolean isInBounds(ReaderNode node) {
                    return node.getLat() > 49 && node.getLon() > 8;
                }
            };
        }
    };
    hopper.importOrLoad();
    Graph graph = hopper.getGraphHopperStorage();
    assertEquals(4, graph.getNodes());
    int n10 = AbstractGraphStorageTester.getIdOf(graph, 51.2492152);
    int n20 = AbstractGraphStorageTester.getIdOf(graph, 52);
    int n30 = AbstractGraphStorageTester.getIdOf(graph, 51.2);
    int n40 = AbstractGraphStorageTester.getIdOf(graph, 51.25);
    assertEquals(GHUtility.asSet(n20), GHUtility.getNeighbors(carOutExplorer.setBaseNode(n10)));
    assertEquals(3, GHUtility.count(carOutExplorer.setBaseNode(n20)));
    assertEquals(GHUtility.asSet(n20), GHUtility.getNeighbors(carOutExplorer.setBaseNode(n30)));
    EdgeIterator iter = carOutExplorer.setBaseNode(n20);
    assertTrue(iter.next());
    assertEquals(n40, iter.getAdjNode());
    AbstractGraphStorageTester.assertPList(Helper.createPointList(), iter.fetchWayGeometry(0));
    assertTrue(iter.next());
    assertEquals(n30, iter.getAdjNode());
    assertEquals(93146.888, iter.getDistance(), 1);
    assertTrue(iter.next());
    AbstractGraphStorageTester.assertPList(Helper.createPointList(), iter.fetchWayGeometry(0));
    assertEquals(n10, iter.getAdjNode());
    assertEquals(88643, iter.getDistance(), 1);
    // get third added location => 2
    iter = carOutExplorer.setBaseNode(n30);
    assertTrue(iter.next());
    assertEquals(n20, iter.getAdjNode());
    assertEquals(93146.888, iter.getDistance(), 1);
    assertFalse(iter.next());
}
Also used : ReaderNode(com.graphhopper.reader.ReaderNode) GraphHopper(com.graphhopper.GraphHopper) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 3 with ReaderNode

use of com.graphhopper.reader.ReaderNode in project graphhopper by graphhopper.

the class OSMXMLHelper method createNode.

public static ReaderNode createNode(long id, XMLStreamReader parser) throws XMLStreamException {
    ReaderNode node = new ReaderNode(id, Double.parseDouble(parser.getAttributeValue(null, "lat")), Double.parseDouble(parser.getAttributeValue(null, "lon")));
    parser.nextTag();
    readTags(node, parser);
    return node;
}
Also used : ReaderNode(com.graphhopper.reader.ReaderNode)

Example 4 with ReaderNode

use of com.graphhopper.reader.ReaderNode in project graphhopper by graphhopper.

the class PbfBlobDecoder method processNodes.

private void processNodes(List<Osmformat.Node> nodes, PbfFieldDecoder fieldDecoder) {
    for (Osmformat.Node node : nodes) {
        Map<String, String> tags = buildTags(node.getKeysList(), node.getValsList(), fieldDecoder);
        ReaderNode osmNode = new ReaderNode(node.getId(), fieldDecoder.decodeLatitude(node.getLat()), fieldDecoder.decodeLatitude(node.getLon()));
        osmNode.setTags(tags);
        // Add the bound object to the results.
        decodedEntities.add(osmNode);
    }
}
Also used : ReaderNode(com.graphhopper.reader.ReaderNode) Osmformat(org.openstreetmap.osmosis.osmbinary.Osmformat)

Example 5 with ReaderNode

use of com.graphhopper.reader.ReaderNode in project graphhopper by graphhopper.

the class CarFlagEncoderTest method testChainBarrier.

@Test
public void testChainBarrier() {
    // by default allow access through the gate for bike & foot!
    ReaderNode node = new ReaderNode(1, -1, -1);
    node.setTag("barrier", "chain");
    assertFalse(encoder.isBarrier(node));
    node.setTag("motor_vehicle", "no");
    assertTrue(encoder.isBarrier(node));
    node.setTag("motor_vehicle", "yes");
    assertFalse(encoder.isBarrier(node));
}
Also used : ReaderNode(com.graphhopper.reader.ReaderNode) Test(org.junit.jupiter.api.Test)

Aggregations

ReaderNode (com.graphhopper.reader.ReaderNode)20 Test (org.junit.jupiter.api.Test)13 GHPoint (com.graphhopper.util.shapes.GHPoint)3 Test (org.junit.Test)3 GraphHopper (com.graphhopper.GraphHopper)2 ReaderWay (com.graphhopper.reader.ReaderWay)2 LongIndexedContainer (com.carrotsearch.hppc.LongIndexedContainer)1 PMap (com.graphhopper.util.PMap)1 Osmformat (org.openstreetmap.osmosis.osmbinary.Osmformat)1