Search in sources :

Example 1 with Way

use of uk.me.parabola.mkgmap.reader.osm.Way in project mkgmap by openstreetmap.

the class StyledConverter method convertWay.

public void convertWay(final Way way) {
    if (way.getPoints().size() < 2 || way.getTagCount() == 0) {
        // no tags or no points => nothing to convert
        removeRestrictionsWithWay(Level.WARNING, way, "is ignored");
        return;
    }
    preConvertRules(way);
    String styleFilterTag = way.getTag(styleFilterTagKey);
    Rule rules;
    if ("polyline".equals(styleFilterTag))
        rules = lineRules;
    else if ("polygon".equals(styleFilterTag))
        rules = polygonRules;
    else {
        if (way.isClosedInOSM() && !way.isComplete() && !way.hasIdenticalEndPoints())
            way.getPoints().add(way.getPoints().get(0));
        if (way.hasIdenticalEndPoints() == false || way.getPoints().size() < 4)
            rules = lineRules;
        else
            rules = wayRules;
    }
    Way cycleWay = null;
    String cycleWayTag = way.getTag(makeCycleWayTagKey);
    if ("yes".equals(cycleWayTag)) {
        way.deleteTag("mkgmap:make-cycle-way");
        cycleWay = makeCycleWay(way);
        // make sure that bicycles are using the added bicycle way
        way.addTag("bicycle", "no");
    }
    wayTypeResult.setWay(way);
    lineCacheId = rules.resolveType(lineCacheId, way, wayTypeResult);
    if (wayTypeResult.isMatched() == false) {
        // no match found but we have to keep it for house number processing
        housenumberGenerator.addWay(way);
    }
    if (cycleWay != null) {
        wayTypeResult.setWay(cycleWay);
        lineCacheId = rules.resolveType(lineCacheId, cycleWay, wayTypeResult);
        if (wayTypeResult.isMatched() == false) {
            // no match found but we have to keep it for house number processing
            housenumberGenerator.addWay(cycleWay);
        }
    }
    if (lastRoadId != way.getId()) {
        // this way was not added to the roads list
        removeRestrictionsWithWay(Level.WARNING, way, "is not routable");
    } else {
        // which have to be skipped by WrongAngleFixer
        for (int i = lines.size() - 1; i >= 0; --i) {
            ConvertedWay cw = lines.get(i);
            if (cw.getWay().getId() == way.getId()) {
                cw.setOverlay(true);
                int lineType = cw.getGType().getType();
                if (GType.isSpecialRoutableLineType(lineType) && cw.getGType().getMinLevel() == 0) {
                    if (!routingWarningWasPrinted.get(lineType)) {
                        log.error("routable type", GType.formatType(cw.getGType().getType()), "is used with a non-routable way which was also added as a routable way. This leads to routing errors.", "Try --check-styles to check the style.");
                        routingWarningWasPrinted.set(lineType);
                    }
                }
            } else
                break;
        }
    }
}
Also used : Rule(uk.me.parabola.mkgmap.reader.osm.Rule) Way(uk.me.parabola.mkgmap.reader.osm.Way) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) MapExitPoint(uk.me.parabola.mkgmap.general.MapExitPoint)

Example 2 with Way

use of uk.me.parabola.mkgmap.reader.osm.Way 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 3 with Way

use of uk.me.parabola.mkgmap.reader.osm.Way in project mkgmap by openstreetmap.

the class StyledConverter method makeCycleWay.

/**
 * Construct a cycleway that has the same points as an existing way.  Used for separate
 * cycle lanes.
 * @param way The original way.
 * @return The new way, which will have the same points and have suitable cycle tags.
 */
private static Way makeCycleWay(Way way) {
    Way cycleWay = new Way(way.getId(), way.getPoints());
    cycleWay.copyTags(way);
    cycleWay.addTag("access", "no");
    cycleWay.addTag("bicycle", "yes");
    cycleWay.addTag("mkgmap:synthesised", "yes");
    cycleWay.addTag(onewayTagKey, "no");
    // remove explicit access tags
    cycleWay.deleteTag("foot");
    cycleWay.deleteTag("motorcar");
    cycleWay.deleteTag("goods");
    cycleWay.deleteTag("hgv");
    cycleWay.deleteTag("bus");
    cycleWay.deleteTag("taxi");
    cycleWay.deleteTag("emergency");
    cycleWay.deleteTag("vehicle");
    cycleWay.deleteTag("motor_vehicle");
    cycleWay.deleteTag("carpool");
    cycleWay.deleteTag("motorcycle");
    cycleWay.deleteTag("psv");
    cycleWay.deleteTag("truck");
    return cycleWay;
}
Also used : Way(uk.me.parabola.mkgmap.reader.osm.Way)

Example 4 with Way

use of uk.me.parabola.mkgmap.reader.osm.Way in project mkgmap by openstreetmap.

the class StyledConverter method filterCoordPOI.

/**
 * Make sure that only CoordPOI which affect routing will be treated as
 * nodes in the following routines.
 */
private void filterCoordPOI() {
    if (!linkPOIsToWays)
        return;
    log.info("translating CoordPOI");
    for (ConvertedWay cw : roads) {
        if (!cw.isValid())
            continue;
        Way way = cw.getWay();
        if ("true".equals(way.getTag("mkgmap:way-has-pois"))) {
            String wayPOI = "";
            List<Coord> points = way.getPoints();
            int numPoints = points.size();
            for (int i = 0; i < numPoints; i++) {
                Coord p = points.get(i);
                if (p instanceof CoordPOI) {
                    CoordPOI cp = (CoordPOI) p;
                    Node node = cp.getNode();
                    boolean usedInThisWay = false;
                    byte wayAccess = cw.getAccess();
                    if (node.getTag("mkgmap:road-class") != null || node.getTag("mkgmap:road-speed") != null) {
                        if (wayAccess != AccessTagsAndBits.FOOT)
                            usedInThisWay = true;
                    }
                    byte nodeAccess = AccessTagsAndBits.evalAccessTags(node);
                    if (nodeAccess != (byte) 0xff) {
                        // barriers etc.
                        if ((wayAccess & nodeAccess) != wayAccess) {
                            // node is more restrictive
                            if (p.getHighwayCount() >= 2 || (i != 0 && i != numPoints - 1)) {
                                usedInThisWay = true;
                                cp.setConvertToViaInRouteRestriction(true);
                            } else {
                                log.info("POI node", node.getId(), "with access restriction is ignored, it is not connected to other routable ways");
                            }
                        } else
                            log.info("Access restriction in POI node", node.toBrowseURL(), "was ignored for way", way.toBrowseURL());
                    }
                    if (usedInThisWay) {
                        cp.setUsed(true);
                        wayPOI += "[" + node.getId() + "]";
                    }
                }
            }
            if (wayPOI.isEmpty()) {
                way.deleteTag("mkgmap:way-has-pois");
                log.info("ignoring CoordPOI(s) for way", way.toBrowseURL(), "because routing is not affected.");
            } else {
                way.addTag(WAY_POI_NODE_IDS, wayPOI);
            }
        }
    }
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) CoordPOI(uk.me.parabola.mkgmap.reader.osm.CoordPOI) 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)

Example 5 with Way

use of uk.me.parabola.mkgmap.reader.osm.Way in project mkgmap by openstreetmap.

the class StyledConverter method splitWayAt.

/**
 * split a Way at the specified point and return the new Way (the
 * original Way is truncated, both ways will contain the split point)
 * @param way the way to split
 * @param index the split position.
 * @return the trailing part of the way
 */
private static Way splitWayAt(Way way, int index) {
    if (way.isViaWay()) {
        log.warn("via way of restriction is split, restriction will be ignored", way);
    }
    Way trailingWay = new Way(way.getId());
    List<Coord> wayPoints = way.getPoints();
    int numPointsInWay = wayPoints.size();
    for (int i = index; i < numPointsInWay; ++i) trailingWay.addPoint(wayPoints.get(i));
    // ensure split point becomes a node
    wayPoints.get(index).incHighwayCount();
    // copy the way's name and tags to the new way
    trailingWay.copyTags(way);
    // it's probably more efficient to remove from the end first
    for (int i = numPointsInWay - 1; i > index; --i) wayPoints.remove(i);
    return trailingWay;
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) Way(uk.me.parabola.mkgmap.reader.osm.Way) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) MapExitPoint(uk.me.parabola.mkgmap.general.MapExitPoint)

Aggregations

Way (uk.me.parabola.mkgmap.reader.osm.Way)142 Test (org.junit.Test)94 TestUtils.makeRuleSet (func.lib.TestUtils.makeRuleSet)70 GType (uk.me.parabola.mkgmap.reader.osm.GType)60 Element (uk.me.parabola.mkgmap.reader.osm.Element)48 Coord (uk.me.parabola.imgfmt.app.Coord)31 ArrayList (java.util.ArrayList)18 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)12 MapExitPoint (uk.me.parabola.mkgmap.general.MapExitPoint)11 List (java.util.List)8 Node (uk.me.parabola.mkgmap.reader.osm.Node)8 HashMap (java.util.HashMap)7 IdentityHashMap (java.util.IdentityHashMap)6 Map (java.util.Map)6 StringStyleFileLoader (func.lib.StringStyleFileLoader)5 CoordNode (uk.me.parabola.imgfmt.app.CoordNode)5 Relation (uk.me.parabola.mkgmap.reader.osm.Relation)5 CoordPOI (uk.me.parabola.mkgmap.reader.osm.CoordPOI)4 RestrictionRelation (uk.me.parabola.mkgmap.reader.osm.RestrictionRelation)4 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)3