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());
}
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");
}
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);
}
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));
}
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));
}
Aggregations