Search in sources :

Example 6 with LevelInfo

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

Example 7 with LevelInfo

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

the class PolishMapDataSource method imgId.

/**
 * The initial 'IMG ID' section.  Contains miscellaneous parameters for
 * the map.
 *
 * @param name Command name.
 * @param value Command value.
 */
private void imgId(String name, String value) {
    if (name.equals("Copyright")) {
        copyright = value;
    } else if (name.equals("Levels")) {
        int nlev = Integer.valueOf(value);
        levels = new LevelInfo[nlev];
    } else if (name.startsWith("Level")) {
        int level = Integer.valueOf(name.substring(5));
        int bits = Integer.valueOf(value);
        LevelInfo info = new LevelInfo(level, bits);
        int nlevels = levels.length;
        if (level >= nlevels)
            return;
        levels[nlevels - level - 1] = info;
    } else if (name.startsWith("Elevation")) {
        char fc = value.charAt(0);
        if (fc == 'm' || fc == 'M')
            elevUnits = 'm';
    } else if (name.equals("CodePage")) {
        dec = Charset.forName("cp" + value).newDecoder();
        dec.onUnmappableCharacter(CodingErrorAction.REPLACE);
    } else if (name.endsWith("LeftSideTraffic")) {
        if ("Y".equals(value)) {
            setDriveOnLeft(true);
        } else if ("N".equals(value)) {
            setDriveOnLeft(false);
        }
    }
}
Also used : LevelInfo(uk.me.parabola.mkgmap.general.LevelInfo) MapPoint(uk.me.parabola.mkgmap.general.MapPoint)

Example 8 with LevelInfo

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

the class PolishMapDataSource method extractResolution.

/**
 * Extract resolution from the level.
 *
 * @param level The level (0..)
 * @return The resolution.
 * @see #extractResolution(String name)
 */
private int extractResolution(int level) {
    int nlevels = levels.length;
    // Some maps use EndLevel=9 to mean the highest level
    if (level >= nlevels)
        level = nlevels - 1;
    LevelInfo li = levels[nlevels - level - 1];
    return li.getBits();
}
Also used : LevelInfo(uk.me.parabola.mkgmap.general.LevelInfo) MapPoint(uk.me.parabola.mkgmap.general.MapPoint)

Aggregations

LevelInfo (uk.me.parabola.mkgmap.general.LevelInfo)8 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)6 Point (uk.me.parabola.imgfmt.app.trergn.Point)3 ExitException (uk.me.parabola.imgfmt.ExitException)2 Zoom (uk.me.parabola.imgfmt.app.trergn.Zoom)2 FileNotFoundException (java.io.FileNotFoundException)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 MapReader (uk.me.parabola.imgfmt.app.map.MapReader)1 Subdivision (uk.me.parabola.imgfmt.app.trergn.Subdivision)1 MapExitPoint (uk.me.parabola.mkgmap.general.MapExitPoint)1 MapShape (uk.me.parabola.mkgmap.general.MapShape)1 OverviewMapDataSource (uk.me.parabola.mkgmap.reader.overview.OverviewMapDataSource)1 TokenScanner (uk.me.parabola.mkgmap.scan.TokenScanner)1