use of com.graphhopper.reader.ReaderWay 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);
}
use of com.graphhopper.reader.ReaderWay in project graphhopper by graphhopper.
the class DataFlagEncoderTest method testFord.
@Test
public void testFord() {
ReaderWay osmWay = new ReaderWay(0);
osmWay.setTag("highway", "unclassified");
osmWay.setTag("ford", "yes");
long flags = encoder.handleWayTags(osmWay, 1, 0);
EdgeIteratorState edge = GHUtility.createMockedEdgeIteratorState(0, flags);
assertEquals("ford", encoder.getTransportModeAsString(edge));
assertTrue(encoder.isTransportModeFord(edge.getFlags()));
assertTrue(encoder.getAnnotation(edge.getFlags(), TranslationMapTest.SINGLETON.get("en")).getMessage().contains("ford"));
}
use of com.graphhopper.reader.ReaderWay in project graphhopper by graphhopper.
the class DataFlagEncoderTest method testMaxspeed.
@Test
public void testMaxspeed() {
ReaderWay osmWay = new ReaderWay(0);
osmWay.setTag("highway", "primary");
osmWay.setTag("maxspeed", "10");
long flags = encoder.handleWayTags(osmWay, 1, 0);
EdgeIteratorState edge = GHUtility.createMockedEdgeIteratorState(0, flags);
assertEquals(10, encoder.getMaxspeed(edge, motorVehicleInt, false), .1);
assertEquals(10, encoder.getMaxspeed(edge, motorVehicleInt, true), .1);
osmWay = new ReaderWay(0);
osmWay.setTag("highway", "primary");
osmWay.setTag("maxspeed:forward", "10");
flags = encoder.handleWayTags(osmWay, 1, 0);
edge = GHUtility.createMockedEdgeIteratorState(0, flags);
assertEquals(10, encoder.getMaxspeed(edge, motorVehicleInt, false), .1);
assertEquals(-1, encoder.getMaxspeed(edge, motorVehicleInt, true), .1);
osmWay = new ReaderWay(0);
osmWay.setTag("highway", "primary");
osmWay.setTag("maxspeed:forward", "50");
osmWay.setTag("maxspeed:backward", "50");
osmWay.setTag("maxspeed", "60");
flags = encoder.handleWayTags(osmWay, 1, 0);
edge = GHUtility.createMockedEdgeIteratorState(0, flags);
assertEquals(50, encoder.getMaxspeed(edge, motorVehicleInt, false), .1);
assertEquals(50, encoder.getMaxspeed(edge, motorVehicleInt, true), .1);
}
use of com.graphhopper.reader.ReaderWay in project graphhopper by graphhopper.
the class DataFlagEncoderTest method testDestinationTag.
@Test
public void testDestinationTag() {
ReaderWay way = new ReaderWay(1);
way.setTag("highway", "secondary");
assertEquals(AccessValue.ACCESSIBLE, encoder.getAccessValue(encoder.handleWayTags(way, encoder.acceptWay(way), 0)));
way.setTag("vehicle", "destination");
assertEquals(AccessValue.EVENTUALLY_ACCESSIBLE, encoder.getAccessValue(encoder.handleWayTags(way, encoder.acceptWay(way), 0)));
way.setTag("vehicle", "no");
assertEquals(AccessValue.NOT_ACCESSIBLE, encoder.getAccessValue(encoder.handleWayTags(way, encoder.acceptWay(way), 0)));
}
use of com.graphhopper.reader.ReaderWay in project graphhopper by graphhopper.
the class EncodedDoubleValueTest method testMaxValue.
@Test
public void testMaxValue() {
EncodedDoubleValue instance1 = new EncodedDoubleValue("test1", 0, 8, 0.5, 60, 100);
long flags = instance1.setDoubleValue(0, instance1.getMaxValue());
assertEquals(100, instance1.getDoubleValue(flags), 1e-1);
CarFlagEncoder carEncoder = new CarFlagEncoder(10, 0.5, 0);
new EncodingManager(carEncoder);
ReaderWay way = new ReaderWay(1);
way.setTag("highway", "motorway_link");
way.setTag("maxspeed", "70 mph");
flags = carEncoder.handleWayTags(way, 1, 0);
// double speed = AbstractFlagEncoder.parseSpeed("70 mph");
flags = carEncoder.reverseFlags(flags);
assertEquals(101.5, carEncoder.getSpeed(flags), 1e-1);
}
Aggregations