use of com.graphhopper.reader.ReaderNode in project graphhopper by graphhopper.
the class AbstractBikeFlagEncoderTester method testBarrierAccess.
@Test
public void testBarrierAccess() {
// by default allow access through the gate for bike & foot!
ReaderNode node = new ReaderNode(1, -1, -1);
node.setTag("barrier", "gate");
// no barrier!
assertFalse(encoder.isBarrier(node));
node.setTag("bicycle", "yes");
// no barrier!
assertFalse(encoder.isBarrier(node));
node = new ReaderNode(1, -1, -1);
node.setTag("barrier", "gate");
node.setTag("access", "no");
// barrier!
assertTrue(encoder.isBarrier(node));
node = new ReaderNode(1, -1, -1);
node.setTag("barrier", "gate");
node.setTag("access", "yes");
node.setTag("bicycle", "no");
// barrier!
assertTrue(encoder.isBarrier(node));
node = new ReaderNode(1, -1, -1);
node.setTag("barrier", "gate");
node.setTag("access", "no");
node.setTag("foot", "yes");
// barrier!
assertTrue(encoder.isBarrier(node));
node = new ReaderNode(1, -1, -1);
node.setTag("barrier", "gate");
node.setTag("access", "no");
node.setTag("bicycle", "yes");
// no barrier!
assertFalse(encoder.isBarrier(node));
}
use of com.graphhopper.reader.ReaderNode in project graphhopper by graphhopper.
the class FootFlagEncoderTest method testBarrierAccess.
@Test
public void testBarrierAccess() {
// by default allow access through the gate for bike & foot!
ReaderNode node = new ReaderNode(1, -1, -1);
node.setTag("barrier", "gate");
// no barrier!
assertFalse(footEncoder.isBarrier(node));
node = new ReaderNode(1, -1, -1);
node.setTag("barrier", "gate");
node.setTag("access", "yes");
// no barrier!
assertFalse(footEncoder.isBarrier(node));
node = new ReaderNode(1, -1, -1);
node.setTag("barrier", "gate");
node.setTag("access", "no");
// barrier!
assertTrue(footEncoder.isBarrier(node));
node.setTag("bicycle", "yes");
// no barrier!?
// assertTrue(footEncoder.handleNodeTags(node) == false);
node = new ReaderNode(1, -1, -1);
node.setTag("barrier", "gate");
node.setTag("access", "no");
node.setTag("foot", "yes");
// no barrier!
assertFalse(footEncoder.isBarrier(node));
node.setTag("locked", "yes");
// barrier!
assertTrue(footEncoder.isBarrier(node));
node.clearTags();
node.setTag("barrier", "yes");
node.setTag("access", "no");
assertTrue(footEncoder.isBarrier(node));
}
use of com.graphhopper.reader.ReaderNode in project graphhopper by graphhopper.
the class FootFlagEncoderTest method testBlockByDefault.
@Test
public void testBlockByDefault() {
FootFlagEncoder tmpFootEncoder = new FootFlagEncoder();
EncodingManager.create(tmpFootEncoder);
ReaderNode node = new ReaderNode(1, -1, -1);
node.setTag("barrier", "gate");
// potential barriers are no barrier by default
assertFalse(tmpFootEncoder.isBarrier(node));
node.setTag("access", "no");
assertTrue(tmpFootEncoder.isBarrier(node));
// absolute barriers always block
node = new ReaderNode(1, -1, -1);
node.setTag("barrier", "fence");
assertTrue(tmpFootEncoder.isBarrier(node));
node.setTag("barrier", "fence");
node.setTag("access", "yes");
assertFalse(tmpFootEncoder.isBarrier(node));
// pass potential barriers per default (if no other access tag exists)
tmpFootEncoder = new FootFlagEncoder();
EncodingManager.create(tmpFootEncoder);
node = new ReaderNode(1, -1, -1);
node.setTag("barrier", "gate");
assertFalse(tmpFootEncoder.isBarrier(node));
node.setTag("access", "yes");
assertFalse(tmpFootEncoder.isBarrier(node));
node = new ReaderNode(1, -1, -1);
node.setTag("barrier", "fence");
assertTrue(tmpFootEncoder.isBarrier(node));
// don't block potential barriers: barrier:cattle_grid should not block here
tmpFootEncoder = new FootFlagEncoder();
EncodingManager.create(tmpFootEncoder);
node = new ReaderNode(1, -1, -1);
node.setTag("barrier", "cattle_grid");
assertFalse(tmpFootEncoder.isBarrier(node));
}
use of com.graphhopper.reader.ReaderNode in project graphhopper by graphhopper.
the class MountainBikeFlagEncoderTest method testBarrierAccess.
// Issue 407 : Always block kissing_gate execpt for mountainbikes
@Test
@Override
public void testBarrierAccess() {
// kissing_gate without bicycle tag
ReaderNode node = new ReaderNode(1, -1, -1);
node.setTag("barrier", "kissing_gate");
// No barrier!
assertFalse(encoder.isBarrier(node));
// kissing_gate with bicycle tag = no
node = new ReaderNode(1, -1, -1);
node.setTag("barrier", "kissing_gate");
node.setTag("bicycle", "no");
// barrier!
assertTrue(encoder.isBarrier(node));
// kissing_gate with bicycle tag
node = new ReaderNode(1, -1, -1);
node.setTag("barrier", "kissing_gate");
node.setTag("bicycle", "yes");
// No barrier!
assertFalse(encoder.isBarrier(node));
}
use of com.graphhopper.reader.ReaderNode in project graphhopper by graphhopper.
the class PbfBlobDecoder method processNodes.
private void processNodes(Osmformat.DenseNodes nodes, PbfFieldDecoder fieldDecoder) {
List<Long> idList = nodes.getIdList();
List<Long> latList = nodes.getLatList();
List<Long> lonList = nodes.getLonList();
// Ensure parallel lists are of equal size.
if (checkData) {
if ((idList.size() != latList.size()) || (idList.size() != lonList.size())) {
throw new RuntimeException("Number of ids (" + idList.size() + "), latitudes (" + latList.size() + "), and longitudes (" + lonList.size() + ") don't match");
}
}
Iterator<Integer> keysValuesIterator = nodes.getKeysValsList().iterator();
/*
Osmformat.DenseInfo denseInfo;
if (nodes.hasDenseinfo()) {
denseInfo = nodes.getDenseinfo();
} else {
denseInfo = null;
}
*/
long nodeId = 0;
long latitude = 0;
long longitude = 0;
// long changesetId = 0;
for (int i = 0; i < idList.size(); i++) {
// Delta decode node fields.
nodeId += idList.get(i);
latitude += latList.get(i);
longitude += lonList.get(i);
/*
if (denseInfo != null) {
// Delta decode dense info fields.
userId += denseInfo.getUid(i);
userSid += denseInfo.getUserSid(i);
timestamp += denseInfo.getTimestamp(i);
changesetId += denseInfo.getChangeset(i);
// Build the user, but only if one exists.
OsmUser user;
if (userId >= 0) {
user = new OsmUser(userId, fieldDecoder.decodeString(userSid));
} else {
user = OsmUser.NONE;
}
entityData = new CommonEntityData(nodeId, denseInfo.getVersion(i),
fieldDecoder.decodeTimestamp(timestamp), user, changesetId);
} else {
entityData = new CommonEntityData(nodeId, EMPTY_VERSION, EMPTY_TIMESTAMP, OsmUser.NONE,
EMPTY_CHANGESET);
}
*/
// Build the tags. The key and value string indexes are sequential
// in the same PBF array. Each set of tags is delimited by an index
// with a value of 0.
Map<String, String> tags = null;
while (keysValuesIterator.hasNext()) {
int keyIndex = keysValuesIterator.next();
if (keyIndex == 0) {
break;
}
if (checkData) {
if (!keysValuesIterator.hasNext()) {
throw new RuntimeException("The PBF DenseInfo keys/values list contains a key with no corresponding value.");
}
}
int valueIndex = keysValuesIterator.next();
if (tags == null) {
// divide by 2 as key&value, multiple by 2 because of the better approximation
tags = new HashMap<>(Math.max(3, 2 * (nodes.getKeysValsList().size() / 2) / idList.size()));
}
tags.put(fieldDecoder.decodeString(keyIndex), fieldDecoder.decodeString(valueIndex));
}
ReaderNode node = new ReaderNode(nodeId, fieldDecoder.decodeLatitude(latitude), fieldDecoder.decodeLongitude(longitude));
node.setTags(tags);
// Add the bound object to the results.
decodedEntities.add(node);
}
}
Aggregations