Search in sources :

Example 6 with MapRoad

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

the class HousenumberGenerator method createHousenumberRoads.

private List<HousenumberRoad> createHousenumberRoads(MultiHashMap<MapRoad, HousenumberMatch> initialHousesForRoads) {
    List<HousenumberRoad> hnrList = new ArrayList<>();
    for (MapRoad road : allRoads) {
        if (road.isSkipHousenumberProcessing())
            continue;
        List<HousenumberMatch> houses = initialHousesForRoads.get(road);
        if (houses == null || houses.isEmpty())
            continue;
        CityInfo ci = getCityInfos(road.getCity(), road.getRegion(), road.getCountry());
        HousenumberRoad hnr = new HousenumberRoad(road, ci, houses);
        if (road.getZip() != null)
            hnr.setZipCodeInfo(getZipInfos(road.getZip()));
        hnrList.add(hnr);
    }
    return hnrList;
}
Also used : CityInfo(uk.me.parabola.mkgmap.general.CityInfo) LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) ArrayList(java.util.ArrayList) MapRoad(uk.me.parabola.mkgmap.general.MapRoad)

Example 7 with MapRoad

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

the class RoadHelper method makeRoad.

public MapRoad makeRoad(MapLine l) {
    assert roadId != 0;
    if (log.isDebugEnabled())
        log.debug("finishing road id " + roadId);
    MapRoad road = new MapRoad(roadId, roadId, l);
    // Set parameters.
    road.setRoadClass(roadClass);
    road.setSpeed(speed);
    if (oneway)
        road.setOneway();
    if (toll)
        road.setToll();
    road.setAccess(mkgmapAccess);
    if (numbers != null && !numbers.isEmpty()) {
        convertNodesForHouseNumbers(road);
        road.setNumbers(numbers);
    }
    List<Coord> points = road.getPoints();
    for (NodeIndex ni : nodes) {
        int n = ni.index;
        if (log.isDebugEnabled())
            log.debug("road has " + points.size() + " points");
        Coord coord = points.get(n);
        long id = coord.getId();
        if (id == 0) {
            CoordNode node = nodeCoords.get((long) ni.nodeId);
            if (node == null) {
                node = new CoordNode(coord, ni.nodeId, ni.boundary);
                nodeCoords.put((long) ni.nodeId, node);
            }
            points.set(n, node);
        } else if (id != ni.nodeId) {
            log.warn("Inconsistant node ids");
        }
    }
    return road;
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) CoordNode(uk.me.parabola.imgfmt.app.CoordNode) MapRoad(uk.me.parabola.mkgmap.general.MapRoad)

Example 8 with MapRoad

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

the class StyledConverterTest method makeConverter.

private StyledConverter makeConverter(String name) throws FileNotFoundException {
    Style style = new StyleImpl(LOC, name);
    MapCollector coll = new MapCollector() {

        public void addToBounds(Coord p) {
        }

        // could save points in the same way as lines to test them
        public void addPoint(MapPoint point) {
        }

        public void addLine(MapLine line) {
            // Save line so that it can be examined in the tests.
            assertNotNull("points are not null", line.getPoints());
            lines.add(line);
        }

        public void addShape(MapShape shape) {
        }

        public void addRoad(MapRoad road) {
            lines.add(road);
        }

        public int addRestriction(GeneralRouteRestriction grr) {
            return 0;
        }

        public void addThroughRoute(int junctionNodeId, long roadIdA, long roadIdB) {
        }
    };
    return new StyledConverter(style, coll, new EnhancedProperties());
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) EnhancedProperties(uk.me.parabola.util.EnhancedProperties) MapLine(uk.me.parabola.mkgmap.general.MapLine) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) GeneralRouteRestriction(uk.me.parabola.imgfmt.app.net.GeneralRouteRestriction) Style(uk.me.parabola.mkgmap.reader.osm.Style) MapRoad(uk.me.parabola.mkgmap.general.MapRoad) MapCollector(uk.me.parabola.mkgmap.general.MapCollector) MapShape(uk.me.parabola.mkgmap.general.MapShape)

Example 9 with MapRoad

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

the class MapArea method split.

/**
 * Split this area into several pieces. All the map elements are reallocated
 * to the appropriate subarea.  Usually this instance would now be thrown
 * away and the new sub areas used instead.
 * <p>
 * This code is dealing with a lot of factors that govern the splitting, eg:
 *  splitPolygonsIntoArea,
 *  tooSmallToDivide,
 *  item.minResolution vs. areaResolution,
 *  number/size of items and the limits of a subDivision,
 *  items that exceed maximum subDivision on their own,
 *  items that extend up to 50% outside the current area,
 *  items bigger than this.
 *
 * @param nx The number of pieces in the x (longitude) direction.
 * @param ny The number of pieces in the y direction.
 * @param bounds the bounding box that is used to create the areas.
 * @param tooSmallToDivide the area is small and data overflows; split into overflow areas
 *
 * @return An array of the new MapArea's or null if can't split.
 */
public MapArea[] split(int nx, int ny, Area bounds, boolean tooSmallToDivide) {
    int resolutionShift = MAX_RESOLUTION - areaResolution;
    Area[] areas = bounds.split(nx, ny, resolutionShift);
    if (areas == null) {
        // Failed to split!
        if (log.isDebugEnabled()) {
            // see what is here
            for (MapLine e : this.lines) if (e.getMinResolution() <= areaResolution)
                log.debug("line. locn=", e.getPoints().get(0).toOSMURL(), " type=", uk.me.parabola.mkgmap.reader.osm.GType.formatType(e.getType()), " name=", e.getName(), " min=", e.getMinResolution(), " max=", e.getMaxResolution());
            for (MapShape e : this.shapes) if (e.getMinResolution() <= areaResolution)
                log.debug("shape. locn=", e.getPoints().get(0).toOSMURL(), " type=", uk.me.parabola.mkgmap.reader.osm.GType.formatType(e.getType()), " name=", e.getName(), " min=", e.getMinResolution(), " max=", e.getMaxResolution(), " full=", e.getFullArea(), " calc=", uk.me.parabola.mkgmap.filters.ShapeMergeFilter.calcAreaSizeTestVal(e.getPoints()));
        // the main culprits are lots of bits of sea and coastline in an overview map (res 12)
        }
        return null;
    }
    MapArea[] mapAreas = new MapArea[nx * ny];
    log.info("Splitting area " + bounds + " into " + nx + "x" + ny + " pieces at resolution " + areaResolution, tooSmallToDivide);
    List<MapArea> addedAreas = new ArrayList<>();
    for (int i = 0; i < mapAreas.length; i++) {
        mapAreas[i] = new MapArea(areas[i], areaResolution, splitPolygonsIntoArea);
        if (log.isDebugEnabled())
            log.debug("area before", mapAreas[i].getBounds());
    }
    int xbaseHp = areas[0].getMinLong() << Coord.DELTA_SHIFT;
    int ybaseHp = areas[0].getMinLat() << Coord.DELTA_SHIFT;
    int dxHp = areas[0].getWidth() << Coord.DELTA_SHIFT;
    int dyHp = areas[0].getHeight() << Coord.DELTA_SHIFT;
    // Some of the work done by PolygonSubdivSizeSplitterFilter now done here
    final int maxSize = Math.min((1 << 24) - 1, Math.max(MapSplitter.MAX_DIVISION_SIZE << (MAX_RESOLUTION - areaResolution), 0x8000));
    /**
     * These constants control when an item (shape unless splitPolygonsIntoArea or line) is shifted into its own MapArea/SubDivision.
     * Generally, an item is allowed into the MapArea chosen by centre provided it is no bigger than the MapArea.
     * This means that there could be big items near the edges of the MapArea that stick out by almost half, so must
     * ensure that this doesn't cause the mapArea to exceed subDivision size limits.
     * When the MapArea get small, we don't want to shift lots if items into their own areas;
     * The *2 of LARGE_OBJECT_DIM is to keep to the same behaviour as earlier versions.
     */
    final int maxWidth = Math.max(Math.min(areas[0].getWidth(), maxSize / 2), LARGE_OBJECT_DIM * 2);
    final int maxHeight = Math.max(Math.min(areas[0].getHeight(), maxSize / 2), LARGE_OBJECT_DIM * 2);
    // and don't have a good tooSmallToDivide strategy when not splitPolygonsIntoArea.
    if (tooSmallToDivide) {
        distShapesIntoNewAreas(addedAreas, mapAreas[0]);
    } else {
        for (MapShape e : this.shapes) {
            Area shapeBounds = e.getBounds();
            if (splitPolygonsIntoArea || shapeBounds.getMaxDimension() > maxSize) {
                splitIntoAreas(mapAreas, e);
                continue;
            }
            int areaIndex = pickArea(mapAreas, e, xbaseHp, ybaseHp, nx, ny, dxHp, dyHp);
            if ((shapeBounds.getHeight() > maxHeight || shapeBounds.getWidth() > maxWidth) && !areas[areaIndex].contains(shapeBounds)) {
                // use splitIntoAreas to deal with overflow
                MapArea largeObjectArea = new MapArea(shapeBounds, areaResolution, true);
                largeObjectArea.addShape(e);
                addedAreas.add(largeObjectArea);
                continue;
            }
            mapAreas[areaIndex].addShape(e);
        }
    }
    if (tooSmallToDivide) {
        distPointsIntoNewAreas(addedAreas, mapAreas[0]);
    } else {
        for (MapPoint p : this.points) {
            int areaIndex = pickArea(mapAreas, p, xbaseHp, ybaseHp, nx, ny, dxHp, dyHp);
            mapAreas[areaIndex].addPoint(p);
        }
    }
    if (tooSmallToDivide) {
        distLinesIntoNewAreas(addedAreas, mapAreas[0]);
    } else {
        for (MapLine l : this.lines) {
            // Drop any zero sized lines.
            if (l instanceof MapRoad == false && l.getRect().height <= 0 && l.getRect().width <= 0)
                continue;
            Area lineBounds = l.getBounds();
            int areaIndex = pickArea(mapAreas, l, xbaseHp, ybaseHp, nx, ny, dxHp, dyHp);
            if ((lineBounds.getHeight() > maxHeight || lineBounds.getWidth() > maxWidth) && !areas[areaIndex].contains(lineBounds)) {
                MapArea largeObjectArea = new MapArea(lineBounds, areaResolution, false);
                largeObjectArea.addLine(l);
                addedAreas.add(largeObjectArea);
                continue;
            }
            mapAreas[areaIndex].addLine(l);
        }
    }
    if (!addedAreas.isEmpty()) {
        // combine list and array
        int pos = mapAreas.length;
        mapAreas = Arrays.copyOf(mapAreas, mapAreas.length + addedAreas.size());
        for (MapArea ma : addedAreas) {
            if (// distShapesIntoNewAreas etc didn't know how big it was going to be
            ma.getBounds() == null)
                // so set to bounds of all elements
                ma.setBounds(ma.getFullBounds());
            mapAreas[pos++] = ma;
        }
    }
    return mapAreas;
}
Also used : Area(uk.me.parabola.imgfmt.app.Area) MapLine(uk.me.parabola.mkgmap.general.MapLine) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) ArrayList(java.util.ArrayList) MapRoad(uk.me.parabola.mkgmap.general.MapRoad) MapShape(uk.me.parabola.mkgmap.general.MapShape) MapPoint(uk.me.parabola.mkgmap.general.MapPoint)

Example 10 with MapRoad

use of uk.me.parabola.mkgmap.general.MapRoad 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)

Aggregations

MapRoad (uk.me.parabola.mkgmap.general.MapRoad)16 ArrayList (java.util.ArrayList)11 Coord (uk.me.parabola.imgfmt.app.Coord)9 MapLine (uk.me.parabola.mkgmap.general.MapLine)6 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)5 LongArrayList (it.unimi.dsi.fastutil.longs.LongArrayList)4 MapShape (uk.me.parabola.mkgmap.general.MapShape)4 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 LinkedHashSet (java.util.LinkedHashSet)3 Numbers (uk.me.parabola.imgfmt.app.net.Numbers)3 CityInfo (uk.me.parabola.mkgmap.general.CityInfo)3 Int2IntOpenHashMap (it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap)2 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 CoordNode (uk.me.parabola.imgfmt.app.CoordNode)2 MapExitPoint (uk.me.parabola.mkgmap.general.MapExitPoint)2 MultiHashMap (uk.me.parabola.util.MultiHashMap)2