Search in sources :

Example 91 with ReaderWay

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

the class GraphHopperStorageForDataFlagEncoderTest method testStorageProperties.

@Test
public void testStorageProperties() {
    graph = new GraphBuilder(encodingManager).setStore(true).setLocation(defaultGraphLoc).create();
    // 0-1
    ReaderWay way_0_1 = new ReaderWay(27l);
    way_0_1.setTag("highway", "primary");
    way_0_1.setTag("maxheight", "4.4");
    graph.edge(0, 1, 1, true);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 0, 0.00, 0.00);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 1, 0.01, 0.01);
    graph.getEdgeIteratorState(0, 1).setFlags(encoder.handleWayTags(way_0_1, 1, 0));
    // 1-2
    ReaderWay way_1_2 = new ReaderWay(28l);
    way_1_2.setTag("highway", "primary");
    way_1_2.setTag("maxweight", "45");
    graph.edge(1, 2, 1, true);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 2, 0.02, 0.02);
    graph.getEdgeIteratorState(1, 2).setFlags(encoder.handleWayTags(way_1_2, 1, 0));
    // 2-0
    ReaderWay way_2_0 = new ReaderWay(29l);
    way_2_0.setTag("highway", "primary");
    way_2_0.setTag("maxwidth", "5");
    graph.edge(2, 0, 1, true);
    graph.getEdgeIteratorState(2, 0).setFlags(encoder.handleWayTags(way_2_0, 1, 0));
    graph.flush();
    graph.close();
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(defaultGraphLoc).setCHEnabled(false).importOrLoad();
    EncodingManager em = hopper.getEncodingManager();
    assertNotNull(em);
    assertEquals(1, em.fetchEdgeEncoders().size());
    FlagEncoder flagEncoder = em.fetchEdgeEncoders().get(0);
    assertTrue(flagEncoder instanceof DataFlagEncoder);
    DataFlagEncoder dataFlagEncoder = (DataFlagEncoder) flagEncoder;
    assertTrue(dataFlagEncoder.isStoreHeight());
    assertTrue(dataFlagEncoder.isStoreWeight());
    assertFalse(dataFlagEncoder.isStoreWidth());
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) DataFlagEncoder(com.graphhopper.routing.util.DataFlagEncoder) DataFlagEncoder(com.graphhopper.routing.util.DataFlagEncoder) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) ReaderWay(com.graphhopper.reader.ReaderWay) GraphHopper(com.graphhopper.GraphHopper) Test(org.junit.Test)

Example 92 with ReaderWay

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

the class AbstractEdgeElevationInterpolatorTest method setUp.

@SuppressWarnings("resource")
@Before
public void setUp() {
    dataFlagEncoder = new DataFlagEncoder();
    graph = new GraphHopperStorage(new RAMDirectory(), new EncodingManager(Arrays.asList(dataFlagEncoder, new FootFlagEncoder()), 8), true, new GraphExtension.NoOpExtension()).create(100);
    edgeElevationInterpolator = createEdgeElevationInterpolator();
    interpolatableWay = createInterpolatableWay();
    normalWay = new ReaderWay(0);
    normalWay.setTag("highway", "primary");
}
Also used : DataFlagEncoder(com.graphhopper.routing.util.DataFlagEncoder) EncodingManager(com.graphhopper.routing.util.EncodingManager) ReaderWay(com.graphhopper.reader.ReaderWay) FootFlagEncoder(com.graphhopper.routing.util.FootFlagEncoder) RAMDirectory(com.graphhopper.storage.RAMDirectory) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) GraphExtension(com.graphhopper.storage.GraphExtension) Before(org.junit.Before)

Example 93 with ReaderWay

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

the class DataFlagEncoderTest method testSpatialId.

@Test
public void testSpatialId() {
    final GermanySpatialRule germany = new GermanySpatialRule();
    germany.setBorders(Collections.singletonList(new Polygon(new double[] { 0, 0, 1, 1 }, new double[] { 0, 1, 1, 0 })));
    SpatialRuleLookup index = new SpatialRuleLookup() {

        @Override
        public SpatialRule lookupRule(double lat, double lon) {
            for (Polygon polygon : germany.getBorders()) {
                if (polygon.contains(lat, lon)) {
                    return germany;
                }
            }
            return SpatialRule.EMPTY;
        }

        @Override
        public SpatialRule lookupRule(GHPoint point) {
            return lookupRule(point.lat, point.lon);
        }

        @Override
        public int getSpatialId(SpatialRule rule) {
            if (germany.equals(rule)) {
                return 1;
            } else {
                return 0;
            }
        }

        @Override
        public int size() {
            return 2;
        }

        @Override
        public BBox getBounds() {
            return new BBox(-180, 180, -90, 90);
        }
    };
    DataFlagEncoder encoder = new DataFlagEncoder(new PMap());
    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 : PMap(com.graphhopper.util.PMap) GermanySpatialRule(com.graphhopper.routing.util.spatialrules.countries.GermanySpatialRule) ReaderWay(com.graphhopper.reader.ReaderWay) Graph(com.graphhopper.storage.Graph) BBox(com.graphhopper.util.shapes.BBox) GraphBuilder(com.graphhopper.storage.GraphBuilder) GHPoint(com.graphhopper.util.shapes.GHPoint) GermanySpatialRule(com.graphhopper.routing.util.spatialrules.countries.GermanySpatialRule) Test(org.junit.Test)

Example 94 with ReaderWay

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

the class FootFlagEncoderTest method handleWayTagsCircularJunction.

@Test
public void handleWayTagsCircularJunction() {
    ReaderWay way = new ReaderWay(1);
    way.setTag("junction", "circular");
    way.setTag("highway", "tertiary");
    long flags = footEncoder.handleWayTags(way, footEncoder.acceptWay(way), 0);
    assertTrue(footEncoder.isBool(flags, FlagEncoder.K_ROUNDABOUT));
}
Also used : ReaderWay(com.graphhopper.reader.ReaderWay) Test(org.junit.Test)

Example 95 with ReaderWay

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

the class MotorcycleFlagEncoderTest method testRoundabout.

@Test
public void testRoundabout() {
    long flags = encoder.setAccess(0, true, true);
    long resFlags = encoder.setBool(flags, FlagEncoder.K_ROUNDABOUT, true);
    assertTrue(encoder.isBool(resFlags, FlagEncoder.K_ROUNDABOUT));
    assertTrue(encoder.isForward(resFlags));
    assertTrue(encoder.isBackward(resFlags));
    resFlags = encoder.setBool(flags, FlagEncoder.K_ROUNDABOUT, false);
    assertFalse(encoder.isBool(resFlags, FlagEncoder.K_ROUNDABOUT));
    assertTrue(encoder.isForward(resFlags));
    assertTrue(encoder.isBackward(resFlags));
    ReaderWay way = new ReaderWay(1);
    way.setTag("highway", "motorway");
    flags = encoder.handleWayTags(way, encoder.acceptBit, 0);
    assertTrue(encoder.isForward(flags));
    assertTrue(encoder.isBackward(flags));
    assertFalse(encoder.isBool(flags, FlagEncoder.K_ROUNDABOUT));
    way.setTag("junction", "roundabout");
    flags = encoder.handleWayTags(way, encoder.acceptBit, 0);
    assertTrue(encoder.isForward(flags));
    assertFalse(encoder.isBackward(flags));
    assertTrue(encoder.isBool(flags, FlagEncoder.K_ROUNDABOUT));
    way.clearTags();
    way.setTag("highway", "motorway");
    way.setTag("junction", "circular");
    flags = encoder.handleWayTags(way, encoder.acceptBit, 0);
    assertTrue(encoder.isForward(flags));
    assertFalse(encoder.isBackward(flags));
    assertTrue(encoder.isBool(flags, FlagEncoder.K_ROUNDABOUT));
}
Also used : ReaderWay(com.graphhopper.reader.ReaderWay) Test(org.junit.Test)

Aggregations

ReaderWay (com.graphhopper.reader.ReaderWay)157 Test (org.junit.jupiter.api.Test)119 IntsRef (com.graphhopper.storage.IntsRef)67 Test (org.junit.Test)24 EncodingManager (com.graphhopper.routing.util.EncodingManager)9 GraphBuilder (com.graphhopper.storage.GraphBuilder)9 ReaderRelation (com.graphhopper.reader.ReaderRelation)8 ConditionalTagInspector (com.graphhopper.reader.ConditionalTagInspector)7 Graph (com.graphhopper.storage.Graph)7 DateFormat (java.text.DateFormat)6 Date (java.util.Date)6 DecimalEncodedValue (com.graphhopper.routing.ev.DecimalEncodedValue)5 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)5 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)4 PMap (com.graphhopper.util.PMap)4 BooleanEncodedValue (com.graphhopper.routing.ev.BooleanEncodedValue)3 DataFlagEncoder (com.graphhopper.routing.util.DataFlagEncoder)3 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)3 GHPoint (com.graphhopper.util.shapes.GHPoint)3 LongIndexedContainer (com.carrotsearch.hppc.LongIndexedContainer)2