Search in sources :

Example 1 with Zoom

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

the class AbstractTestMap method makeMap.

protected void makeMap(String[] args) {
    // Default to nowhere in particular.
    double lat = 51.724;
    double lng = 0.2487;
    // Arguments allow you to place the map where ever you wish.
    if (args.length > 1) {
        lat = Double.valueOf(args[0]);
        lng = Double.valueOf(args[1]);
    }
    log.debug("this is a test make map program. Start", lat, '/', lng);
    FileSystemParam params = new FileSystemParam();
    params.setBlockSize(512);
    params.setMapDescription("OSM street map");
    Map map;
    try {
        map = Map.createMap("32860003", ".", params, "32860003", SrtTextReader.sortForCodepage(1252));
    } catch (FileExistsException e) {
        throw new ExitException("File exists already", e);
    } catch (FileNotWritableException e) {
        throw new ExitException("Could not create or write file", e);
    }
    map.addInfo("Program released under the GPL");
    map.addInfo("This map data is made available under the Open Database License:");
    // There has to be (at least) two copyright messages or else the map
    // does not show up.  The second one will be displayed at startup,
    // although the conditions where that happens are not known.
    map.addCopyright("program licenced under GPL v2");
    // This one gets shown when you switch on, so put the actual
    // map copyright here.  This is made up data, so no copyright applies.
    map.addCopyright("No copyright");
    Area area = new Area(lat, lng, lat + 1, lng + 1);
    map.setBounds(area);
    // There must always be an empty zoom level at the least detailed level.
    log.info("area " + area);
    log.info(" or " + lat + '/' + lng);
    Zoom z1 = map.createZoom(1, 24);
    Subdivision topdiv = map.topLevelSubdivision(area, z1);
    // Create a most detailed view
    Zoom z = map.createZoom(0, 24);
    Subdivision div = map.createSubdivision(topdiv, area, z);
    div.startDivision();
    drawTestMap(map, div, lat, lng);
    map.close();
}
Also used : Area(uk.me.parabola.imgfmt.app.Area) FileSystemParam(uk.me.parabola.imgfmt.FileSystemParam) FileNotWritableException(uk.me.parabola.imgfmt.FileNotWritableException) Zoom(uk.me.parabola.imgfmt.app.trergn.Zoom) Subdivision(uk.me.parabola.imgfmt.app.trergn.Subdivision) Map(uk.me.parabola.imgfmt.app.map.Map) ExitException(uk.me.parabola.imgfmt.ExitException) FileExistsException(uk.me.parabola.imgfmt.FileExistsException)

Example 2 with Zoom

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

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

the class OverviewBuilder method readShapes.

/**
 * Read the polygons 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 readShapes(MapReader mapReader) {
    Zoom[] levels = mapReader.getLevels();
    for (int l = 1; l < levels.length; l++) {
        int min = levels[l].getLevel();
        int res = levels[l].getResolution();
        List<Polygon> list = mapReader.shapesForLevel(min, MapReader.WITH_EXT_TYPE_DATA);
        for (Polygon shape : list) {
            if (log.isDebugEnabled())
                log.debug("got polygon", shape);
            if (shape.getType() == 0x4b) {
                hasBackground = true;
            }
            MapShape ms = new MapShape();
            List<Coord> points = shape.getPoints();
            if (log.isDebugEnabled())
                log.debug("polygon point list", points);
            if (points.size() < 3)
                continue;
            ms.setType(shape.getType());
            if (shape.getLabel() != null)
                ms.setName(shape.getLabel().getText());
            ms.setMaxResolution(res);
            ms.setMinResolution(res);
            ms.setPoints(points);
            overviewSource.addShape(ms);
        }
    }
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) Zoom(uk.me.parabola.imgfmt.app.trergn.Zoom) Polygon(uk.me.parabola.imgfmt.app.trergn.Polygon) MapShape(uk.me.parabola.mkgmap.general.MapShape) Point(uk.me.parabola.imgfmt.app.trergn.Point) MapPoint(uk.me.parabola.mkgmap.general.MapPoint)

Example 4 with Zoom

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

Example 5 with Zoom

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

the class OverviewBuilder method readFileIntoOverview.

/**
 * Add an individual .img file to the overview map.
 *
 * @param finfo Information about an individual map.
 */
private void readFileIntoOverview(FileInfo finfo) throws FileNotFoundException {
    addMapCoverageArea(finfo);
    MapReader mapReader = null;
    String filename = finfo.getFilename();
    if (codepage == null) {
        codepage = finfo.getCodePage();
    }
    if (codepage != finfo.getCodePage()) {
        System.err.println("WARNING: input file " + filename + " has different code page " + finfo.getCodePage());
    }
    try {
        mapReader = new MapReader(filename);
        if (encodingType == null) {
            encodingType = mapReader.getEncodingType();
        }
        if (encodingType != mapReader.getEncodingType()) {
            System.err.println("WARNING: input file " + filename + " has different charset type " + encodingType);
        }
        String[] msgs = mapReader.getCopyrights();
        boolean found = false;
        for (String[] block : copyrightMsgs) {
            if (Arrays.deepEquals(block, msgs)) {
                found = true;
                break;
            }
        }
        if (!found)
            copyrightMsgs.add(msgs);
        msgs = finfo.getLicenseInfo();
        found = false;
        for (String[] block : licenseInfos) {
            if (Arrays.deepEquals(block, msgs)) {
                found = true;
                break;
            }
        }
        if (!found)
            licenseInfos.add(msgs);
        Zoom[] levels = mapReader.getLevels();
        if (wantedLevels == null) {
            LevelInfo[] mapLevels;
            if (isOverviewImg(filename)) {
                mapLevels = new LevelInfo[levels.length - 1];
                for (int i = 1; i < levels.length; i++) {
                    mapLevels[i - 1] = new LevelInfo(levels[i].getLevel(), levels[i].getResolution());
                }
            } else {
                mapLevels = new LevelInfo[1];
                mapLevels[0] = new LevelInfo(levels[1].getLevel(), levels[1].getResolution());
            }
            wantedLevels = mapLevels;
        }
        if (isOverviewImg(filename)) {
            readPoints(mapReader);
            readLines(mapReader);
            readShapes(mapReader);
        }
    } catch (FileNotFoundException e) {
        throw new ExitException("Could not open " + filename + " when creating overview file");
    } finally {
        Utils.closeFile(mapReader);
    }
}
Also used : MapReader(uk.me.parabola.imgfmt.app.map.MapReader) LevelInfo(uk.me.parabola.mkgmap.general.LevelInfo) FileNotFoundException(java.io.FileNotFoundException) Zoom(uk.me.parabola.imgfmt.app.trergn.Zoom) ExitException(uk.me.parabola.imgfmt.ExitException) Point(uk.me.parabola.imgfmt.app.trergn.Point) MapPoint(uk.me.parabola.mkgmap.general.MapPoint)

Aggregations

Zoom (uk.me.parabola.imgfmt.app.trergn.Zoom)6 Point (uk.me.parabola.imgfmt.app.trergn.Point)5 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)5 ExitException (uk.me.parabola.imgfmt.ExitException)3 Area (uk.me.parabola.imgfmt.app.Area)2 Coord (uk.me.parabola.imgfmt.app.Coord)2 Subdivision (uk.me.parabola.imgfmt.app.trergn.Subdivision)2 LevelInfo (uk.me.parabola.mkgmap.general.LevelInfo)2 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 FileExistsException (uk.me.parabola.imgfmt.FileExistsException)1 FileNotWritableException (uk.me.parabola.imgfmt.FileNotWritableException)1 FileSystemParam (uk.me.parabola.imgfmt.FileSystemParam)1 Map (uk.me.parabola.imgfmt.app.map.Map)1 MapReader (uk.me.parabola.imgfmt.app.map.MapReader)1 Polygon (uk.me.parabola.imgfmt.app.trergn.Polygon)1 Polyline (uk.me.parabola.imgfmt.app.trergn.Polyline)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