Search in sources :

Example 1 with OverviewMapDataSource

use of uk.me.parabola.mkgmap.reader.overview.OverviewMapDataSource in project mkgmap by openstreetmap.

the class MapBuilder method makeMap.

/**
 * Main method to create the map, just calls out to several routines
 * that do the work.
 *
 * @param map The map.
 * @param src The map data.
 */
public void makeMap(Map map, LoadableMapDataSource src) {
    RGNFile rgnFile = map.getRgnFile();
    TREFile treFile = map.getTreFile();
    lblFile = map.getLblFile();
    NETFile netFile = map.getNetFile();
    DEMFile demFile = map.getDemFile();
    if (routeCenterBoundaryType != 0 && netFile != null && src instanceof MapperBasedMapDataSource) {
        for (RouteCenter rc : src.getRoadNetwork().getCenters()) {
            ((MapperBasedMapDataSource) src).addBoundaryLine(rc.getArea(), routeCenterBoundaryType, rc.reportSizes());
        }
    }
    if (mapInfo.isEmpty())
        getMapInfo();
    normalizeCountries(src);
    processCities(map, src);
    processRoads(map, src);
    processPOIs(map, src);
    processOverviews(map, src);
    processInfo(map, src);
    makeMapAreas(map, src);
    if (driveOnLeft == null) {
        // check if source gives info about driving side
        if (src instanceof MapperBasedMapDataSource) {
            driveOnLeft = ((MapperBasedMapDataSource) src).getDriveOnLeft();
        }
    }
    if (driveOnLeft == null)
        driveOnLeft = false;
    treFile.setDriveOnLeft(driveOnLeft);
    treFile.setLastRgnPos(rgnFile.position() - RGNHeader.HEADER_LEN);
    rgnFile.write();
    treFile.write(rgnFile.haveExtendedTypes());
    lblFile.write();
    lblFile.writePost();
    if (netFile != null) {
        RoadNetwork network = src.getRoadNetwork();
        netFile.setNetwork(network.getRoadDefs());
        NODFile nodFile = map.getNodFile();
        if (nodFile != null) {
            nodFile.setNetwork(network.getCenters(), network.getRoadDefs(), network.getBoundary());
            nodFile.setDriveOnLeft(driveOnLeft);
            nodFile.write();
        }
        netFile.write(lblFile.numCities(), lblFile.numZips());
        if (nodFile != null) {
            nodFile.writePost();
        }
        netFile.writePost(rgnFile.getWriter());
    }
    warnAbout3ByteImgRefs();
    if (demFile != null) {
        try {
            long t1 = System.currentTimeMillis();
            java.awt.geom.Area demArea = null;
            if (demPolygon != null) {
                Area bbox = src.getBounds();
                // the rectangle is a bit larger to avoid problems at tile boundaries
                Rectangle2D r = new Rectangle2D.Double(bbox.getMinLong() - 2, bbox.getMinLat() - 2, bbox.getWidth() + 4, bbox.getHeight() + 4);
                if (demPolygon.intersects(r) && !demPolygon.contains(r)) {
                    demArea = demPolygon;
                }
            }
            if (demArea == null && src instanceof OverviewMapDataSource) {
                Path2D demPoly = ((OverviewMapDataSource) src).getTileAreaPath();
                if (demPoly != null) {
                    demArea = new java.awt.geom.Area(demPoly);
                }
            }
            Area treArea = demFile.calc(src.getBounds(), demArea, pathToHGT, demDists, demOutsidePolygonHeight, demInterpolationMethod);
            map.setBounds(treArea);
            long t2 = System.currentTimeMillis();
            log.info("DEM file calculation for", map.getFilename(), "took", (t2 - t1), "ms");
            demFile.write();
        } catch (MapFailedException e) {
            log.error("exception while creating DEM file", e.getMessage());
            // TODO: better remove DEM file?
            throw new MapFailedException("DEM");
        }
    }
    treFile.writePost();
}
Also used : MapperBasedMapDataSource(uk.me.parabola.mkgmap.reader.MapperBasedMapDataSource) TREFile(uk.me.parabola.imgfmt.app.trergn.TREFile) MapFailedException(uk.me.parabola.imgfmt.MapFailedException) RGNFile(uk.me.parabola.imgfmt.app.trergn.RGNFile) Path2D(java.awt.geom.Path2D) Rectangle2D(java.awt.geom.Rectangle2D) RouteCenter(uk.me.parabola.imgfmt.app.net.RouteCenter) NODFile(uk.me.parabola.imgfmt.app.net.NODFile) DEMFile(uk.me.parabola.imgfmt.app.dem.DEMFile) Area(uk.me.parabola.imgfmt.app.Area) RoadNetwork(uk.me.parabola.imgfmt.app.net.RoadNetwork) NETFile(uk.me.parabola.imgfmt.app.net.NETFile) OverviewMapDataSource(uk.me.parabola.mkgmap.reader.overview.OverviewMapDataSource)

Example 2 with OverviewMapDataSource

use of uk.me.parabola.mkgmap.reader.overview.OverviewMapDataSource in project mkgmap by openstreetmap.

the class MapBuilder method makeMapAreas.

/**
 * Drive the map generation by stepping through the levels, generating the
 * subdivisions for the level and filling in the map elements that should
 * go into the area.
 *
 * This is fairly complex: you need to divide into subdivisions depending on
 * their size and the number of elements that will be contained.
 *
 * @param map The map.
 * @param src The data for the map.
 */
private void makeMapAreas(Map map, LoadableMapDataSource src) {
    // The top level has to cover the whole map without subdividing, so
    // do a special check to make sure.
    LevelInfo[] levels = null;
    if (src instanceof OverviewMapDataSource) {
        mergeLines = true;
        prepShapesForMerge(src.getShapes());
        mergeShapes = true;
        levels = src.mapLevels();
    } else {
        if (OverviewBuilder.isOverviewImg(map.getFilename())) {
            levels = src.overviewMapLevels();
        } else {
            levels = src.mapLevels();
        }
    }
    if (levels == null) {
        throw new ExitException("no info about levels available.");
    }
    LevelInfo levelInfo = levels[0];
    // If there is already a top level zoom, then we shouldn't add our own
    Subdivision topdiv;
    if (levelInfo.isTop()) {
        // There is already a top level definition.  So use the values from it and
        // then remove it from the levels definition.
        levels = Arrays.copyOfRange(levels, 1, levels.length);
        Zoom zoom = map.createZoom(levelInfo.getLevel(), levelInfo.getBits());
        topdiv = makeTopArea(src, map, zoom);
    } else {
        // We have to automatically create the definition for the top zoom level.
        int maxBits = getMaxBits(src);
        // decrease it so that it is less.
        if (levelInfo.getBits() <= maxBits)
            maxBits = levelInfo.getBits() - 1;
        // Create the empty top level
        Zoom zoom = map.createZoom(levelInfo.getLevel() + 1, maxBits);
        topdiv = makeTopArea(src, map, zoom);
    }
    // We start with one map data source.
    List<SourceSubdiv> srcList = Collections.singletonList(new SourceSubdiv(src, topdiv));
    // Now the levels filled with features.
    for (LevelInfo linfo : levels) {
        List<SourceSubdiv> nextList = new ArrayList<>();
        Zoom zoom = map.createZoom(linfo.getLevel(), linfo.getBits());
        for (SourceSubdiv srcDivPair : srcList) {
            MapSplitter splitter = new MapSplitter(srcDivPair.getSource(), zoom);
            MapArea[] areas = splitter.split(orderByDecreasingArea);
            log.info("Map region", srcDivPair.getSource().getBounds(), "split into", areas.length, "areas at resolution", zoom.getResolution());
            for (MapArea area : areas) {
                Subdivision parent = srcDivPair.getSubdiv();
                Subdivision div = makeSubdivision(map, parent, area, zoom);
                if (log.isDebugEnabled())
                    log.debug("ADD parent-subdiv", parent, srcDivPair.getSource(), ", z=", zoom, " new=", div);
                nextList.add(new SourceSubdiv(area, div));
            }
            if (nextList.size() > 0) {
                Subdivision lastdiv = nextList.get(nextList.size() - 1).getSubdiv();
                lastdiv.setLast(true);
            }
        }
        srcList = nextList;
    }
}
Also used : LevelInfo(uk.me.parabola.mkgmap.general.LevelInfo) ArrayList(java.util.ArrayList) Subdivision(uk.me.parabola.imgfmt.app.trergn.Subdivision) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) MapExitPoint(uk.me.parabola.mkgmap.general.MapExitPoint) Point(uk.me.parabola.imgfmt.app.trergn.Point) Zoom(uk.me.parabola.imgfmt.app.trergn.Zoom) ExitException(uk.me.parabola.imgfmt.ExitException) OverviewMapDataSource(uk.me.parabola.mkgmap.reader.overview.OverviewMapDataSource)

Aggregations

OverviewMapDataSource (uk.me.parabola.mkgmap.reader.overview.OverviewMapDataSource)2 Path2D (java.awt.geom.Path2D)1 Rectangle2D (java.awt.geom.Rectangle2D)1 ArrayList (java.util.ArrayList)1 ExitException (uk.me.parabola.imgfmt.ExitException)1 MapFailedException (uk.me.parabola.imgfmt.MapFailedException)1 Area (uk.me.parabola.imgfmt.app.Area)1 DEMFile (uk.me.parabola.imgfmt.app.dem.DEMFile)1 NETFile (uk.me.parabola.imgfmt.app.net.NETFile)1 NODFile (uk.me.parabola.imgfmt.app.net.NODFile)1 RoadNetwork (uk.me.parabola.imgfmt.app.net.RoadNetwork)1 RouteCenter (uk.me.parabola.imgfmt.app.net.RouteCenter)1 Point (uk.me.parabola.imgfmt.app.trergn.Point)1 RGNFile (uk.me.parabola.imgfmt.app.trergn.RGNFile)1 Subdivision (uk.me.parabola.imgfmt.app.trergn.Subdivision)1 TREFile (uk.me.parabola.imgfmt.app.trergn.TREFile)1 Zoom (uk.me.parabola.imgfmt.app.trergn.Zoom)1 LevelInfo (uk.me.parabola.mkgmap.general.LevelInfo)1 MapExitPoint (uk.me.parabola.mkgmap.general.MapExitPoint)1 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)1