use of com.graphhopper.reader.ReaderWay in project graphhopper by graphhopper.
the class MountainBikeFlagEncoderTest method testHandleWayTags.
@Test
public void testHandleWayTags() {
ReaderWay way = new ReaderWay(1);
String wayType;
way.setTag("highway", "track");
wayType = getWayTypeFromFlags(way);
assertEquals("small way, unpaved", wayType);
way.clearTags();
way.setTag("highway", "path");
wayType = getWayTypeFromFlags(way);
assertEquals("small way, unpaved", wayType);
way.clearTags();
way.setTag("highway", "path");
way.setTag("surface", "grass");
wayType = getWayTypeFromFlags(way);
assertEquals("small way, unpaved", wayType);
way.clearTags();
way.setTag("highway", "path");
way.setTag("surface", "concrete");
wayType = getWayTypeFromFlags(way);
assertEquals("", wayType);
way.clearTags();
way.setTag("highway", "track");
way.setTag("foot", "yes");
way.setTag("surface", "paved");
way.setTag("tracktype", "grade1");
wayType = getWayTypeFromFlags(way);
assertEquals("", wayType);
way.clearTags();
way.setTag("highway", "track");
way.setTag("foot", "yes");
way.setTag("surface", "paved");
way.setTag("tracktype", "grade2");
wayType = getWayTypeFromFlags(way);
assertEquals("small way, unpaved", wayType);
way.clearTags();
way.setTag("highway", "pedestrian");
wayType = getWayTypeFromFlags(way);
assertEquals("get off the bike", wayType);
}
use of com.graphhopper.reader.ReaderWay in project graphhopper by graphhopper.
the class RacingBikeFlagEncoderTest method testAvoidanceOfHighMaxSpeed.
@Test
public void testAvoidanceOfHighMaxSpeed() {
ReaderWay osmWay = new ReaderWay(1);
osmWay.setTag("highway", "tertiary");
osmWay.setTag("maxspeed", "50");
assertEquals(20, encoder.getSpeed(encoder.setSpeed(0, encoder.applyMaxSpeed(osmWay, 20))), 1e-1);
assertPriority(PREFER.getValue(), osmWay);
osmWay.setTag("maxspeed", "60");
assertEquals(20, encoder.getSpeed(encoder.setSpeed(0, encoder.applyMaxSpeed(osmWay, 20))), 1e-1);
assertPriority(PREFER.getValue(), osmWay);
osmWay.setTag("maxspeed", "80");
assertEquals(20, encoder.getSpeed(encoder.setSpeed(0, encoder.applyMaxSpeed(osmWay, 20))), 1e-1);
assertPriority(PREFER.getValue(), osmWay);
osmWay.setTag("maxspeed", "90");
assertEquals(20, encoder.getSpeed(encoder.setSpeed(0, encoder.applyMaxSpeed(osmWay, 20))), 1e-1);
assertPriority(UNCHANGED.getValue(), osmWay);
osmWay.setTag("maxspeed", "120");
assertEquals(20, encoder.getSpeed(encoder.setSpeed(0, encoder.applyMaxSpeed(osmWay, 20))), 1e-1);
assertPriority(UNCHANGED.getValue(), osmWay);
osmWay.setTag("highway", "motorway");
assertEquals(20, encoder.getSpeed(encoder.setSpeed(0, encoder.applyMaxSpeed(osmWay, 20))), 1e-1);
assertPriority(REACH_DEST.getValue(), osmWay);
osmWay.setTag("tunnel", "yes");
assertEquals(20, encoder.getSpeed(encoder.setSpeed(0, encoder.applyMaxSpeed(osmWay, 20))), 1e-1);
assertPriority(AVOID_AT_ALL_COSTS.getValue(), osmWay);
osmWay.clearTags();
osmWay.setTag("highway", "motorway");
osmWay.setTag("tunnel", "yes");
osmWay.setTag("maxspeed", "80");
assertEquals(20, encoder.getSpeed(encoder.setSpeed(0, encoder.applyMaxSpeed(osmWay, 20))), 1e-1);
assertPriority(AVOID_AT_ALL_COSTS.getValue(), osmWay);
osmWay.clearTags();
osmWay.setTag("highway", "motorway");
osmWay.setTag("tunnel", "yes");
osmWay.setTag("maxspeed", "120");
assertEquals(20, encoder.getSpeed(encoder.setSpeed(0, encoder.applyMaxSpeed(osmWay, 20))), 1e-1);
assertPriority(AVOID_AT_ALL_COSTS.getValue(), osmWay);
osmWay.clearTags();
osmWay.setTag("highway", "notdefined");
osmWay.setTag("tunnel", "yes");
osmWay.setTag("maxspeed", "120");
assertEquals(20, encoder.getSpeed(encoder.setSpeed(0, encoder.applyMaxSpeed(osmWay, 20))), 1e-1);
assertPriority(AVOID_AT_ALL_COSTS.getValue(), osmWay);
osmWay.clearTags();
osmWay.setTag("highway", "notdefined");
osmWay.setTag("maxspeed", "50");
assertEquals(20, encoder.getSpeed(encoder.setSpeed(0, encoder.applyMaxSpeed(osmWay, 20))), 1e-1);
assertPriority(UNCHANGED.getValue(), osmWay);
}
use of com.graphhopper.reader.ReaderWay in project graphhopper by graphhopper.
the class InstructionListTest method flagsForSpeed.
private long flagsForSpeed(EncodingManager encodingManager, int speedKmPerHour) {
ReaderWay way = new ReaderWay(1);
way.setTag("highway", "motorway");
way.setTag("maxspeed", String.format("%d km/h", speedKmPerHour));
return encodingManager.handleWayTags(way, 1, 0);
}
use of com.graphhopper.reader.ReaderWay in project graphhopper by graphhopper.
the class OSMShapeFileReader method addEdge.
private void addEdge(int fromTower, int toTower, SimpleFeature road, double distance, GHPoint estmCentre, PointList pillarNodes) {
EdgeIteratorState edge = graph.edge(fromTower, toTower);
// read the OSM id, should never be null
long id = getOSMId(road);
// Make a temporary ReaderWay object with the properties we need so we
// can use the enocding manager
// We (hopefully don't need the node structure on here as we're only
// calling the flag
// encoders, which don't use this...
ReaderWay way = new ReaderWay(id);
way.setTag("estimated_distance", distance);
way.setTag("estimated_center", estmCentre);
// read the highway type
Object type = road.getAttribute("fclass");
if (type != null) {
way.setTag("highway", type.toString());
}
// read maxspeed filtering for 0 which for Geofabrik shapefiles appears
// to correspond to no tag
Object maxSpeed = road.getAttribute("maxspeed");
if (maxSpeed != null && !maxSpeed.toString().trim().equals("0")) {
way.setTag("maxspeed", maxSpeed.toString());
}
for (String tag : DIRECT_COPY_TAGS) {
Object val = road.getAttribute(tag);
if (val != null) {
way.setTag(tag, val.toString());
}
}
// read oneway
Object oneway = road.getAttribute("oneway");
if (oneway != null) {
// Geofabrik is using an odd convention for oneway field in
// shapefile.
// We map back to the standard convention so that tag can be dealt
// with correctly by the flag encoder.
String val = toLowerCase(oneway.toString().trim());
if (val.equals("b")) {
// both ways
val = "no";
} else if (val.equals("t")) {
// one way against the direction of digitisation
val = "-1";
} else if (val.equals("f")) {
// one way Forward in the direction of digitisation
val = "yes";
} else {
throw new RuntimeException("Unrecognised value of oneway field \"" + val + "\" found in road with OSM id " + id);
}
way.setTag("oneway", val);
}
// Process the flags using the encoders
long includeWay = encodingManager.acceptWay(way);
if (includeWay == 0) {
return;
}
// TODO we're not using the relation flags
long relationFlags = 0;
long wayFlags = encodingManager.handleWayTags(way, includeWay, relationFlags);
if (wayFlags == 0)
return;
edge.setDistance(distance);
edge.setFlags(wayFlags);
edge.setWayGeometry(pillarNodes);
if (edgeAddedListeners.size() > 0) {
// listeners
for (EdgeAddedListener l : edgeAddedListeners) {
l.edgeAdded(way, edge);
}
}
}
use of com.graphhopper.reader.ReaderWay in project graphhopper by graphhopper.
the class BikeFlagEncoderTest method testHandleWayTags.
@Test
public void testHandleWayTags() {
ReaderWay way = new ReaderWay(1);
String wayType;
way.setTag("highway", "track");
wayType = getWayTypeFromFlags(way);
assertEquals("small way, unpaved", wayType);
way.clearTags();
way.setTag("highway", "path");
wayType = getWayTypeFromFlags(way);
assertEquals("get off the bike, unpaved", wayType);
way.clearTags();
way.setTag("highway", "path");
way.setTag("surface", "grass");
wayType = getWayTypeFromFlags(way);
assertEquals("get off the bike, unpaved", wayType);
way.clearTags();
way.setTag("highway", "path");
way.setTag("surface", "concrete");
wayType = getWayTypeFromFlags(way);
assertEquals("get off the bike", wayType);
way.clearTags();
way.setTag("highway", "track");
way.setTag("foot", "yes");
way.setTag("surface", "paved");
way.setTag("tracktype", "grade1");
wayType = getWayTypeFromFlags(way);
assertEquals("", wayType);
way.setTag("tracktype", "grade2");
wayType = getWayTypeFromFlags(way);
assertEquals("get off the bike, unpaved", wayType);
way.clearTags();
way.setTag("junction", "roundabout");
way.setTag("highway", "tertiary");
long flags = encoder.handleWayTags(way, encoder.acceptWay(way), 0);
assertTrue(encoder.isBool(flags, FlagEncoder.K_ROUNDABOUT));
way.clearTags();
way.setTag("junction", "circular");
way.setTag("highway", "tertiary");
flags = encoder.handleWayTags(way, encoder.acceptWay(way), 0);
assertTrue(encoder.isBool(flags, FlagEncoder.K_ROUNDABOUT));
}
Aggregations