Search in sources :

Example 1 with MapLine

use of uk.me.parabola.mkgmap.general.MapLine in project mkgmap by openstreetmap.

the class StyledConverter method elementSetup.

private static void elementSetup(MapElement ms, GType gt, Element element) {
    String[] labels = new String[4];
    int noLabels = 0;
    for (int labelNo = 0; labelNo < 4; labelNo++) {
        String label1 = element.getTag(labelTagKeys[labelNo]);
        String label = Label.squashSpaces(label1);
        if (label != null) {
            labels[noLabels] = label;
            noLabels++;
        }
    }
    if (labels[0] != null) {
        ms.setLabels(labels);
    }
    ms.setType(gt.getType());
    ms.setMinResolution(gt.getMinResolution());
    ms.setMaxResolution(gt.getMaxResolution());
    if (element.tagIsLikeYes(highResOnlyTagKey)) {
        ms.setMinResolution(ms.getMaxResolution());
    }
    if (ms instanceof MapLine && element.tagIsLikeYes(skipSizeFilterTagKey)) {
        ((MapLine) ms).setSkipSizeFilter(true);
    }
    // Now try to get some address info for POIs
    String country = element.getTag(countryTagKey);
    String region = element.getTag(regionTagKey);
    String city = element.getTag(cityTagKey);
    String zip = element.getTag(postal_codeTagKey);
    String street = element.getTag(streetTagKey);
    String houseNumber = element.getTag(housenumberTagKey);
    String phone = element.getTag(phoneTagKey);
    String isIn = element.getTag(is_inTagKey);
    if (country != null)
        ms.setCountry(country);
    if (region != null)
        ms.setRegion(region);
    if (city != null)
        ms.setCity(city);
    if (zip != null)
        ms.setZip(zip);
    if (street != null)
        ms.setStreet(street);
    if (houseNumber != null)
        ms.setHouseNumber(houseNumber);
    if (isIn != null)
        ms.setIsIn(isIn);
    if (phone != null)
        ms.setPhone(phone);
    if (MapObject.hasExtendedType(gt.getType())) {
        // pass attributes with mkgmap:xt- prefix (strip prefix)
        Map<String, String> xta = element.getTagsWithPrefix("mkgmap:xt-", true);
        // also pass all attributes with seamark: prefix (no strip prefix)
        xta.putAll(element.getTagsWithPrefix("seamark:", false));
        ms.setExtTypeAttributes(new ExtTypeAttributes(xta, "OSM id " + element.getId()));
    }
}
Also used : MapLine(uk.me.parabola.mkgmap.general.MapLine) ExtTypeAttributes(uk.me.parabola.imgfmt.app.trergn.ExtTypeAttributes) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) MapExitPoint(uk.me.parabola.mkgmap.general.MapExitPoint)

Example 2 with MapLine

use of uk.me.parabola.mkgmap.general.MapLine in project mkgmap by openstreetmap.

the class StyledConverter method addLine.

private void addLine(Way way, GType gt, int replType, List<Coord> points) {
    MapLine line = new MapLine();
    elementSetup(line, gt, way);
    if (replType >= 0)
        line.setType(replType);
    line.setPoints(points);
    if (way.tagIsLikeYes(onewayTagKey))
        line.setDirection(true);
    clipper.clipLine(line, lineAdder);
}
Also used : MapLine(uk.me.parabola.mkgmap.general.MapLine)

Example 3 with MapLine

use of uk.me.parabola.mkgmap.general.MapLine in project mkgmap by openstreetmap.

the class StyledConverter method addRoadWithoutLoops.

private void addRoadWithoutLoops(ConvertedWay cw) {
    Way way = cw.getWay();
    List<Integer> nodeIndices = new ArrayList<>();
    List<Coord> points = way.getPoints();
    if (points.size() < 2) {
        log.warn("road has < 2 points", way.getId(), "(discarding)");
        return;
    }
    Way trailingWay = null;
    String debugWayName = way.getDebugName();
    // collect the Way's nodes and also split the way if any
    // inter-node arc length becomes excessive
    double arcLength = 0;
    // detect if it would be split by the LineSizeSplitterFilter
    class WayBBox {

        int minLat = Integer.MAX_VALUE;

        int maxLat = Integer.MIN_VALUE;

        int minLon = Integer.MAX_VALUE;

        int maxLon = Integer.MIN_VALUE;

        void addPoint(Coord co) {
            int lat = co.getLatitude();
            if (lat < minLat)
                minLat = lat;
            if (lat > maxLat)
                maxLat = lat;
            int lon = co.getLongitude();
            if (lon < minLon)
                minLon = lon;
            if (lon > maxLon)
                maxLon = lon;
        }

        boolean tooBig() {
            return LineSizeSplitterFilter.testDims(maxLat - minLat, maxLon - minLon) >= 1.0;
        }
    }
    WayBBox wayBBox = new WayBBox();
    for (int i = 0; i < points.size(); ++i) {
        Coord p = points.get(i);
        wayBBox.addPoint(p);
        // the arc length between nodes
        if ((i + 1) < points.size()) {
            Coord nextP = points.get(i + 1);
            double d = p.distance(nextP);
            for (; ; ) {
                int dlat = Math.abs(nextP.getLatitude() - p.getLatitude());
                int dlon = Math.abs(nextP.getLongitude() - p.getLongitude());
                if (d > MAX_ARC_LENGTH || Math.max(dlat, dlon) >= LineSizeSplitterFilter.MAX_SIZE) {
                    double frac = Math.min(0.5, 0.95 * (MAX_ARC_LENGTH / d));
                    nextP = p.makeBetweenPoint(nextP, frac);
                    nextP.incHighwayCount();
                    points.add(i + 1, nextP);
                    double newD = p.distance(nextP);
                    if (log.isInfoEnabled())
                        log.info("Way", debugWayName, "contains a segment that is", (int) d + "m long but I am adding a new point to reduce its length to", (int) newD + "m");
                    d = newD;
                } else
                    break;
            }
            wayBBox.addPoint(nextP);
            if ((arcLength + d) > MAX_ARC_LENGTH) {
                if (i <= 0)
                    log.error("internal error: long arc segment was not split", debugWayName);
                assert i > 0 : "long arc segment was not split";
                assert trailingWay == null : "trailingWay not null #1";
                trailingWay = splitWayAt(way, i);
                // points so the loop will now terminate
                if (log.isInfoEnabled())
                    log.info("Splitting way", debugWayName, "at", points.get(i).toOSMURL(), "to limit arc length to", (long) arcLength + "m");
            } else if (wayBBox.tooBig()) {
                if (i <= 0)
                    log.error("internal error: arc segment with big bbox not split", debugWayName);
                assert i > 0 : "arc segment with big bbox not split";
                assert trailingWay == null : "trailingWay not null #2";
                trailingWay = splitWayAt(way, i);
                // points so the loop will now terminate
                if (log.isInfoEnabled())
                    log.info("Splitting way", debugWayName, "at", points.get(i).toOSMURL(), "to limit the size of its bounding box");
            } else {
                if (p.getHighwayCount() > 1) {
                    // point is a node so zero arc length
                    arcLength = 0;
                }
                arcLength += d;
            }
        }
        if (p.getHighwayCount() > 1) {
            // this point is a node connecting highways
            CoordNode coordNode = nodeIdMap.get(p);
            if (coordNode == null) {
                // assign a node id
                coordNode = new CoordNode(p, nextNodeId++, p.getOnBoundary());
                nodeIdMap.put(p, coordNode);
            }
            if (p instanceof CoordPOI) {
                // check if this poi should be converted to a route restriction
                CoordPOI cp = (CoordPOI) p;
                if (cp.getConvertToViaInRouteRestriction()) {
                    String wayPOI = way.getTag(WAY_POI_NODE_IDS);
                    if (wayPOI != null && wayPOI.contains("[" + cp.getNode().getId() + "]")) {
                        byte nodeAccess = AccessTagsAndBits.evalAccessTags(cp.getNode());
                        if (nodeAccess != cw.getAccess()) {
                            List<Way> wayList = poiRestrictions.get(cp.getNode());
                            if (wayList == null) {
                                wayList = new ArrayList<>();
                                poiRestrictions.put(cp.getNode(), wayList);
                            }
                            wayList.add(way);
                        }
                    }
                }
            }
            // add this index to node Indexes (should not already be there)
            assert !nodeIndices.contains(i) : debugWayName + " has multiple nodes for point " + i + " new node is " + p.toOSMURL();
            nodeIndices.add(i);
            if ((i + 1) < points.size() && nodeIndices.size() == MAX_NODES_IN_WAY) {
                // limit
                assert trailingWay == null : "trailingWay not null #7";
                trailingWay = splitWayAt(way, i);
                // points so the loop will now terminate
                if (log.isInfoEnabled())
                    log.info("Splitting way", debugWayName, "at", points.get(i).toOSMURL(), "as it has at least", MAX_NODES_IN_WAY, "nodes");
            }
        }
    }
    MapLine line = new MapLine();
    elementSetup(line, cw.getGType(), way);
    line.setPoints(points);
    MapRoad road = new MapRoad(nextRoadId++, way.getId(), line);
    if (routable == false)
        road.skipAddToNOD(true);
    boolean doFlareCheck = true;
    if (cw.isRoundabout()) {
        road.setRoundabout(true);
        doFlareCheck = false;
    }
    if (way.tagIsLikeYes("mkgmap:synthesised")) {
        road.setSynthesised(true);
        doFlareCheck = false;
    }
    if (way.tagIsLikeNo("mkgmap:flare-check")) {
        doFlareCheck = false;
    } else if (way.tagIsLikeYes("mkgmap:flare-check")) {
        doFlareCheck = true;
    }
    road.doFlareCheck(doFlareCheck);
    // set road parameters
    // copy road class and road speed
    road.setRoadClass(cw.getRoadClass());
    road.setSpeed(cw.getRoadSpeed());
    if (cw.isOneway()) {
        road.setDirection(true);
        road.setOneway();
    }
    road.setAccess(cw.getAccess());
    // does the road have a carpool lane?
    if (cw.isCarpool())
        road.setCarpoolLane();
    if (cw.isThroughroute() == false)
        road.setNoThroughRouting();
    if (cw.isToll())
        road.setToll();
    // by default, ways are paved
    if (cw.isUnpaved())
        road.paved(false);
    // by default, way's are not ferry routes
    if (cw.isFerry())
        road.ferry(true);
    int numNodes = nodeIndices.size();
    if (way.isViaWay() && numNodes > 2) {
        List<RestrictionRelation> rrList = wayRelMap.get(way.getId());
        for (RestrictionRelation rr : rrList) {
            rr.updateViaWay(way, nodeIndices);
        }
    }
    if (numNodes > 0) {
        // replace Coords that are nodes with CoordNodes
        for (int i = 0; i < numNodes; ++i) {
            int n = nodeIndices.get(i);
            Coord coord = points.get(n);
            CoordNode thisCoordNode = nodeIdMap.get(coord);
            assert thisCoordNode != null : "Way " + debugWayName + " node " + i + " (point index " + n + ") at " + coord.toOSMURL() + " yields a null coord node";
            boolean boundary = coord.getOnBoundary();
            if (boundary && log.isInfoEnabled()) {
                log.info("Way", debugWayName + "'s point #" + n, "at", coord.toOSMURL(), "is a boundary node");
            }
            points.set(n, thisCoordNode);
        }
    }
    if (roadLog.isInfoEnabled()) {
        // shift the bits so that they have the correct position
        int cmpAccess = (road.getRoadDef().getTabAAccess() & 0xff) + ((road.getRoadDef().getTabAAccess() & 0xc000) >> 6);
        if (road.isDirection()) {
            cmpAccess |= 1 << 10;
        }
        String access = String.format("%11s", Integer.toBinaryString(cmpAccess)).replace(' ', '0');
        roadLog.info(String.format("%19d 0x%-2x %11s %6d %6d %6d %s", way.getId(), road.getType(), access, road.getRoadDef().getRoadClass(), road.getRoadDef().getRoadSpeed(), road.getPoints().size(), Arrays.toString(road.getLabels())));
    }
    // add the road to the housenumber generator
    // it will add the road later on to the lineAdder
    housenumberGenerator.addRoad(way, road);
    if (trailingWay != null)
        addRoadWithoutLoops(new ConvertedWay(cw, trailingWay));
}
Also used : MapLine(uk.me.parabola.mkgmap.general.MapLine) ArrayList(java.util.ArrayList) MapRoad(uk.me.parabola.mkgmap.general.MapRoad) Way(uk.me.parabola.mkgmap.reader.osm.Way) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) MapExitPoint(uk.me.parabola.mkgmap.general.MapExitPoint) Coord(uk.me.parabola.imgfmt.app.Coord) RestrictionRelation(uk.me.parabola.mkgmap.reader.osm.RestrictionRelation) CoordPOI(uk.me.parabola.mkgmap.reader.osm.CoordPOI) CoordNode(uk.me.parabola.imgfmt.app.CoordNode)

Example 4 with MapLine

use of uk.me.parabola.mkgmap.general.MapLine in project mkgmap by openstreetmap.

the class OverlayReader method addLine.

public void addLine(MapLine line, LineAdder adder) {
    int origType = line.getType();
    List<Integer> integerList = overlays.get(origType);
    if (integerList != null) {
        MapLine newline = line.copy();
        newline.setType(integerList.get(0));
        List<Coord> points = line.getPoints();
        newline.setPoints(points);
        adder.add(newline);
        // Force all following types to be added as lines rather than roads.
        for (ListIterator<Integer> t = integerList.listIterator(1); t.hasNext(); ) {
            newline = new MapLine(line);
            newline.setType(t.next());
            newline.setPoints(new ArrayList<Coord>(points));
            adder.add(newline);
        }
    } else {
        adder.add(line);
    }
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) MapLine(uk.me.parabola.mkgmap.general.MapLine)

Example 5 with MapLine

use of uk.me.parabola.mkgmap.general.MapLine in project mkgmap by openstreetmap.

the class MapperBasedMapDataSource method addBoundaryLine.

public void addBoundaryLine(Area area, int type, String name) {
    List<Coord> coords = new ArrayList<Coord>();
    coords.add(new Coord(area.getMinLat(), area.getMinLong()));
    coords.add(new Coord(area.getMinLat(), area.getMaxLong()));
    coords.add(new Coord(area.getMaxLat(), area.getMaxLong()));
    coords.add(new Coord(area.getMaxLat(), area.getMinLong()));
    coords.add(new Coord(area.getMinLat() + 1, area.getMinLong()));
    MapLine boundary = new MapLine();
    boundary.setType(type);
    if (name != null)
        boundary.setName(name);
    // On all levels
    boundary.setMinResolution(0);
    boundary.setPoints(coords);
    mapper.addLine(boundary);
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) MapLine(uk.me.parabola.mkgmap.general.MapLine) ArrayList(java.util.ArrayList)

Aggregations

MapLine (uk.me.parabola.mkgmap.general.MapLine)29 Coord (uk.me.parabola.imgfmt.app.Coord)16 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)15 ArrayList (java.util.ArrayList)12 MapShape (uk.me.parabola.mkgmap.general.MapShape)10 MapRoad (uk.me.parabola.mkgmap.general.MapRoad)6 MapExitPoint (uk.me.parabola.mkgmap.general.MapExitPoint)4 Point (uk.me.parabola.imgfmt.app.trergn.Point)3 CoordNode (uk.me.parabola.imgfmt.app.CoordNode)2 FilterConfig (uk.me.parabola.mkgmap.filters.FilterConfig)2 Area (uk.me.parabola.imgfmt.app.Area)1 City (uk.me.parabola.imgfmt.app.lbl.City)1 LBLFile (uk.me.parabola.imgfmt.app.lbl.LBLFile)1 Zip (uk.me.parabola.imgfmt.app.lbl.Zip)1 GeneralRouteRestriction (uk.me.parabola.imgfmt.app.net.GeneralRouteRestriction)1 Numbers (uk.me.parabola.imgfmt.app.net.Numbers)1 ExtTypeAttributes (uk.me.parabola.imgfmt.app.trergn.ExtTypeAttributes)1 Polyline (uk.me.parabola.imgfmt.app.trergn.Polyline)1 Subdivision (uk.me.parabola.imgfmt.app.trergn.Subdivision)1 Zoom (uk.me.parabola.imgfmt.app.trergn.Zoom)1