Search in sources :

Example 11 with Node

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

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

the class HousenumberIvl method trySplitAt.

/**
 * Check if an address node can be used to calculate new intervals
 * @param houseToAdd a single address from OSM data
 * @return null in case of error or an array with two new {@link HousenumberIvl} instances
 */
public HousenumberIvl[] trySplitAt(HousenumberMatch houseToAdd) {
    if (houseToAdd.isInterpolated())
        return null;
    if (houseToAdd.getRoad() != knownHouses[0].getRoad() && houseToAdd.getRoad() != knownHouses[1].getRoad())
        return null;
    HousenumberMatch s = knownHouses[0];
    HousenumberMatch e = knownHouses[1];
    if (s.getSegment() > e.getSegment() || s.getSegment() == e.getSegment() && s.getSegmentFrac() > e.getSegmentFrac()) {
        s = knownHouses[1];
        e = knownHouses[0];
    }
    if (houseToAdd.getSegment() < s.getSegment() || houseToAdd.getSegment() > e.getSegment())
        return null;
    if (houseToAdd.getSegment() == s.getSegment() && houseToAdd.getSegmentFrac() < s.getSegmentFrac())
        return null;
    if (houseToAdd.getSegment() == e.getSegment() && houseToAdd.getSegmentFrac() > e.getSegmentFrac())
        return null;
    for (int i = 0; i + 1 < points.size(); i++) {
        Coord c1 = points.get(i);
        Coord c2 = points.get(i + 1);
        double frac = HousenumberGenerator.getFrac(c1, c2, houseToAdd.getLocation());
        if (frac < 0 || frac > 1)
            continue;
        HousenumberIvl[] ivls = new HousenumberIvl[2];
        HousenumberMatch hnm = null;
        if (houseToAdd.element instanceof Node) {
            hnm = houseToAdd;
        } else {
            // create a Node instance
            Node toAdd = new Node(houseToAdd.getElement().getId(), houseToAdd.getLocation());
            toAdd.setFakeId();
            toAdd.copyTags(houseToAdd.element);
            HousenumberElem hnElem = new HousenumberElem(toAdd, houseToAdd.getCityInfo());
            hnm = new HousenumberMatch(hnElem);
            hnm.setZipCode(houseToAdd.getZipCode());
            HousenumberGenerator.findClosestRoadSegment(hnm, houseToAdd.getRoad(), houseToAdd.getSegment(), houseToAdd.getSegment());
        }
        List<Coord> points1 = new ArrayList<>();
        List<Coord> points2 = new ArrayList<>();
        points1.addAll(points.subList(0, i + 1));
        points1.add(houseToAdd.getLocation());
        points2.add(houseToAdd.getLocation());
        points2.addAll(points.subList(i + 1, points.size()));
        ivls[0] = new HousenumberIvl(streetName, interpolationWay, n1, (Node) hnm.element);
        ivls[0].setStart(knownHouses[0].getHousenumber());
        ivls[0].setEnd(houseToAdd.getHousenumber());
        ivls[0].setStep(step);
        ivls[0].calcSteps();
        ivls[0].setPoints(points1);
        ivls[0].addHousenumberMatch(knownHouses[0]);
        ivls[0].addHousenumberMatch(hnm);
        ivls[1] = new HousenumberIvl(streetName, interpolationWay, (Node) hnm.element, n2);
        ivls[1].setStart(houseToAdd.getHousenumber());
        ivls[1].setEnd(knownHouses[1].getHousenumber());
        ivls[1].setStep(step);
        ivls[1].calcSteps();
        ivls[1].setPoints(points2);
        ivls[1].addHousenumberMatch(knownHouses[1]);
        ivls[1].addHousenumberMatch(hnm);
        return ivls;
    }
    return null;
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) Node(uk.me.parabola.mkgmap.reader.osm.Node) ArrayList(java.util.ArrayList)

Example 13 with Node

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

the class O5mBinHandler method readNode.

/**
 * read a node data set
 * @throws IOException
 */
private void readNode() throws IOException {
    lastNodeId += readSignedNum64();
    if (bytesToRead == 0)
        // only nodeId: this is a delete action, we ignore it
        return;
    readVersionTsAuthor();
    if (bytesToRead == 0)
        // only nodeId+version: this is a delete action, we ignore it
        return;
    int lon = readSignedNum32() + lastLon;
    lastLon = lon;
    int lat = readSignedNum32() + lastLat;
    lastLat = lat;
    double flon = (double) (100L * lon) * FACTOR;
    double flat = (double) (100L * lat) * FACTOR;
    assert flat >= -90.0 && flat <= 90.0;
    assert flon >= -180.0 && flon <= 180.0;
    Coord co = new Coord(flat, flon);
    saver.addPoint(lastNodeId, co);
    if (bytesToRead > 0) {
        Node node = new Node(lastNodeId, co);
        readTags(node);
        if (node.getTagCount() > 0) {
            // If there are tags, then we save a proper node for it.
            saver.addNode(node);
            hooks.onAddNode(node);
        }
    }
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) Node(uk.me.parabola.mkgmap.reader.osm.Node)

Example 14 with Node

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

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

the class OsmXmlHandler method startInNode.

/**
 * A new tag has been started while we are inside a node element.
 * @param qName The new tag name.
 * @param attributes Its attributes.
 */
private void startInNode(String qName, Attributes attributes) {
    if (qName.equals("tag")) {
        String key = attributes.getValue("k");
        String val = attributes.getValue("v");
        // We only want to create a full node for nodes that are POI's
        // and not just one point of a way.  Only create if it has tags that
        // could be used in a POI.
        key = keepTag(key, val);
        if (key != null) {
            if (currentNode == null) {
                Coord co = saver.getCoord(currentElementId);
                currentNode = new Node(currentElementId, co);
            }
            currentNode.addTagFromRawOSM(key, val);
        }
    }
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) Node(uk.me.parabola.mkgmap.reader.osm.Node)

Aggregations

Node (uk.me.parabola.mkgmap.reader.osm.Node)15 Coord (uk.me.parabola.imgfmt.app.Coord)13 Way (uk.me.parabola.mkgmap.reader.osm.Way)8 ArrayList (java.util.ArrayList)7 Element (uk.me.parabola.mkgmap.reader.osm.Element)7 Map (java.util.Map)5 HashMap (java.util.HashMap)4 List (java.util.List)4 CoordNode (uk.me.parabola.imgfmt.app.CoordNode)4 IdentityHashMap (java.util.IdentityHashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 MapExitPoint (uk.me.parabola.mkgmap.general.MapExitPoint)3 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)3 CoordPOI (uk.me.parabola.mkgmap.reader.osm.CoordPOI)3 MultiHashMap (uk.me.parabola.util.MultiHashMap)3 Area (uk.me.parabola.imgfmt.app.Area)2 Relation (uk.me.parabola.mkgmap.reader.osm.Relation)2 RestrictionRelation (uk.me.parabola.mkgmap.reader.osm.RestrictionRelation)2 Int2IntOpenHashMap (it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap)1 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)1