Search in sources :

Example 6 with Subdivision

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

the class Map method topLevelSubdivision.

/**
 * Create the top level division. It must be empty afaik and cover
 * the whole area of the map.
 *
 * @param area The whole map area.
 * @param zoom The zoom level that you want the top level to be
 * at.  Its going to be at least level 1.
 * @return The top level division.
 */
public Subdivision topLevelSubdivision(Area area, Zoom zoom) {
    // May not always be necessary/desired
    zoom.setInherited(true);
    InternalFiles ifiles = this;
    Subdivision sub = Subdivision.topLevelSubdivision(ifiles, area, zoom);
    rgnFile.startDivision(sub);
    return sub;
}
Also used : InternalFiles(uk.me.parabola.imgfmt.app.trergn.InternalFiles) Subdivision(uk.me.parabola.imgfmt.app.trergn.Subdivision)

Example 7 with Subdivision

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

the class MapReader method pointsForLevel.

/**
 * Get a list of all the points for a given level.
 * @param level The level, lower numbers are the most detailed.
 */
public List<Point> pointsForLevel(int level, boolean withExtType) {
    List<Point> points = new ArrayList<Point>();
    Subdivision[] subdivisions = treFile.subdivForLevel(level);
    for (Subdivision sd : subdivisions) {
        List<Point> subdivPoints = rgnFile.pointsForSubdiv(sd, withExtType);
        points.addAll(subdivPoints);
    }
    return points;
}
Also used : ArrayList(java.util.ArrayList) Point(uk.me.parabola.imgfmt.app.trergn.Point) Subdivision(uk.me.parabola.imgfmt.app.trergn.Subdivision)

Example 8 with Subdivision

use of uk.me.parabola.imgfmt.app.trergn.Subdivision 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

Subdivision (uk.me.parabola.imgfmt.app.trergn.Subdivision)8 ArrayList (java.util.ArrayList)4 ExitException (uk.me.parabola.imgfmt.ExitException)2 Point (uk.me.parabola.imgfmt.app.trergn.Point)2 Zoom (uk.me.parabola.imgfmt.app.trergn.Zoom)2 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)2 FileExistsException (uk.me.parabola.imgfmt.FileExistsException)1 FileNotWritableException (uk.me.parabola.imgfmt.FileNotWritableException)1 FileSystemParam (uk.me.parabola.imgfmt.FileSystemParam)1 Area (uk.me.parabola.imgfmt.app.Area)1 Map (uk.me.parabola.imgfmt.app.map.Map)1 InternalFiles (uk.me.parabola.imgfmt.app.trergn.InternalFiles)1 Polygon (uk.me.parabola.imgfmt.app.trergn.Polygon)1 Polyline (uk.me.parabola.imgfmt.app.trergn.Polyline)1 LevelInfo (uk.me.parabola.mkgmap.general.LevelInfo)1 MapExitPoint (uk.me.parabola.mkgmap.general.MapExitPoint)1 MapLine (uk.me.parabola.mkgmap.general.MapLine)1 MapShape (uk.me.parabola.mkgmap.general.MapShape)1 OverviewMapDataSource (uk.me.parabola.mkgmap.reader.overview.OverviewMapDataSource)1