Search in sources :

Example 1 with TagParser

use of com.graphhopper.routing.util.parsers.TagParser in project graphhopper by graphhopper.

the class GraphHopperTest method testSRTMWithTunnelInterpolation.

@ParameterizedTest
@ValueSource(booleans = { true, false })
public void testSRTMWithTunnelInterpolation(boolean withTunnelInterpolation) {
    final String profile = "profile";
    final String vehicle = "foot";
    final String weighting = "shortest";
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setStoreOnFlush(true);
    if (!withTunnelInterpolation) {
        hopper.setTagParserFactory(new DefaultTagParserFactory() {

            @Override
            public TagParser create(EncodedValueLookup lookup, String name) {
                TagParser parser = super.create(lookup, name);
                if (name.equals("road_environment"))
                    parser = new OSMRoadEnvironmentParser(lookup.getEnumEncodedValue(RoadEnvironment.KEY, RoadEnvironment.class)) {

                        @Override
                        public IntsRef handleWayTags(IntsRef edgeFlags, ReaderWay readerWay, IntsRef relationFlags) {
                            // do not change RoadEnvironment to avoid triggering tunnel interpolation
                            return edgeFlags;
                        }
                    };
                return parser;
            }
        });
        hopper.setEncodedValuesString("road_environment");
    }
    hopper.setElevationProvider(new SRTMProvider(DIR));
    hopper.importOrLoad();
    GHPoint from = new GHPoint(43.7405647, 7.4299266);
    GHPoint to = new GHPoint(43.7378990, 7.4279780);
    // make sure we hit tower nodes, because all we really want is test the elevation interpolation
    assertEquals(Snap.Position.TOWER, hopper.getLocationIndex().findClosest(from.lat, from.lon, EdgeFilter.ALL_EDGES).getSnappedPosition());
    assertEquals(Snap.Position.TOWER, hopper.getLocationIndex().findClosest(to.lat, to.lon, EdgeFilter.ALL_EDGES).getSnappedPosition());
    GHResponse rsp = hopper.route(new GHRequest(from, to).setProfile(profile));
    ResponsePath res = rsp.getBest();
    PointList pointList = res.getPoints();
    assertEquals(6, pointList.size());
    assertTrue(pointList.is3D());
    if (withTunnelInterpolation) {
        assertEquals(351.8, res.getDistance(), .1);
        assertEquals(17, pointList.getEle(0), .1);
        assertEquals(19.04, pointList.getEle(1), .1);
        assertEquals(21.67, pointList.getEle(2), .1);
        assertEquals(25.03, pointList.getEle(3), .1);
        assertEquals(28.65, pointList.getEle(4), .1);
        assertEquals(34.00, pointList.getEle(5), .1);
    } else {
        assertEquals(358.3, res.getDistance(), .1);
        assertEquals(17.0, pointList.getEle(0), .1);
        assertEquals(23.0, pointList.getEle(1), .1);
        assertEquals(23.0, pointList.getEle(2), .1);
        assertEquals(41.0, pointList.getEle(3), .1);
        assertEquals(19.0, pointList.getEle(4), .1);
        assertEquals(34.0, pointList.getEle(5), .1);
    }
}
Also used : DefaultTagParserFactory(com.graphhopper.routing.util.parsers.DefaultTagParserFactory) TagParser(com.graphhopper.routing.util.parsers.TagParser) EncodedValueLookup(com.graphhopper.routing.ev.EncodedValueLookup) ReaderWay(com.graphhopper.reader.ReaderWay) LMProfile(com.graphhopper.config.LMProfile) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) SRTMProvider(com.graphhopper.reader.dem.SRTMProvider) OSMRoadEnvironmentParser(com.graphhopper.routing.util.parsers.OSMRoadEnvironmentParser) IntsRef(com.graphhopper.storage.IntsRef) GHPoint(com.graphhopper.util.shapes.GHPoint) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with TagParser

use of com.graphhopper.routing.util.parsers.TagParser in project graphhopper by graphhopper.

the class TagParsingTest method testSharedEncodedValues.

@Test
public void testSharedEncodedValues() {
    EncodingManager manager = EncodingManager.create("car,foot,bike,motorcycle,mtb");
    BooleanEncodedValue roundaboutEnc = manager.getBooleanEncodedValue(Roundabout.KEY);
    List<TagParser> tagParsers = Arrays.asList(new OSMRoundaboutParser(roundaboutEnc), new CarTagParser(manager, new PMap()), new FootTagParser(manager, new PMap()), new BikeTagParser(manager, new PMap()), new MotorcycleTagParser(manager, new PMap()), new MountainBikeTagParser(manager, new PMap()));
    for (TagParser tagParser : tagParsers) if (tagParser instanceof VehicleTagParser)
        ((VehicleTagParser) tagParser).init(new DateRangeParser());
    final IntsRef edgeFlags = manager.createEdgeFlags();
    IntsRef relFlags = manager.createRelationFlags();
    ReaderWay way = new ReaderWay(1);
    way.setTag("highway", "primary");
    way.setTag("junction", "roundabout");
    tagParsers.forEach(p -> p.handleWayTags(edgeFlags, way, relFlags));
    for (FlagEncoder tmp : manager.fetchEdgeEncoders()) {
        BooleanEncodedValue accessEnc = tmp.getAccessEnc();
        assertTrue(accessEnc.getBool(false, edgeFlags));
        assertTrue(roundaboutEnc.getBool(false, edgeFlags), tmp.toString());
    }
    final IntsRef edgeFlags2 = manager.createEdgeFlags();
    way.clearTags();
    way.setTag("highway", "tertiary");
    way.setTag("junction", "circular");
    tagParsers.forEach(p -> p.handleWayTags(edgeFlags2, way, relFlags));
    for (FlagEncoder tmp : manager.fetchEdgeEncoders()) {
        BooleanEncodedValue accessEnc = tmp.getAccessEnc();
        assertTrue(accessEnc.getBool(false, edgeFlags));
        assertTrue(roundaboutEnc.getBool(false, edgeFlags), tmp.toString());
    }
}
Also used : TagParser(com.graphhopper.routing.util.parsers.TagParser) OSMBikeNetworkTagParser(com.graphhopper.routing.util.parsers.OSMBikeNetworkTagParser) OSMRoundaboutParser(com.graphhopper.routing.util.parsers.OSMRoundaboutParser) PMap(com.graphhopper.util.PMap) ReaderWay(com.graphhopper.reader.ReaderWay) DateRangeParser(com.graphhopper.reader.osm.conditional.DateRangeParser) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Aggregations

ReaderWay (com.graphhopper.reader.ReaderWay)2 TagParser (com.graphhopper.routing.util.parsers.TagParser)2 IntsRef (com.graphhopper.storage.IntsRef)2 CHProfile (com.graphhopper.config.CHProfile)1 LMProfile (com.graphhopper.config.LMProfile)1 Profile (com.graphhopper.config.Profile)1 SRTMProvider (com.graphhopper.reader.dem.SRTMProvider)1 DateRangeParser (com.graphhopper.reader.osm.conditional.DateRangeParser)1 EncodedValueLookup (com.graphhopper.routing.ev.EncodedValueLookup)1 DefaultTagParserFactory (com.graphhopper.routing.util.parsers.DefaultTagParserFactory)1 OSMBikeNetworkTagParser (com.graphhopper.routing.util.parsers.OSMBikeNetworkTagParser)1 OSMRoadEnvironmentParser (com.graphhopper.routing.util.parsers.OSMRoadEnvironmentParser)1 OSMRoundaboutParser (com.graphhopper.routing.util.parsers.OSMRoundaboutParser)1 CustomProfile (com.graphhopper.routing.weighting.custom.CustomProfile)1 PMap (com.graphhopper.util.PMap)1 GHPoint (com.graphhopper.util.shapes.GHPoint)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 ValueSource (org.junit.jupiter.params.provider.ValueSource)1