Search in sources :

Example 31 with Area

use of uk.me.parabola.imgfmt.app.Area in project mkgmap by openstreetmap.

the class MapSplitter method addAreasToList.

/**
 * Adds map areas to a list.  If an area has too many features, then it
 * is split into 2 and this routine is called recursively to add the new
 * areas.
 *
 * @param areas The areas to add to the list (and possibly split up).
 * @param alist The list that will finally contain the complete list of
 * map areas.
 */
private void addAreasToList(MapArea[] areas, List<MapArea> alist, int depth) {
    int shift = zoom.getShiftValue();
    for (MapArea area : areas) {
        if (!area.hasData())
            continue;
        Area bounds = area.getBounds();
        int[] sizes = area.getEstimatedSizes();
        if (log.isInfoEnabled()) {
            String padding = depth + "                                                                      ";
            log.info(padding.substring(0, (depth + 1) * 2) + bounds.getWidth() + "x" + bounds.getHeight() + ", points = " + area.getNumPoints() + "/" + sizes[MapArea.POINT_KIND] + ", lines = " + area.getNumLines() + "/" + sizes[MapArea.LINE_KIND] + ", shapes = " + area.getNumShapes() + "/" + sizes[MapArea.SHAPE_KIND]);
        }
        boolean wantSplit = false;
        boolean mustSplit = false;
        if (area.getNumLines() > MAX_NUM_LINES || area.getNumPoints() > MAX_NUM_POINTS || (sizes[MapArea.POINT_KIND] + sizes[MapArea.LINE_KIND] + sizes[MapArea.SHAPE_KIND]) > MAX_RGN_SIZE || sizes[MapArea.XT_POINT_KIND] > MAX_XT_POINTS_SIZE || sizes[MapArea.XT_LINE_KIND] > MAX_XT_LINES_SIZE || sizes[MapArea.XT_SHAPE_KIND] > MAX_XT_SHAPES_SIZE)
            mustSplit = true;
        else if (bounds.getMaxDimension() > (MIN_DIMENSION << shift)) {
            int sumSize = 0;
            for (int s : sizes) sumSize += s;
            if (sumSize > WANTED_MAX_AREA_SIZE) {
                // area has more bytes than wanted, and large enough to split
                log.debug("splitting area because data size is larger than wanted:", sumSize);
                wantSplit = true;
            }
        }
        if (wantSplit || mustSplit) {
            if (!area.canSplit()) {
                if (mustSplit)
                    log.error("Single item predicted to exceed subdivision", area.getBounds().getCenter().toOSMURL());
                else
                    log.info("Single item larger that WANTED_MAX_AREA_SIZE", area.getBounds().getCenter().toOSMURL());
            } else if (bounds.getMaxDimension() > (MIN_DIMENSION << shift)) {
                log.debug("splitting area in half", area, mustSplit, wantSplit);
                MapArea[] sublist;
                if (bounds.getWidth() > bounds.getHeight())
                    sublist = area.split(2, 1, bounds, false);
                else
                    sublist = area.split(1, 2, bounds, false);
                if (sublist == null)
                    log.error("SubDivision split failed at", area.getBounds().getCenter().toOSMURL());
                else {
                    addAreasToList(sublist, alist, depth + 1);
                    continue;
                }
            } else if (mustSplit) {
                // can't reduce size, so force more subdivisions
                log.debug("splitting area by contents", area);
                MapArea[] sublist = area.split(1, 1, bounds, true);
                addAreasToList(sublist, alist, depth + 1);
                continue;
            }
        }
        log.debug("adding area unsplit: has points", area.hasPoints());
        alist.add(area);
    }
}
Also used : Area(uk.me.parabola.imgfmt.app.Area)

Example 32 with Area

use of uk.me.parabola.imgfmt.app.Area in project mkgmap by openstreetmap.

the class OverviewBuilder method addMapCoverageArea.

/**
 * Add an area that shows the area covered by a detailed map.  This can
 * be an arbitary shape, although at the current time we only support
 * rectangles.
 *
 * @param finfo Information about a detail map.
 */
private void addMapCoverageArea(FileInfo finfo) {
    Area bounds = finfo.getBounds();
    List<Coord> points = bounds.toCoords();
    for (Coord co : points) {
        overviewSource.addToBounds(co);
    }
    // Create the tile coverage rectangle
    MapShape bg = new MapShape();
    bg.setType(0x4a);
    bg.setPoints(points);
    bg.setMinResolution(0);
    bg.setName(finfo.getDescription() + '\u001d' + finfo.getMapname());
    overviewSource.addShape(bg);
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) Area(uk.me.parabola.imgfmt.app.Area) MapShape(uk.me.parabola.mkgmap.general.MapShape)

Example 33 with Area

use of uk.me.parabola.imgfmt.app.Area in project mkgmap by openstreetmap.

the class PolygonSplitterBase method split.

/**
 * Split the given shape and place the resulting shapes in the outputs list.
 * @param shape The original shape (that is too big).
 * @param outputs The output list.
 */
protected void split(MapShape shape, List<MapShape> outputs) {
    int dividingLine = 0;
    boolean isLongitude = false;
    Area bounds = shape.getBounds();
    if (bounds.getWidth() > bounds.getHeight()) {
        isLongitude = true;
        Area[] tmpAreas = bounds.split(2, 1, shift);
        dividingLine = tmpAreas != null ? tmpAreas[0].getMaxLong() : (bounds.getMinLong() + bounds.getWidth() / 2);
    } else {
        Area[] tmpAreas = bounds.split(1, 2, shift);
        dividingLine = tmpAreas != null ? tmpAreas[0].getMaxLat() : (bounds.getMinLat() + bounds.getHeight() / 2);
    }
    List<List<Coord>> subShapePoints = new ArrayList<>();
    ShapeSplitter.splitShape(shape.getPoints(), dividingLine << Coord.DELTA_SHIFT, isLongitude, subShapePoints, subShapePoints, null);
    for (List<Coord> subShape : subShapePoints) {
        MapShape s = shape.copy();
        s.setPoints(subShape);
        outputs.add(s);
    }
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) Area(uk.me.parabola.imgfmt.app.Area) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) MapShape(uk.me.parabola.mkgmap.general.MapShape)

Example 34 with Area

use of uk.me.parabola.imgfmt.app.Area in project mkgmap by openstreetmap.

the class DebugWriter method writeOSM.

/**
 * Convert list of ways to osm file for debugging purposes.
 * @param bbox the bounding box for the osm file
 * @param outPath the directory
 * @param name the file name
 * @param convertedWays the list of ways
 */
public static void writeOSM(Area bbox, String outPath, String name, List<ConvertedWay> convertedWays) {
    if (outPath == null)
        return;
    File outDir = new File(outPath + "/.");
    if (outDir.getParentFile() != null) {
        outDir.getParentFile().mkdirs();
    }
    Map<String, byte[]> dummyMap = new HashMap<>();
    for (int pass = 1; pass <= 2; pass++) {
        IdentityHashMap<Coord, Integer> allPoints = new IdentityHashMap<>();
        uk.me.parabola.splitter.Area bounds = new uk.me.parabola.splitter.Area(bbox.getMinLat(), bbox.getMinLong(), bbox.getMaxLat(), bbox.getMaxLong());
        O5mMapWriter writer = new O5mMapWriter(bounds, outDir, 0, 0, dummyMap, dummyMap);
        writer.initForWrite();
        Integer nodeId;
        try {
            for (ConvertedWay cw : convertedWays) {
                if (cw == null)
                    continue;
                for (Coord p : cw.getPoints()) {
                    nodeId = allPoints.get(p);
                    if (nodeId == null) {
                        nodeId = allPoints.size();
                        allPoints.put(p, nodeId);
                        uk.me.parabola.splitter.Node nodeOut = new uk.me.parabola.splitter.Node();
                        if (pass == 1)
                            // high prec
                            nodeOut.set(nodeId + 1000000000L, p.getLatDegrees(), p.getLonDegrees());
                        else
                            nodeOut.set(nodeId + 1000000000L, Utils.toDegrees(p.getLatitude()), Utils.toDegrees(p.getLongitude()));
                        if (p instanceof CoordPOI) {
                            for (Map.Entry<String, String> tagEntry : ((CoordPOI) p).getNode().getTagEntryIterator()) {
                                nodeOut.addTag(tagEntry.getKey(), tagEntry.getValue());
                            }
                        }
                        writer.write(nodeOut);
                    }
                }
            }
            for (int w = 0; w < convertedWays.size(); w++) {
                ConvertedWay cw = convertedWays.get(w);
                if (cw == null)
                    continue;
                Way way = cw.getWay();
                uk.me.parabola.splitter.Way wayOut = new uk.me.parabola.splitter.Way();
                for (Coord p : way.getPoints()) {
                    nodeId = allPoints.get(p);
                    assert nodeId != null;
                    wayOut.addRef(nodeId + 1000000000L);
                }
                for (Map.Entry<String, String> tagEntry : way.getTagEntryIterator()) {
                    wayOut.addTag(tagEntry.getKey(), tagEntry.getValue());
                }
                wayOut.addTag("aaa-osm-id", Long.toString(way.getId()));
                wayOut.setId(w);
                writer.write(wayOut);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        writer.finishWrite();
        File f = new File(outDir.getAbsoluteFile(), "00000000.o5m");
        File ren = new File(outDir.getAbsoluteFile(), name + ((pass == 1) ? "_hp" : "_mu") + ".o5m");
        if (ren.exists())
            ren.delete();
        f.renameTo(ren);
    }
}
Also used : IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) IdentityHashMap(java.util.IdentityHashMap) Way(uk.me.parabola.mkgmap.reader.osm.Way) ConvertedWay(uk.me.parabola.mkgmap.osmstyle.ConvertedWay) ConvertedWay(uk.me.parabola.mkgmap.osmstyle.ConvertedWay) CoordPOI(uk.me.parabola.mkgmap.reader.osm.CoordPOI) IOException(java.io.IOException) Coord(uk.me.parabola.imgfmt.app.Coord) Area(uk.me.parabola.imgfmt.app.Area) O5mMapWriter(uk.me.parabola.splitter.O5mMapWriter) File(java.io.File) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 35 with Area

use of uk.me.parabola.imgfmt.app.Area in project mkgmap by openstreetmap.

the class LocationHook method end.

public void end() {
    long t1 = System.currentTimeMillis();
    log.info("Starting with location hook");
    Area nodesBounds = saver.getDataBoundingBox();
    if (nodesBounds != null) {
        Area bbox = saver.getBoundingBox();
        // calculate the needed bounding box
        Area searchBounds = bbox.intersect(nodesBounds);
        boundaryGrid = new BoundaryGrid(boundaryDirName, searchBounds, props);
        processLocationRelevantElements();
        boundaryGrid = null;
    }
    long dt = (System.currentTimeMillis() - t1);
    log.info("======= LocationHook Stats =====");
    log.info("QuadTree searches    :", cntQTSearch);
    log.info("unsuccesfull         :", cntNotFnd);
    log.info("unsuccesfull for ways:", cntwayNotFnd);
    log.info("Location hook finished in", dt, "ms");
}
Also used : Area(uk.me.parabola.imgfmt.app.Area) BoundaryGrid(uk.me.parabola.mkgmap.reader.osm.boundary.BoundaryGrid)

Aggregations

Area (uk.me.parabola.imgfmt.app.Area)49 Test (org.junit.Test)26 Coord (uk.me.parabola.imgfmt.app.Coord)14 ArrayList (java.util.ArrayList)9 List (java.util.List)7 MapShape (uk.me.parabola.mkgmap.general.MapShape)4 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)3 Way (uk.me.parabola.mkgmap.reader.osm.Way)3 Rectangle (java.awt.Rectangle)2 File (java.io.File)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ExitException (uk.me.parabola.imgfmt.ExitException)2 MapFailedException (uk.me.parabola.imgfmt.MapFailedException)2 Point (uk.me.parabola.imgfmt.app.trergn.Point)2 Zoom (uk.me.parabola.imgfmt.app.trergn.Zoom)2 Element (uk.me.parabola.mkgmap.reader.osm.Element)2 Node (uk.me.parabola.mkgmap.reader.osm.Node)2 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)1