Search in sources :

Example 11 with MapPoint

use of uk.me.parabola.mkgmap.general.MapPoint 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 12 with MapPoint

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

the class OverviewBuilder method readPoints.

/**
 * Read the points from the .img file and add them to the overview map.
 * We read from the least detailed level (apart from the empty one).
 *
 * @param mapReader Map reader on the detailed .img file.
 */
private void readPoints(MapReader mapReader) {
    Area bounds = overviewSource.getBounds();
    Zoom[] levels = mapReader.getLevels();
    for (int l = 1; l < levels.length; l++) {
        int min = levels[l].getLevel();
        int res = levels[l].getResolution();
        List<Point> pointList = mapReader.pointsForLevel(min, MapReader.WITH_EXT_TYPE_DATA);
        for (Point point : pointList) {
            if (log.isDebugEnabled())
                log.debug("got point", point);
            if (bounds.contains(point.getLocation()) == false) {
                if (log.isDebugEnabled())
                    log.debug(point, "dropped, is outside of tile boundary");
                continue;
            }
            MapPoint mp = new MapPoint();
            mp.setType(point.getType());
            if (point.getLabel() != null) {
                mp.setName(point.getLabel().getText());
            }
            mp.setMaxResolution(res);
            mp.setMinResolution(res);
            mp.setLocation(point.getLocation());
            overviewSource.addPoint(mp);
        }
    }
}
Also used : Area(uk.me.parabola.imgfmt.app.Area) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) Zoom(uk.me.parabola.imgfmt.app.trergn.Zoom) Point(uk.me.parabola.imgfmt.app.trergn.Point) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) Point(uk.me.parabola.imgfmt.app.trergn.Point) MapPoint(uk.me.parabola.mkgmap.general.MapPoint)

Example 13 with MapPoint

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

the class StyledConverter method checkDuplicatePOI.

/**
 * Check if we already have added a point with the same type + name and equal location.
 * @param mp
 * @return
 */
private boolean checkDuplicatePOI(MapPoint mp) {
    Map<String, MapPoint> typeMap = pointMap.get(mp.getType());
    if (typeMap == null) {
        typeMap = new HashMap<>();
        pointMap.put(mp.getType(), typeMap);
    }
    MapPoint old = typeMap.get(mp.getName());
    if (old == null) {
        typeMap.put(mp.getName(), mp);
    } else {
        if (old.getLocation().equals(mp.getLocation()))
            return true;
    }
    return false;
}
Also used : MapPoint(uk.me.parabola.mkgmap.general.MapPoint)

Example 14 with MapPoint

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

the class Locator method findNearbyCityByName.

public MapPoint findNearbyCityByName(MapPoint p) {
    if (p.getCity() == null)
        return null;
    Collection<MapPoint> nextCityList = cityMap.get(p.getCity());
    if (nextCityList.isEmpty()) {
        return null;
    }
    MapPoint near = null;
    double minDist = Double.MAX_VALUE;
    for (MapPoint nextCity : nextCityList) {
        double dist = p.getLocation().distance(nextCity.getLocation());
        if (dist < minDist) {
            minDist = dist;
            near = nextCity;
        }
    }
    if (// Wrong hit more the 30 km away ?
    minDist <= MAX_CITY_DIST)
        return near;
    else
        return null;
}
Also used : MapPoint(uk.me.parabola.mkgmap.general.MapPoint)

Example 15 with MapPoint

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

the class MapArea method addSize.

/**
 * Add an estimate of the size that will be required to hold this element
 * if it should be displayed at the given resolution.  We also keep track
 * of the number of <i>active</i> elements here ie elements that will be
 * shown because they are at a resolution at least as great as the resolution
 * of the area.
 *
 * @param el The element containing the minimum resolution that it will be
 * displayed at.
 * @param kind What kind of element this is KIND_POINT etc.
 */
private void addSize(MapElement el, int kind) {
    int res = el.getMinResolution();
    if (res > areaResolution || res > MAX_RESOLUTION)
        return;
    ++splittableCount;
    int numPoints;
    int numElements;
    switch(kind) {
        case POINT_KIND:
        case XT_POINT_KIND:
            // Points are predictably less than 10 bytes.
            sizes[kind] += 9;
            if (!el.hasExtendedType()) {
                if (((MapPoint) el).isCity())
                    nActiveIndPoints++;
                else
                    nActivePoints++;
            }
            break;
        case LINE_KIND:
        case XT_LINE_KIND:
            // Estimate the size taken by lines and shapes as a constant plus
            // a factor based on the number of points.
            numPoints = PredictFilterPoints.predictedMaxNumPoints(((MapLine) el).getPoints(), areaResolution, // assume MapBuilder.doRoads is true. subDiv.getZoom().getLevel() == 0 is maximum resolution
            ((MapLine) el).isRoad() && areaResolution == MAX_RESOLUTION);
            if (numPoints <= 1 && !((MapLine) el).isRoad())
                return;
            numElements = 1 + ((numPoints - 1) / LineSplitterFilter.MAX_POINTS_IN_LINE);
            // very pessimistic, typically less than 2 bytes are needed for one point
            sizes[kind] += numElements * 11 + numPoints * 4;
            if (!el.hasExtendedType())
                nActiveLines += numElements;
            break;
        case SHAPE_KIND:
        case XT_SHAPE_KIND:
            // see canSplit() above
            ++splittableCount;
            // Estimate the size taken by lines and shapes as a constant plus
            // a factor based on the number of points.
            numPoints = PredictFilterPoints.predictedMaxNumPoints(((MapShape) el).getPoints(), areaResolution, false);
            if (numPoints <= 3)
                return;
            numElements = 1 + ((numPoints - 1) / PolygonSplitterFilter.MAX_POINT_IN_ELEMENT);
            // very pessimistic, typically less than 2 bytes are needed for one point
            sizes[kind] += numElements * 11 + numPoints * 4;
            if (!el.hasExtendedType())
                nActiveShapes += numElements;
            break;
        default:
            log.error("should not be here");
            assert false;
            break;
    }
}
Also used : MapLine(uk.me.parabola.mkgmap.general.MapLine) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) MapShape(uk.me.parabola.mkgmap.general.MapShape) MapPoint(uk.me.parabola.mkgmap.general.MapPoint)

Aggregations

MapPoint (uk.me.parabola.mkgmap.general.MapPoint)20 MapLine (uk.me.parabola.mkgmap.general.MapLine)8 Coord (uk.me.parabola.imgfmt.app.Coord)5 MapShape (uk.me.parabola.mkgmap.general.MapShape)5 LBLFile (uk.me.parabola.imgfmt.app.lbl.LBLFile)4 City (uk.me.parabola.imgfmt.app.lbl.City)3 Point (uk.me.parabola.imgfmt.app.trergn.Point)3 MapExitPoint (uk.me.parabola.mkgmap.general.MapExitPoint)3 MapRoad (uk.me.parabola.mkgmap.general.MapRoad)3 ArrayList (java.util.ArrayList)2 Area (uk.me.parabola.imgfmt.app.Area)2 POIRecord (uk.me.parabola.imgfmt.app.lbl.POIRecord)2 Zip (uk.me.parabola.imgfmt.app.lbl.Zip)2 Test (org.junit.Test)1 Exit (uk.me.parabola.imgfmt.app.Exit)1 Label (uk.me.parabola.imgfmt.app.Label)1 Country (uk.me.parabola.imgfmt.app.lbl.Country)1 Region (uk.me.parabola.imgfmt.app.lbl.Region)1 GeneralRouteRestriction (uk.me.parabola.imgfmt.app.net.GeneralRouteRestriction)1 Numbers (uk.me.parabola.imgfmt.app.net.Numbers)1