Search in sources :

Example 76 with Element

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

the class RoadMerger method workoutThroughRoutes.

private void workoutThroughRoutes(List<Relation> throughRouteRelations) {
    for (Relation relation : throughRouteRelations) {
        Node node = null;
        Way w1 = null;
        Way w2 = null;
        for (Map.Entry<String, Element> member : relation.getElements()) {
            if (member.getValue() instanceof Node) {
                if (node == null)
                    node = (Node) member.getValue();
                else
                    log.warn("Through route relation " + relation.toBrowseURL() + " has more than 1 node");
            } else if (member.getValue() instanceof Way) {
                Way w = (Way) member.getValue();
                if (w1 == null)
                    w1 = w;
                else if (w2 == null)
                    w2 = w;
                else
                    log.warn("Through route relation " + relation.toBrowseURL() + " has more than 2 ways");
            }
        }
        if (node == null)
            log.warn("Through route relation " + relation.toBrowseURL() + " is missing the junction node");
        if (w1 == null || w2 == null)
            log.warn("Through route relation " + relation.toBrowseURL() + " should reference 2 ways that meet at the junction node");
        if (node != null && w1 != null && w2 != null) {
            restrictions.add(node.getLocation(), w1.getId());
            restrictions.add(node.getLocation(), w2.getId());
        }
    }
}
Also used : Relation(uk.me.parabola.mkgmap.reader.osm.Relation) RestrictionRelation(uk.me.parabola.mkgmap.reader.osm.RestrictionRelation) Node(uk.me.parabola.mkgmap.reader.osm.Node) Element(uk.me.parabola.mkgmap.reader.osm.Element) IdentityHashMap(java.util.IdentityHashMap) Map(java.util.Map) MultiIdentityHashMap(uk.me.parabola.util.MultiIdentityHashMap) Way(uk.me.parabola.mkgmap.reader.osm.Way)

Example 77 with Element

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

the class HousenumberGenerator method addRelation.

/**
 * Evaluate type=associatedStreet relations.
 */
public void addRelation(Relation r) {
    String relType = r.getTag("type");
    // the wiki says that we should also evaluate type=street
    if ("associatedStreet".equals(relType) || "street".equals(relType)) {
        List<Element> houses = new ArrayList<>();
        List<Element> streets = new ArrayList<>();
        for (Map.Entry<String, Element> member : r.getElements()) {
            if (member.getValue() instanceof Node) {
                Node node = (Node) member.getValue();
                houses.add(node);
            } else if (member.getValue() instanceof Way) {
                Way w = (Way) member.getValue();
                String role = member.getKey();
                switch(role) {
                    case "house":
                    case "addr:houselink":
                    case "address":
                        houses.add(w);
                        break;
                    case "street":
                        streets.add(w);
                        break;
                    case "":
                        if (w.getTag("highway") != null) {
                            streets.add(w);
                            continue;
                        }
                        String buildingTag = w.getTag("building");
                        if (buildingTag != null)
                            houses.add(w);
                        else
                            log.warn("Relation", r.toBrowseURL(), ": role of member", w.toBrowseURL(), "unclear");
                        break;
                    default:
                        if ("associatedStreet".equals(relType))
                            log.warn("Relation", r.toBrowseURL(), ": don't know how to handle member with role", role);
                        break;
                }
            }
        }
        String streetName = r.getTag("name");
        String streetNameFromRoads = null;
        List<Element> unnamedStreetElems = new ArrayList<>();
        boolean nameFromStreetsIsUnclear = false;
        if (streets.isEmpty() == false) {
            for (Element street : streets) {
                String roadName = street.getTag(streetTagKey);
                if (roadName == null)
                    roadName = street.getTag("name");
                if (roadName == null) {
                    unnamedStreetElems.add(street);
                    continue;
                }
                if (streetNameFromRoads == null)
                    streetNameFromRoads = roadName;
                else if (streetNameFromRoads.equals(roadName) == false)
                    nameFromStreetsIsUnclear = true;
            }
        }
        if (streetName == null) {
            if (nameFromStreetsIsUnclear == false)
                streetName = streetNameFromRoads;
            else {
                log.warn("Relation", r.toBrowseURL(), ": ignored, street name is not clear.");
                return;
            }
        } else {
            if (streetNameFromRoads != null) {
                if (nameFromStreetsIsUnclear == false && streetName.equals(streetNameFromRoads) == false) {
                    if (unnamedStreetElems.isEmpty() == false) {
                        log.warn("Relation", r.toBrowseURL(), ": ignored, street name is not clear.");
                        return;
                    }
                    log.warn("Relation", r.toBrowseURL(), ": street name is not clear, using the name from the way, not that of the relation.");
                    streetName = streetNameFromRoads;
                } else if (nameFromStreetsIsUnclear == true) {
                    log.warn("Relation", r.toBrowseURL(), ": street name is not clear, using the name from the relation.");
                }
            }
        }
        int countModHouses = 0;
        if (streetName != null && streetName.isEmpty() == false) {
            for (Element house : houses) {
                if (addStreetTagFromRel(r, house, streetName))
                    countModHouses++;
            }
            for (Element street : unnamedStreetElems) {
                street.addTag(streetTagKey, streetName);
                street.addTag("name", streetName);
            }
        }
        if (log.isInfoEnabled()) {
            if (countModHouses > 0 || !unnamedStreetElems.isEmpty()) {
                if (countModHouses > 0)
                    log.info("Relation", r.toBrowseURL(), ": added tag mkgmap:street=", streetName, "to", countModHouses, "of", houses.size(), "house members");
                if (!unnamedStreetElems.isEmpty())
                    log.info("Relation", r.toBrowseURL(), ": added tag mkgmap:street=", streetName, "to", unnamedStreetElems.size(), "of", streets.size(), "street members");
            } else
                log.info("Relation", r.toBrowseURL(), ": ignored, no house or street member was changed");
        }
    }
}
Also used : Element(uk.me.parabola.mkgmap.reader.osm.Element) Node(uk.me.parabola.mkgmap.reader.osm.Node) LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) Map(java.util.Map) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) Int2IntOpenHashMap(it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap) TreeMap(java.util.TreeMap) MultiHashMap(uk.me.parabola.util.MultiHashMap) Way(uk.me.parabola.mkgmap.reader.osm.Way)

Example 78 with Element

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

the class OsmXmlHandler method startInRelation.

/**
 * A new tag has been started while we are inside the relation tag.
 * @param qName The new tag name.
 * @param attributes Its attributes.
 */
private void startInRelation(String qName, Attributes attributes) {
    if (qName.equals("member")) {
        long id = idVal(attributes.getValue("ref"));
        Element el;
        String type = attributes.getValue("type");
        if ("way".equals(type)) {
            el = saver.getWay(id);
        } else if ("node".equals(type)) {
            el = saver.getNode(id);
            if (el == null) {
                // we didn't make a node for this point earlier,
                // do it now (if it exists)
                Coord co = saver.getCoord(id);
                if (co != null) {
                    el = new Node(id, co);
                    saver.addNode((Node) el);
                }
            }
        } else if ("relation".equals(type)) {
            el = saver.getRelation(id);
            if (el == null) {
                saver.deferRelation(id, currentRelation, attributes.getValue("role"));
            }
        } else
            el = null;
        if (// ignore non existing ways caused by splitting files
        el != null)
            currentRelation.addElement(attributes.getValue("role"), el);
    } else if (qName.equals("tag")) {
        String key = attributes.getValue("k");
        String val = attributes.getValue("v");
        // the type tag is required for relations - all other tags are filtered
        if ("type".equals(key))
            // intern the key
            key = "type";
        else
            key = keepTag(key, val);
        if (key == null) {
            currentRelation.setTagsIncomplete(true);
        } else {
            currentRelation.addTagFromRawOSM(key, val);
        }
    }
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) Element(uk.me.parabola.mkgmap.reader.osm.Element) Node(uk.me.parabola.mkgmap.reader.osm.Node)

Example 79 with Element

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

the class AddAccessActionTest method testNoMatchingAlternatives.

/**
 * The add/set commands now support alternatives just like the name command
 * has always done.
 * Several alternatives, but none match.
 */
@Test
public void testNoMatchingAlternatives() {
    AddAccessAction act = new AddAccessAction("${notset}", false);
    act.add("${hello}");
    act.add("${world}");
    Element el = stdElement();
    act.perform(el);
    for (String accessTag : ACCESS_TAGS.keySet()) assertNull(accessTag + "a not set", el.getTag(accessTag));
}
Also used : Element(uk.me.parabola.mkgmap.reader.osm.Element) Test(org.junit.Test)

Example 80 with Element

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

the class AddAccessActionTest method stdElement.

private Element stdElement() {
    Element el1 = new Way(1);
    el1.addTag("access", ACCESSVAL);
    el1.addTag("bicycle", "yes");
    el1.addTag("foot", "private");
    el1.addTag("highway", "track");
    return el1;
}
Also used : Element(uk.me.parabola.mkgmap.reader.osm.Element) Way(uk.me.parabola.mkgmap.reader.osm.Way)

Aggregations

Element (uk.me.parabola.mkgmap.reader.osm.Element)94 Test (org.junit.Test)75 Way (uk.me.parabola.mkgmap.reader.osm.Way)48 GType (uk.me.parabola.mkgmap.reader.osm.GType)25 TestUtils.makeRuleSet (func.lib.TestUtils.makeRuleSet)23 Action (uk.me.parabola.mkgmap.osmstyle.actions.Action)15 Rule (uk.me.parabola.mkgmap.reader.osm.Rule)8 ArrayList (java.util.ArrayList)7 Node (uk.me.parabola.mkgmap.reader.osm.Node)7 Relation (uk.me.parabola.mkgmap.reader.osm.Relation)7 Coord (uk.me.parabola.imgfmt.app.Coord)5 StringStyleFileLoader (func.lib.StringStyleFileLoader)4 Map (java.util.Map)4 GeneralRelation (uk.me.parabola.mkgmap.reader.osm.GeneralRelation)4 TypeResult (uk.me.parabola.mkgmap.reader.osm.TypeResult)4 HashMap (java.util.HashMap)3 IdentityHashMap (java.util.IdentityHashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Area (uk.me.parabola.imgfmt.app.Area)2