Search in sources :

Example 11 with MapLine

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

the class MapBuilder method normalizeCountries.

/**
 * Process the country names of all elements and normalize them
 * so that one consistent country name is used for the same country
 * instead of different spellings.
 * @param src the source of elements
 */
private void normalizeCountries(MapDataSource src) {
    for (MapPoint p : src.getPoints()) {
        String countryStr = p.getCountry();
        if (countryStr != null) {
            countryStr = locator.normalizeCountry(countryStr);
            p.setCountry(countryStr);
        }
    }
    for (MapLine l : src.getLines()) {
        String countryStr = l.getCountry();
        if (countryStr != null) {
            countryStr = locator.normalizeCountry(countryStr);
            l.setCountry(countryStr);
        }
    }
// shapes do not have address information
// untag the following lines if this is wrong
// for (MapShape s : src.getShapes()) {
// String countryStr = s.getCountry();
// if (countryStr != null) {
// countryStr = locator.normalizeCountry(countryStr);
// s.setCountry(countryStr);
// }
// }
}
Also used : MapLine(uk.me.parabola.mkgmap.general.MapLine) MapPoint(uk.me.parabola.mkgmap.general.MapPoint)

Example 12 with MapLine

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

the class MapBuilder method makeSubdivision.

/**
 * Make an individual subdivision for the map.  To do this we need a link
 * to its parent and the zoom level that we are working at.
 *
 * @param map	The map to add this subdivision into.
 * @param parent The parent division.
 * @param ma	 The area of the map that we are fitting into this division.
 * @param z	  The zoom level.
 * @return The new subdivsion.
 */
private Subdivision makeSubdivision(Map map, Subdivision parent, MapArea ma, Zoom z) {
    List<MapPoint> points = ma.getPoints();
    List<MapLine> lines = ma.getLines();
    List<MapShape> shapes = ma.getShapes();
    Subdivision div = map.createSubdivision(parent, ma.getFullBounds(), z);
    if (ma.hasPoints())
        div.setHasPoints(true);
    if (ma.hasIndPoints())
        div.setHasIndPoints(true);
    if (ma.hasLines())
        div.setHasPolylines(true);
    if (ma.hasShapes())
        div.setHasPolygons(true);
    div.startDivision();
    processPoints(map, div, points);
    processLines(map, div, lines);
    processShapes(map, div, shapes);
    div.endDivision();
    return div;
}
Also used : MapLine(uk.me.parabola.mkgmap.general.MapLine) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) Subdivision(uk.me.parabola.imgfmt.app.trergn.Subdivision) MapShape(uk.me.parabola.mkgmap.general.MapShape)

Example 13 with MapLine

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

the class MapBuilder method processLines.

/**
 * Step through the lines, filter, simplify if necessary, and create a map
 * line which is then added to the map.
 *
 * Note that the location and resolution of map elements is relative to the
 * subdivision that they occur in.
 *
 * @param map	The map to add points to.
 * @param div	The subdivision that the lines belong to.
 * @param lines The lines to be added.
 */
private void processLines(Map map, Subdivision div, List<MapLine> lines) {
    // Signal that we are beginning to draw the lines.
    div.startLines();
    int res = div.getResolution();
    FilterConfig config = new FilterConfig();
    config.setResolution(res);
    config.setLevel(div.getZoom().getLevel());
    config.setRoutable(doRoads);
    // Maybe more efficient if merging before creating subdivisions.
    if (mergeLines) {
        LineMergeFilter merger = new LineMergeFilter();
        lines = merger.merge(lines, res);
    }
    LayerFilterChain filters = new LayerFilterChain(config);
    if (enableLineCleanFilters && (res < 24)) {
        filters.addFilter(new RoundCoordsFilter());
        filters.addFilter(new SizeFilter(MIN_SIZE_LINE));
        if (reducePointError > 0)
            filters.addFilter(new DouglasPeuckerFilter(reducePointError));
    }
    filters.addFilter(new LineSplitterFilter());
    filters.addFilter(new RemoveEmpty());
    filters.addFilter(new RemoveObsoletePointsFilter());
    filters.addFilter(new LinePreparerFilter(div));
    filters.addFilter(new LineAddFilter(div, map, doRoads));
    for (MapLine line : lines) {
        if (line.getMinResolution() > res)
            continue;
        filters.startFilter(line);
    }
}
Also used : MapLine(uk.me.parabola.mkgmap.general.MapLine) DouglasPeuckerFilter(uk.me.parabola.mkgmap.filters.DouglasPeuckerFilter) SizeFilter(uk.me.parabola.mkgmap.filters.SizeFilter) LinePreparerFilter(uk.me.parabola.mkgmap.filters.LinePreparerFilter) LineMergeFilter(uk.me.parabola.mkgmap.filters.LineMergeFilter) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) MapExitPoint(uk.me.parabola.mkgmap.general.MapExitPoint) Point(uk.me.parabola.imgfmt.app.trergn.Point) RoundCoordsFilter(uk.me.parabola.mkgmap.filters.RoundCoordsFilter) RemoveEmpty(uk.me.parabola.mkgmap.filters.RemoveEmpty) RemoveObsoletePointsFilter(uk.me.parabola.mkgmap.filters.RemoveObsoletePointsFilter) FilterConfig(uk.me.parabola.mkgmap.filters.FilterConfig) LineSplitterFilter(uk.me.parabola.mkgmap.filters.LineSplitterFilter)

Example 14 with MapLine

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

the class MapBuilder method processRoads.

private void processRoads(Map map, MapDataSource src) {
    LBLFile lbl = map.getLblFile();
    MapPoint searchPoint = new MapPoint();
    for (MapLine line : src.getLines()) {
        if (line.isRoad()) {
            String cityName = line.getCity();
            String cityCountryName = line.getCountry();
            String cityRegionName = line.getRegion();
            String zipStr = line.getZip();
            if (cityName == null && locationAutofill.contains("nearest")) {
                // Get name of next city if untagged
                searchPoint.setLocation(line.getLocation());
                MapPoint nextCity = locator.findNextPoint(searchPoint);
                if (nextCity != null) {
                    cityName = nextCity.getCity();
                    // city/region/country fields should match to the found city
                    cityCountryName = nextCity.getCountry();
                    cityRegionName = nextCity.getRegion();
                    // use the zip code only if no zip code is known
                    if (zipStr == null)
                        zipStr = nextCity.getZip();
                }
            }
            MapRoad road = (MapRoad) line;
            road.resetImgData();
            City roadCity = calcCity(lbl, cityName, cityRegionName, cityCountryName);
            if (roadCity != null)
                road.addRoadCity(roadCity);
            if (zipStr != null) {
                road.addRoadZip(lbl.createZip(zipStr));
            }
            List<Numbers> numbers = road.getRoadDef().getNumbersList();
            if (numbers != null) {
                for (Numbers num : numbers) {
                    for (int i = 0; i < 2; i++) {
                        boolean left = (i == 0);
                        ZipCodeInfo zipInfo = num.getZipCodeInfo(left);
                        if (zipInfo != null && zipInfo.getZipCode() != null) {
                            Zip zip = zipInfo.getImgZip();
                            if (zipInfo.getImgZip() == null) {
                                zip = lbl.createZip(zipInfo.getZipCode());
                                zipInfo.setImgZip(zip);
                            }
                            if (zip != null)
                                road.addRoadZip(zip);
                        }
                        CityInfo cityInfo = num.getCityInfo(left);
                        if (cityInfo != null) {
                            City city = cityInfo.getImgCity();
                            if (city == null) {
                                city = calcCity(lbl, cityInfo.getCity(), cityInfo.getRegion(), cityInfo.getCountry());
                                cityInfo.setImgCity(city);
                            }
                            if (city != null)
                                road.addRoadCity(city);
                        }
                    }
                }
            }
        }
    }
}
Also used : Zip(uk.me.parabola.imgfmt.app.lbl.Zip) CityInfo(uk.me.parabola.mkgmap.general.CityInfo) MapLine(uk.me.parabola.mkgmap.general.MapLine) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) MapRoad(uk.me.parabola.mkgmap.general.MapRoad) City(uk.me.parabola.imgfmt.app.lbl.City) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) MapExitPoint(uk.me.parabola.mkgmap.general.MapExitPoint) Point(uk.me.parabola.imgfmt.app.trergn.Point) Numbers(uk.me.parabola.imgfmt.app.net.Numbers) ZipCodeInfo(uk.me.parabola.mkgmap.general.ZipCodeInfo) LBLFile(uk.me.parabola.imgfmt.app.lbl.LBLFile)

Example 15 with MapLine

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

the class RemoveObsoletePointsFilter 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;
    List<Coord> points = line.getPoints();
    int numPoints = points.size();
    if (numPoints <= 1) {
        return;
    }
    int requiredPoints = (line instanceof MapShape) ? 4 : 2;
    List<Coord> newPoints = new ArrayList<Coord>(numPoints);
    while (true) {
        boolean removedSpike = false;
        numPoints = points.size();
        Coord lastP = points.get(0);
        newPoints.add(lastP);
        for (int i = 1; i < numPoints; i++) {
            Coord newP = points.get(i);
            int last = newPoints.size() - 1;
            lastP = newPoints.get(last);
            if (lastP.equals(newP)) {
                // coordinates to the last point or is preserved
                if (checkPreserved && line.isRoad()) {
                    if (newP.preserved() == false)
                        continue;
                    else if (lastP.preserved() == false) {
                        // replace last
                        newPoints.set(last, newP);
                    }
                } else
                    continue;
            }
            if (newPoints.size() > 1) {
                switch(Utils.isStraight(newPoints.get(last - 1), lastP, newP)) {
                    case Utils.STRICTLY_STRAIGHT:
                        if (checkPreserved && lastP.preserved() && line.isRoad()) {
                        // keep it
                        } else {
                            log.debug("found three consecutive points on strictly straight line");
                            newPoints.set(last, newP);
                            continue;
                        }
                        break;
                    case Utils.STRAIGHT_SPIKE:
                        if (line instanceof MapShape) {
                            log.debug("removing spike");
                            newPoints.remove(last);
                            removedSpike = true;
                            if (newPoints.get(last - 1).equals(newP))
                                continue;
                        }
                        break;
                    default:
                        break;
                }
            }
            newPoints.add(newP);
        }
        if (!removedSpike || newPoints.size() < requiredPoints)
            break;
        points = newPoints;
        newPoints = new ArrayList<Coord>(points.size());
    }
    if (line instanceof MapShape) {
        // in a shape are identical.
        while (newPoints.size() > 3) {
            int nPoints = newPoints.size();
            switch(Utils.isStraight(newPoints.get(newPoints.size() - 2), newPoints.get(0), newPoints.get(1))) {
                case Utils.STRAIGHT_SPIKE:
                    newPoints.remove(0);
                    newPoints.set(newPoints.size() - 1, newPoints.get(0));
                    if (newPoints.get(newPoints.size() - 2).equals(newPoints.get(newPoints.size() - 1)))
                        newPoints.remove(newPoints.size() - 1);
                    break;
                case Utils.STRICTLY_STRAIGHT:
                    newPoints.remove(newPoints.size() - 1);
                    newPoints.set(0, newPoints.get(newPoints.size() - 1));
                    break;
            }
            if (nPoints == newPoints.size())
                break;
        }
    }
    if (newPoints.size() != line.getPoints().size()) {
        if (line instanceof MapShape && newPoints.size() <= 3 || newPoints.size() <= 1)
            return;
        MapLine newLine = line.copy();
        newLine.setPoints(newPoints);
        next.doFilter(newLine);
    } else {
        // no need to create new object
        next.doFilter(line);
    }
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) MapLine(uk.me.parabola.mkgmap.general.MapLine) ArrayList(java.util.ArrayList) MapShape(uk.me.parabola.mkgmap.general.MapShape)

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