Search in sources :

Example 1 with GeneralRouteRestriction

use of uk.me.parabola.imgfmt.app.net.GeneralRouteRestriction in project mkgmap by openstreetmap.

the class StyledConverter method createRouteRestrictionsFromPOI.

/**
 * If POI changes access restrictions (e.g. bollards), create corresponding
 * route restrictions so that only allowed vehicles/pedestrians are routed
 * through this point.
 */
private void createRouteRestrictionsFromPOI() {
    Iterator<Map.Entry<Node, List<Way>>> iter = poiRestrictions.entrySet().iterator();
    while (iter.hasNext()) {
        Map.Entry<Node, List<Way>> entry = iter.next();
        Node node = entry.getKey();
        Coord p = node.getLocation();
        // list of ways that are connected to the poi
        List<Way> wayList = entry.getValue();
        byte exceptMask = AccessTagsAndBits.evalAccessTags(node);
        Map<Integer, CoordNode> otherNodeIds = new LinkedHashMap<>();
        CoordNode viaNode = null;
        boolean viaIsUnique = true;
        for (Way way : wayList) {
            CoordNode lastNode = null;
            for (Coord co : way.getPoints()) {
                // not 100% fail safe: points may have been replaced before
                if (co instanceof CoordNode == false)
                    continue;
                CoordNode cn = (CoordNode) co;
                if (p.highPrecEquals(cn)) {
                    if (viaNode == null)
                        viaNode = cn;
                    else if (viaNode != cn) {
                        log.error("Found multiple points with equal coords as CoordPOI at " + p.toOSMURL());
                        // if we ever get here we can add code to identify the exact node
                        viaIsUnique = false;
                    }
                    if (lastNode != null)
                        otherNodeIds.put(lastNode.getId(), lastNode);
                } else {
                    if (p.highPrecEquals(lastNode))
                        otherNodeIds.put(cn.getId(), cn);
                }
                lastNode = cn;
            }
        }
        if (viaNode == null) {
            log.error("Did not find CoordPOI node at " + p.toOSMURL() + " in ways " + wayList);
            continue;
        }
        if (viaIsUnique == false) {
            log.error("Found multiple points with equal coords as CoordPOI at " + p.toOSMURL());
            continue;
        }
        if (otherNodeIds.size() < 2) {
            log.info("Access restriction in POI node " + node.toBrowseURL() + " was ignored, has no effect on any connected way");
            continue;
        }
        GeneralRouteRestriction rr = new GeneralRouteRestriction("no_through", exceptMask, "CoordPOI at " + p.toOSMURL());
        rr.setViaNodes(Arrays.asList(viaNode));
        int added = collector.addRestriction(rr);
        if (added == 0) {
            log.info("Access restriction in POI node " + node.toBrowseURL() + " was ignored, has no effect on any connected way");
        } else {
            log.info("Access restriction in POI node", node.toBrowseURL(), "was translated to", added, "route restriction(s)");
        }
        if (wayList.size() > 1 && added > 2) {
            log.warn("Access restriction in POI node", node.toBrowseURL(), "affects routing on multiple ways");
        }
    }
}
Also used : Node(uk.me.parabola.mkgmap.reader.osm.Node) CoordNode(uk.me.parabola.imgfmt.app.CoordNode) Way(uk.me.parabola.mkgmap.reader.osm.Way) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) MapExitPoint(uk.me.parabola.mkgmap.general.MapExitPoint) LinkedHashMap(java.util.LinkedHashMap) Coord(uk.me.parabola.imgfmt.app.Coord) Entry(java.util.Map.Entry) GeneralRouteRestriction(uk.me.parabola.imgfmt.app.net.GeneralRouteRestriction) List(java.util.List) ArrayList(java.util.ArrayList) CoordNode(uk.me.parabola.imgfmt.app.CoordNode) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MultiHashMap(uk.me.parabola.util.MultiHashMap)

Example 2 with GeneralRouteRestriction

use of uk.me.parabola.imgfmt.app.net.GeneralRouteRestriction in project mkgmap by openstreetmap.

the class StyledConverterTest method makeConverter.

private StyledConverter makeConverter(String name) throws FileNotFoundException {
    Style style = new StyleImpl(LOC, name);
    MapCollector coll = new MapCollector() {

        public void addToBounds(Coord p) {
        }

        // could save points in the same way as lines to test them
        public void addPoint(MapPoint point) {
        }

        public void addLine(MapLine line) {
            // Save line so that it can be examined in the tests.
            assertNotNull("points are not null", line.getPoints());
            lines.add(line);
        }

        public void addShape(MapShape shape) {
        }

        public void addRoad(MapRoad road) {
            lines.add(road);
        }

        public int addRestriction(GeneralRouteRestriction grr) {
            return 0;
        }

        public void addThroughRoute(int junctionNodeId, long roadIdA, long roadIdB) {
        }
    };
    return new StyledConverter(style, coll, new EnhancedProperties());
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) EnhancedProperties(uk.me.parabola.util.EnhancedProperties) MapLine(uk.me.parabola.mkgmap.general.MapLine) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) GeneralRouteRestriction(uk.me.parabola.imgfmt.app.net.GeneralRouteRestriction) Style(uk.me.parabola.mkgmap.reader.osm.Style) MapRoad(uk.me.parabola.mkgmap.general.MapRoad) MapCollector(uk.me.parabola.mkgmap.general.MapCollector) MapShape(uk.me.parabola.mkgmap.general.MapShape)

Example 3 with GeneralRouteRestriction

use of uk.me.parabola.imgfmt.app.net.GeneralRouteRestriction in project mkgmap by openstreetmap.

the class RestrictionHelper method processAndAddRestrictions.

public void processAndAddRestrictions(RoadHelper roadHelper, MapDetails mapper) {
    Map<Long, CoordNode> allNodes = roadHelper.getNodeCoords();
    for (PolishTurnRestriction tr : allRestrictions) {
        GeneralRouteRestriction grr = new GeneralRouteRestriction("not", tr.getExceptMask(), Long.toString(tr.getNodId()));
        grr.setFromNode(allNodes.get(tr.getFromNodId()));
        grr.setFromWayId(tr.getRoadIdA());
        grr.setToNode(allNodes.get(tr.getToNodId()));
        if (tr.getViaNodId() != 0) {
            grr.setViaNodes(Arrays.asList(allNodes.get(tr.getNodId()), allNodes.get(tr.getViaNodId())));
            grr.setViaWayIds(Arrays.asList(tr.getRoadIdB()));
            grr.setToWayId(tr.getRoadIdC());
        } else {
            grr.setViaNodes(Arrays.asList(allNodes.get(tr.getNodId())));
            grr.setToWayId(tr.getRoadIdB());
        }
        // restriction should be part of the map
        mapper.addRestriction(grr);
    }
}
Also used : GeneralRouteRestriction(uk.me.parabola.imgfmt.app.net.GeneralRouteRestriction) CoordNode(uk.me.parabola.imgfmt.app.CoordNode)

Example 4 with GeneralRouteRestriction

use of uk.me.parabola.imgfmt.app.net.GeneralRouteRestriction in project mkgmap by openstreetmap.

the class RestrictionRelation method addRestriction.

public void addRestriction(MapCollector collector, IdentityHashMap<Coord, CoordNode> nodeIdMap) {
    if (!valid)
        return;
    List<CoordNode> viaNodes = new ArrayList<>();
    for (Coord v : viaPoints) {
        CoordNode vn = nodeIdMap.get(v);
        if (vn == null) {
            log.error(messagePrefix, "via node is not a routing node");
            return;
        }
        viaNodes.add(vn);
    }
    if (viaNodes.size() > 6) {
        log.warn(messagePrefix, "has more than 6 via nodes, this is not supported");
        return;
    }
    if (restriction == null) {
        log.error("internal error: can't add valid restriction relation", this.getId(), "type", restriction);
        return;
    }
    int addedRestrictions = 0;
    GeneralRouteRestriction grr;
    if (restriction.startsWith("no_")) {
        for (long fromWayId : fromWayIds) {
            for (long toWayId : toWayIds) {
                grr = new GeneralRouteRestriction("not", exceptMask, messagePrefix);
                grr.setFromWayId(fromWayId);
                grr.setToWayId(toWayId);
                grr.setViaNodes(viaNodes);
                grr.setViaWayIds(viaWayIds);
                grr.setDirIndicator(dirIndicator);
                addedRestrictions += collector.addRestriction(grr);
            }
        }
        if (log.isInfoEnabled())
            log.info(messagePrefix, restriction, "translated to", addedRestrictions, "img file restrictions");
    } else if (restriction.startsWith("only_")) {
        grr = new GeneralRouteRestriction("only", exceptMask, messagePrefix);
        grr.setFromWayId(fromWayIds.get(0));
        grr.setToWayId(toWayIds.get(0));
        grr.setViaNodes(viaNodes);
        grr.setViaWayIds(viaWayIds);
        grr.setDirIndicator(dirIndicator);
        int numAdded = collector.addRestriction(grr);
        if (numAdded > 0)
            log.info(messagePrefix, restriction, "added - allows routing to way", toWayIds.get(0));
    } else {
        log.error("mkgmap internal error: unknown restriction", restriction);
    }
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) ArrayList(java.util.ArrayList) GeneralRouteRestriction(uk.me.parabola.imgfmt.app.net.GeneralRouteRestriction) CoordNode(uk.me.parabola.imgfmt.app.CoordNode)

Aggregations

GeneralRouteRestriction (uk.me.parabola.imgfmt.app.net.GeneralRouteRestriction)4 Coord (uk.me.parabola.imgfmt.app.Coord)3 CoordNode (uk.me.parabola.imgfmt.app.CoordNode)3 ArrayList (java.util.ArrayList)2 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)2 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 MapCollector (uk.me.parabola.mkgmap.general.MapCollector)1 MapExitPoint (uk.me.parabola.mkgmap.general.MapExitPoint)1 MapLine (uk.me.parabola.mkgmap.general.MapLine)1 MapRoad (uk.me.parabola.mkgmap.general.MapRoad)1 MapShape (uk.me.parabola.mkgmap.general.MapShape)1 Node (uk.me.parabola.mkgmap.reader.osm.Node)1 Style (uk.me.parabola.mkgmap.reader.osm.Style)1 Way (uk.me.parabola.mkgmap.reader.osm.Way)1 EnhancedProperties (uk.me.parabola.util.EnhancedProperties)1