Search in sources :

Example 26 with MapLine

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

the class LineSplitterFilter method doFilter.

/**
 * If the line is short enough then we just pass it on straight away.
 * Otherwise we cut it into pieces that are short enough and hand them
 * on.
 *
 * @param element A map element.
 * @param next This is used to pass the possibly transformed element onward.
 */
public void doFilter(MapElement element, MapFilterChain next) {
    // We do not deal with shapes.
    assert !(element instanceof MapShape) && element instanceof MapLine;
    MapLine line = (MapLine) element;
    List<Coord> points = line.getPoints();
    int npoints = points.size();
    if (npoints <= MAX_POINTS_IN_LINE) {
        next.doFilter(element);
        return;
    }
    log.debug("line has too many points, splitting");
    if (line.isRoad() && level == 0 && isRoutable && log.isDebugEnabled()) {
        log.debug("Way " + ((MapRoad) line).getRoadDef() + " has more than " + MAX_POINTS_IN_LINE + " points and is about to be split");
    }
    boolean last = false;
    int wantedSize = (npoints < 2 * MAX_POINTS_IN_LINE) ? npoints / 2 + 1 : MAX_POINTS_IN_LINE;
    int pos = 0;
    while (true) {
        if (pos == 0)
            log.debug("saving first part");
        else if (!last)
            log.debug("saving next part");
        else
            log.debug("saving final part");
        MapLine l = line.copy();
        l.setPoints(new ArrayList<>(points.subList(pos, pos + wantedSize)));
        if (wantedSize < MAX_POINTS_IN_LINE / 2)
            log.error("size?", npoints, pos, wantedSize);
        if (!last && line instanceof MapRoad)
            ((MapRoad) l).setSegmentsFollowing(true);
        next.doFilter(l);
        if (last)
            break;
        // we start with the last point of previous part
        pos += wantedSize - 1;
        int remaining = npoints - pos;
        // make sure that the last parts have enough points
        if (remaining <= MAX_POINTS_IN_LINE) {
            last = true;
            wantedSize = remaining;
        } else if (remaining < 2 * MAX_POINTS_IN_LINE)
            wantedSize = remaining / 2 + 1;
    }
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) MapLine(uk.me.parabola.mkgmap.general.MapLine) MapRoad(uk.me.parabola.mkgmap.general.MapRoad) MapShape(uk.me.parabola.mkgmap.general.MapShape)

Example 27 with MapLine

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

the class RoundCoordsFilter method doFilter.

/**
 * @param element A map element that will be a line or a polygon.
 * @param next This is used to pass the possibly transformed element onward.
 */
public void doFilter(MapElement element, MapFilterChain next) {
    MapLine line = (MapLine) element;
    // 0.5 shifted
    int half = 1 << (shift - 1);
    // to remove fraction bits
    int mask = ~((1 << shift) - 1);
    if (shift == 0) {
        // do nothing
        next.doFilter(line);
    } else {
        // round lat/lon values to nearest for shift
        List<Coord> newPoints = new ArrayList<Coord>(line.getPoints().size());
        Coord lastP = null;
        for (Coord p : line.getPoints()) {
            int lat = (p.getLatitude() + half) & mask;
            int lon = (p.getLongitude() + half) & mask;
            Coord newP;
            if (p instanceof CoordNode && checkRouting)
                newP = new CoordNode(lat, lon, p.getId(), p.getOnBoundary());
            else
                newP = new Coord(lat, lon);
            newP.preserved(p.preserved());
            // CoordNode and the last point wasn't a CoordNode
            if (lastP == null || !lastP.equals(newP) || (newP instanceof CoordNode && !(lastP instanceof CoordNode))) {
                newPoints.add(newP);
                lastP = newP;
            } else if (newP.preserved()) {
                // this point is not going to be used because it
                // has the same (rounded) coordinates as the last
                // node but it has been marked as being "preserved" -
                // transfer that property to the previous point so
                // that it's not lost
                lastP.preserved(true);
            }
        }
        if (newPoints.size() > 1) {
            MapLine newLine = line.copy();
            newLine.setPoints(newPoints);
            next.doFilter(newLine);
        }
    }
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) MapLine(uk.me.parabola.mkgmap.general.MapLine) ArrayList(java.util.ArrayList) CoordNode(uk.me.parabola.imgfmt.app.CoordNode)

Example 28 with MapLine

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

the class PolishMapDataSource method sectionStart.

/**
 * Record that we are starting a new section.
 * Section names are enclosed in square brackets.  Inside the section there
 * are a number of lines with the key=value format.
 *
 * @param line The raw line from the input file.
 */
private void sectionStart(String line) {
    String name = line.substring(1, line.length() - 1).trim();
    log.debug("section name", name);
    extraAttributes = null;
    if (name.equalsIgnoreCase("IMG ID")) {
        section = S_IMG_ID;
    } else if (name.equalsIgnoreCase("POI") || name.equals("RGN10") || name.equals("RGN20")) {
        point = new MapPoint();
        section = S_POINT;
    } else if (name.equalsIgnoreCase("POLYLINE") || name.equals("RGN40")) {
        polyline = new MapLine();
        roadHelper.clear();
        section = S_POLYLINE;
    } else if (name.equalsIgnoreCase("POLYGON") || name.equals("RGN80")) {
        shape = new MapShape();
        section = S_POLYGON;
    } else if (name.equalsIgnoreCase("Restrict")) {
        restriction = new PolishTurnRestriction();
        section = S_RESTRICTION;
    } else
        System.out.println("Ignoring unrecognised section: " + name);
}
Also used : MapLine(uk.me.parabola.mkgmap.general.MapLine) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) MapShape(uk.me.parabola.mkgmap.general.MapShape)

Example 29 with MapLine

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

the class TestPoints method drawTestMap.

/**
 * We draw points, lines and polygons separately.  They should be in
 * order from west to east of the generated map, starting in the bottom
 * left hand corner (SW).
 *
 * @param mapper Collector for the generated points etc.
 * @param startLat The S coord.
 * @param startLong The W coord.
 */
private void drawTestMap(MapCollector mapper, double startLat, double startLong) {
    String s = props.getProperty("npoints");
    int npoints = 10;
    if (s != null)
        npoints = Integer.valueOf(s);
    for (int x = 0; x < npoints; x++) {
        for (int y = 0; y < npoints; y++) {
            MapPoint point = new MapPoint();
            double baseLat = startLat + y * ELEMENT_SPACING;
            double baseLong = startLong + x * ELEMENT_SPACING;
            point.setMinResolution(24 - (x & 0x7));
            point.setName("P " + (x * npoints + y));
            point.setLocation(new Coord(baseLat, baseLong));
            point.setType((0x2c << 8) + (y & 0xf));
            mapper.addPoint(point);
            // XXX shouldn't be needed.
            mapper.addToBounds(point.getLocation());
        }
    }
    // some.
    for (int x = 0; x < npoints; x++) {
        for (int y = 0; y < npoints; y++) {
            int type = x * 16 + y;
            type &= 0xf;
            MapLine line = new MapLine();
            line.setMinResolution(10);
            line.setName("0x" + Integer.toHexString(type));
            double baseLat = startLat + y * ELEMENT_SPACING;
            double baseLong = startLong + x * ELEMENT_SPACING;
            List<Coord> coords = new ArrayList<Coord>();
            for (int i = 0; i < 5; i++) {
                Coord co = new Coord(baseLat + i * ELEMENT_SIZE, baseLong + i * ELEMENT_SIZE);
                coords.add(co);
                mapper.addToBounds(co);
            }
            line.setType(type);
            line.setPoints(coords);
            mapper.addLine(line);
        }
    }
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) MapLine(uk.me.parabola.mkgmap.general.MapLine) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) ArrayList(java.util.ArrayList) MapPoint(uk.me.parabola.mkgmap.general.MapPoint)

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