use of com.graphhopper.reader.ReaderRelation in project graphhopper by graphhopper.
the class OSMReaderTest method testRelation.
@Test
public void testRelation() {
EncodingManager manager = new EncodingManager("bike");
GraphHopperStorage ghStorage = new GraphHopperStorage(new RAMDirectory(), manager, false, new GraphExtension.NoOpExtension());
OSMReader reader = new OSMReader(ghStorage);
ReaderRelation osmRel = new ReaderRelation(1);
osmRel.add(new ReaderRelation.Member(ReaderRelation.WAY, 1, ""));
osmRel.add(new ReaderRelation.Member(ReaderRelation.WAY, 2, ""));
osmRel.setTag("route", "bicycle");
osmRel.setTag("network", "lcn");
reader.prepareWaysWithRelationInfo(osmRel);
long flags = reader.getRelFlagsMap().get(1);
assertTrue(flags != 0);
// do NOT overwrite with UNCHANGED
osmRel.setTag("network", "mtb");
reader.prepareWaysWithRelationInfo(osmRel);
long flags2 = reader.getRelFlagsMap().get(1);
assertEquals(flags, flags2);
// overwrite with outstanding
osmRel.setTag("network", "ncn");
reader.prepareWaysWithRelationInfo(osmRel);
long flags3 = reader.getRelFlagsMap().get(1);
assertTrue(flags != flags3);
}
use of com.graphhopper.reader.ReaderRelation in project graphhopper by graphhopper.
the class EncodingManagerTest method testMixBikeTypesAndRelationCombination.
@Test
public void testMixBikeTypesAndRelationCombination() {
ReaderWay osmWay = new ReaderWay(1);
osmWay.setTag("highway", "track");
osmWay.setTag("tracktype", "grade1");
ReaderRelation osmRel = new ReaderRelation(1);
BikeFlagEncoder bikeEncoder = new BikeFlagEncoder();
MountainBikeFlagEncoder mtbEncoder = new MountainBikeFlagEncoder();
EncodingManager manager = new EncodingManager(bikeEncoder, mtbEncoder);
// relation code for network rcn is VERY_NICE for bike and PREFER for mountainbike
osmRel.setTag("route", "bicycle");
osmRel.setTag("network", "rcn");
long relFlags = manager.handleRelationTags(osmRel, 0);
long allow = bikeEncoder.acceptBit | mtbEncoder.acceptBit;
long flags = manager.handleWayTags(osmWay, allow, relFlags);
// bike: uninfluenced speed for grade but via network => VERY_NICE
// mtb: uninfluenced speed only PREFER
assertTrue(bikeEncoder.getDouble(flags, PriorityWeighting.KEY) > mtbEncoder.getDouble(flags, PriorityWeighting.KEY));
}
use of com.graphhopper.reader.ReaderRelation in project graphhopper by graphhopper.
the class EncodingManagerTest method testCombineRelations.
@Test
public void testCombineRelations() {
ReaderWay osmWay = new ReaderWay(1);
osmWay.setTag("highway", "track");
ReaderRelation osmRel = new ReaderRelation(1);
BikeFlagEncoder defaultBike = new BikeFlagEncoder();
BikeFlagEncoder lessRelationCodes = new BikeFlagEncoder() {
@Override
public int defineRelationBits(int index, int shift) {
relationCodeEncoder = new EncodedValue("RelationCode2", shift, 2, 1, 0, 3);
return shift + 2;
}
@Override
public long handleRelationTags(ReaderRelation relation, long oldRelFlags) {
if (relation.hasTag("route", "bicycle"))
return relationCodeEncoder.setValue(0, 2);
return relationCodeEncoder.setValue(0, 0);
}
@Override
protected int handlePriority(ReaderWay way, double wayTypeSpeed, int priorityFromRelation) {
return priorityFromRelation;
}
@Override
public String toString() {
return "less_relations_bits";
}
};
EncodingManager manager = new EncodingManager(defaultBike, lessRelationCodes);
// relation code is PREFER
osmRel.setTag("route", "bicycle");
osmRel.setTag("network", "lcn");
long relFlags = manager.handleRelationTags(osmRel, 0);
long allow = defaultBike.acceptBit | lessRelationCodes.acceptBit;
long flags = manager.handleWayTags(osmWay, allow, relFlags);
assertTrue(defaultBike.getDouble(flags, PriorityWeighting.KEY) > lessRelationCodes.getDouble(flags, PriorityWeighting.KEY));
}
use of com.graphhopper.reader.ReaderRelation in project graphhopper by graphhopper.
the class RacingBikeFlagEncoderTest method testHandleWayTagsInfluencedByRelation.
@Test
public void testHandleWayTagsInfluencedByRelation() {
ReaderWay osmWay = new ReaderWay(1);
osmWay.setTag("highway", "track");
assertEquals(PUSHING_SECTION_SPEED / 2, getSpeedFromFlags(osmWay), 1e-1);
assertEquals("small way, unpaved", getWayTypeFromFlags(osmWay, 0));
// relation code is PREFER
long allowed = encoder.acceptBit;
ReaderRelation osmRel = new ReaderRelation(1);
osmRel.setTag("route", "bicycle");
osmRel.setTag("network", "lcn");
long relFlags = encoder.handleRelationTags(osmRel, 0);
long flags = encoder.handleWayTags(osmWay, allowed, relFlags);
assertEquals(2, encoder.getSpeed(flags), 1e-1);
assertPriority(AVOID_AT_ALL_COSTS.getValue(), osmWay, relFlags);
assertEquals("small way, unpaved", getWayTypeFromFlags(osmWay, relFlags));
// relation code is OUTSTANDING NICE but as unpaved, the speed is still PUSHING_SECTION_SPEED/2
osmRel.setTag("network", "icn");
relFlags = encoder.handleRelationTags(osmRel, 0);
flags = encoder.handleWayTags(osmWay, allowed, relFlags);
assertEquals(2, encoder.getSpeed(flags), 1e-1);
assertPriority(AVOID_AT_ALL_COSTS.getValue(), osmWay, relFlags);
// Now we assume bicycle=yes, anyhow still unpaved
osmWay.setTag("bicycle", "yes");
relFlags = encoder.handleRelationTags(osmRel, 0);
flags = encoder.handleWayTags(osmWay, allowed, relFlags);
assertEquals(2, encoder.getSpeed(flags), 1e-1);
assertPriority(AVOID_AT_ALL_COSTS.getValue(), osmWay, relFlags);
// Now we assume bicycle=yes, and paved
osmWay.setTag("tracktype", "grade1");
relFlags = encoder.handleRelationTags(osmRel, 0);
flags = encoder.handleWayTags(osmWay, allowed, relFlags);
assertEquals(20, encoder.getSpeed(flags), 1e-1);
assertPriority(PREFER.getValue(), osmWay, relFlags);
assertEquals("cycleway", getWayTypeFromFlags(osmWay, relFlags));
// Now we assume bicycle=yes, and unpaved as part of a cycle relation
osmWay.setTag("tracktype", "grade2");
osmWay.setTag("bicycle", "yes");
relFlags = encoder.handleRelationTags(osmRel, 0);
flags = encoder.handleWayTags(osmWay, allowed, relFlags);
assertEquals(10, encoder.getSpeed(flags), 1e-1);
assertPriority(AVOID_AT_ALL_COSTS.getValue(), osmWay, relFlags);
assertEquals("small way, unpaved", getWayTypeFromFlags(osmWay, relFlags));
// Now we assume bicycle=yes, and unpaved not part of a cycle relation
osmRel.clearTags();
osmWay.clearTags();
osmWay.setTag("highway", "track");
osmWay.setTag("tracktype", "grade3");
relFlags = encoder.handleRelationTags(osmRel, 0);
flags = encoder.handleWayTags(osmWay, allowed, relFlags);
assertEquals(PUSHING_SECTION_SPEED, encoder.getSpeed(flags), 1e-1);
assertPriority(AVOID_AT_ALL_COSTS.getValue(), osmWay, relFlags);
assertEquals("get off the bike, unpaved", getWayTypeFromFlags(osmWay, relFlags));
// Now we assume bicycle=yes, and tracktype = null
osmRel.clearTags();
osmWay.clearTags();
osmWay.setTag("highway", "track");
relFlags = encoder.handleRelationTags(osmRel, 0);
flags = encoder.handleWayTags(osmWay, allowed, relFlags);
assertEquals(2, encoder.getSpeed(flags), 1e-1);
assertPriority(AVOID_AT_ALL_COSTS.getValue(), osmWay, relFlags);
assertEquals("small way, unpaved", getWayTypeFromFlags(osmWay, relFlags));
}
use of com.graphhopper.reader.ReaderRelation in project graphhopper by graphhopper.
the class BikeFlagEncoderTest method testUnchangedRelationShouldNotInfluencePriority.
@Test
public void testUnchangedRelationShouldNotInfluencePriority() {
ReaderWay osmWay = new ReaderWay(1);
osmWay.setTag("highway", "secondary");
ReaderRelation osmRel = new ReaderRelation(1);
osmRel.setTag("description", "something");
long relFlags = encoder.handleRelationTags(osmRel, 0);
assertPriority(REACH_DEST.getValue(), osmWay, relFlags);
}
Aggregations