Search in sources :

Example 1 with DefaultSpatialRule

use of com.graphhopper.routing.util.spatialrules.countries.DefaultSpatialRule in project graphhopper by graphhopper.

the class LandmarkStorageTest method testWithBorderBlocking.

@Test
public void testWithBorderBlocking() {
    AbstractRoutingAlgorithmTester.initBiGraph(ghStorage);
    LandmarkStorage storage = new LandmarkStorage(ghStorage, new RAMDirectory(), 2, new FastestWeighting(encoder), TraversalMode.NODE_BASED);
    final SpatialRule ruleRight = new DefaultSpatialRule() {

        @Override
        public String getId() {
            return "right";
        }
    };
    final SpatialRule ruleLeft = new DefaultSpatialRule() {

        @Override
        public String getId() {
            return "left";
        }
    };
    final SpatialRuleLookup lookup = new SpatialRuleLookup() {

        @Override
        public SpatialRule lookupRule(double lat, double lon) {
            if (lon > 0.00105)
                return ruleRight;
            return ruleLeft;
        }

        @Override
        public SpatialRule lookupRule(GHPoint point) {
            return lookupRule(point.lat, point.lon);
        }

        @Override
        public void addRule(SpatialRule rule) {
        }

        @Override
        public int getSpatialId(SpatialRule rule) {
            throw new IllegalStateException();
        }

        @Override
        public BBox getBounds() {
            throw new IllegalStateException();
        }

        @Override
        public int size() {
            return 2;
        }
    };
    storage.setSpatialRuleLookup(lookup);
    storage.setMinimumNodes(2);
    storage.createLandmarks();
    assertEquals(3, storage.getSubnetworksWithLandmarks());
}
Also used : FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) SpatialRule(com.graphhopper.routing.util.spatialrules.SpatialRule) DefaultSpatialRule(com.graphhopper.routing.util.spatialrules.countries.DefaultSpatialRule) DefaultSpatialRule(com.graphhopper.routing.util.spatialrules.countries.DefaultSpatialRule) SpatialRuleLookup(com.graphhopper.routing.util.spatialrules.SpatialRuleLookup) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Aggregations

SpatialRule (com.graphhopper.routing.util.spatialrules.SpatialRule)1 SpatialRuleLookup (com.graphhopper.routing.util.spatialrules.SpatialRuleLookup)1 DefaultSpatialRule (com.graphhopper.routing.util.spatialrules.countries.DefaultSpatialRule)1 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)1 GHPoint (com.graphhopper.util.shapes.GHPoint)1 Test (org.junit.Test)1