Search in sources :

Example 1 with SpatialRule

use of com.graphhopper.routing.util.spatialrules.SpatialRule in project graphhopper by graphhopper.

the class DataFlagEncoder method handleWayTags.

@Override
public long handleWayTags(ReaderWay way, long allowed, long relationFlags) {
    if (!isAccept(allowed))
        return 0;
    try {
        // HIGHWAY
        int hwValue = getHighwayValue(way);
        // exclude any routing like if you have car and need to exclude all rails or ships
        if (hwValue == 0)
            return 0;
        long flags = 0;
        if (isFerry(allowed)) {
            hwValue = highwayMap.get("ferry");
        }
        flags = highwayEncoder.setValue(0, hwValue);
        // MAXSPEED
        double maxSpeed = parseSpeed(way.getTag("maxspeed"));
        if (isSpatialRuleLookupEnabled() && maxSpeed < 0) {
            // TODO What if no maxspeed is set, but only forward and backward, and both are higher than the usually allowed?
            maxSpeed = getSpatialRule(way).getMaxSpeed(way.getTag("highway", ""), maxSpeed);
        }
        double fwdSpeed = parseSpeed(way.getTag("maxspeed:forward"));
        if (fwdSpeed < 0 && maxSpeed > 0)
            fwdSpeed = maxSpeed;
        if (fwdSpeed > getMaxPossibleSpeed())
            fwdSpeed = getMaxPossibleSpeed();
        double bwdSpeed = parseSpeed(way.getTag("maxspeed:backward"));
        if (bwdSpeed < 0 && maxSpeed > 0)
            bwdSpeed = maxSpeed;
        if (bwdSpeed > getMaxPossibleSpeed())
            bwdSpeed = getMaxPossibleSpeed();
        // TODO and 140 should be used for "none" speed limit on German Autobahn
        if (fwdSpeed > 0)
            flags = carFwdMaxspeedEncoder.setDoubleValue(flags, fwdSpeed);
        if (bwdSpeed > 0)
            flags = carBwdMaxspeedEncoder.setDoubleValue(flags, bwdSpeed);
        // Road attributes (height, weight, width)
        if (isStoreHeight()) {
            List<String> heightTags = Arrays.asList("maxheight", "maxheight:physical");
            flags = extractMeter(way, flags, heightEncoder, heightTags);
        }
        if (isStoreWeight()) {
            List<String> weightTags = Arrays.asList("maxweight", "maxgcweight");
            flags = extractTons(way, flags, weightEncoder, weightTags);
        }
        if (isStoreWidth()) {
            List<String> widthTags = Arrays.asList("maxwidth", "maxwidth:physical");
            flags = extractMeter(way, flags, widthEncoder, widthTags);
        }
        // SURFACE
        String surfaceValue = way.getTag("surface");
        Integer sValue = surfaceMap.get(surfaceValue);
        if (sValue == null)
            sValue = 0;
        flags = surfaceEncoder.setValue(flags, sValue);
        // TRANSPORT MODE
        int tmValue = 0;
        for (String tm : transportModeList) {
            if (way.hasTag(tm)) {
                tmValue = transportModeMap.get(tm);
                break;
            }
        }
        flags = transportModeEncoder.setValue(flags, tmValue);
        // ROUNDABOUT
        boolean isRoundabout = way.hasTag("junction", "roundabout");
        if (isRoundabout)
            flags = setBool(flags, K_ROUNDABOUT, true);
        // ONEWAY (currently car only)
        boolean isOneway = way.hasTag("oneway", oneways) || way.hasTag("vehicle:backward") || way.hasTag("vehicle:forward") || way.hasTag("motor_vehicle:backward") || way.hasTag("motor_vehicle:forward");
        if (isOneway || isRoundabout) {
            boolean isBackward = way.hasTag("oneway", "-1") || way.hasTag("vehicle:forward", "no") || way.hasTag("motor_vehicle:forward", "no");
            if (isBackward)
                flags |= backwardBit;
            else
                flags |= forwardBit;
        } else
            flags |= directionBitMask;
        if (!isBit0Empty(flags))
            throw new IllegalStateException("bit0 has to be empty on creation");
        flags = accessEncoder.setValue(flags, getAccessValue(way));
        if (isSpatialRuleLookupEnabled()) {
            GHPoint estimatedCenter = way.getTag("estimated_center", null);
            if (estimatedCenter != null) {
                SpatialRule rule = spatialRuleLookup.lookupRule(estimatedCenter);
                flags = spatialEncoder.setValue(flags, spatialRuleLookup.getSpatialId(rule));
            }
        }
        return flags;
    } catch (Exception ex) {
        throw new RuntimeException("Error while parsing way " + way.toString(), ex);
    }
}
Also used : SpatialRule(com.graphhopper.routing.util.spatialrules.SpatialRule) GHPoint(com.graphhopper.util.shapes.GHPoint) GHPoint(com.graphhopper.util.shapes.GHPoint)

Example 2 with SpatialRule

use of com.graphhopper.routing.util.spatialrules.SpatialRule in project graphhopper by graphhopper.

the class LandmarkStorage method findBorderEdgeIds.

/**
     * This method makes edges crossing the specified border inaccessible to split a bigger area into smaller subnetworks.
     * This is important for the world wide use case to limit the maximum distance and also to detect unreasonable routes faster.
     */
protected IntHashSet findBorderEdgeIds(SpatialRuleLookup ruleLookup) {
    AllEdgesIterator allEdgesIterator = graph.getAllEdges();
    NodeAccess nodeAccess = graph.getNodeAccess();
    IntHashSet inaccessible = new IntHashSet();
    while (allEdgesIterator.next()) {
        int adjNode = allEdgesIterator.getAdjNode();
        SpatialRule ruleAdj = ruleLookup.lookupRule(nodeAccess.getLatitude(adjNode), nodeAccess.getLongitude(adjNode));
        int baseNode = allEdgesIterator.getBaseNode();
        SpatialRule ruleBase = ruleLookup.lookupRule(nodeAccess.getLatitude(baseNode), nodeAccess.getLongitude(baseNode));
        if (ruleAdj != ruleBase)
            inaccessible.add(allEdgesIterator.getEdge());
    }
    return inaccessible;
}
Also used : IntHashSet(com.carrotsearch.hppc.IntHashSet) SpatialRule(com.graphhopper.routing.util.spatialrules.SpatialRule) GHPoint(com.graphhopper.util.shapes.GHPoint)

Example 3 with SpatialRule

use of com.graphhopper.routing.util.spatialrules.SpatialRule 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)3 GHPoint (com.graphhopper.util.shapes.GHPoint)3 IntHashSet (com.carrotsearch.hppc.IntHashSet)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 Test (org.junit.Test)1