Search in sources :

Example 1 with MapReader

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

the class SimpleTest method testBasic.

/**
 * A very basic check that the size of all the sections has not changed.
 * This can be used to make sure that a change that is not expected to
 * change the output does not do so.
 *
 * The sizes will have to be always changed when the output does change
 * though.
 */
@Test
public void testBasic() throws FileNotFoundException {
    Main.mainNoSystemExit(Args.TEST_STYLE_ARG, "--preserve-element-order", Args.TEST_RESOURCE_OSM + "uk-test-1.osm.gz");
    MapReader mr = new MapReader(Args.DEF_MAP_ID + ".img");
    TestUtils.registerFile(mr);
    // FileSystem fs = ImgFS.openFs(Args.DEF_MAP_ID + ".img");
    assertNotNull("file exists", mr);
    Area bounds = mr.getTreBounds();
    Area expBox = new Area(2402404, -11185, 2407064, -6524);
    assertEquals("bounds of map", expBox, bounds);
    List<Point> list = mr.pointsForLevel(0, MapReader.WITH_EXT_TYPE_DATA);
    assertEquals("number of points at level 0", 204, list.size());
    List<Polyline> list1 = mr.linesForLevel(0);
    assertEquals("number of lines at level 0", 3382, list1.size());
}
Also used : Area(uk.me.parabola.imgfmt.app.Area) MapReader(uk.me.parabola.imgfmt.app.map.MapReader) Polyline(uk.me.parabola.imgfmt.app.trergn.Polyline) Point(uk.me.parabola.imgfmt.app.trergn.Point) Test(org.junit.Test)

Example 2 with MapReader

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

the class ImgReadTest method testNet.

@Test
public void testNet() throws IOException {
    try (MapReader mr = new MapReader(Utils.joinPath(Args.TEST_RESOURCE_IMG, Args.DEF_MAP_FILENAME3))) {
        List<RoadDef> roads = mr.getRoads();
        assertEquals("number of roads", 1365, roads.size());
    }
}
Also used : MapReader(uk.me.parabola.imgfmt.app.map.MapReader) RoadDef(uk.me.parabola.imgfmt.app.net.RoadDef) Test(org.junit.Test)

Example 3 with MapReader

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

the class TdbBuilder method addToTdb.

/**
 * Add the information about the current map to the tdb file.
 *
 * @param finfo Information about the current .img file.
 */
private void addToTdb(FileInfo finfo) {
    DetailMapBlock detail = new DetailMapBlock(tdbVersion);
    detail.setArea(finfo.getBounds());
    String mapname = finfo.getMapname();
    String mapdesc = finfo.getDescription();
    detail.setMapName(mapname);
    String desc = mapdesc + " (" + mapname + ')';
    detail.setDescription(desc);
    detail.setSubFiles(finfo.subFiles());
    log.info("overview-mapname", overviewMapname);
    log.info("overview-mapnumber", parent);
    detail.setParentMapNumber(parent);
    tdb.addDetail(detail);
    String[] msgs = finfo.getLicenseInfo();
    for (String m : msgs) tdb.addCopyright(m);
    MapReader mapReader = null;
    String filename = finfo.getFilename();
    try {
        mapReader = new MapReader(filename);
        msgs = mapReader.getCopyrights();
        boolean found = false;
        for (String[] block : copyrightMsgs) {
            if (Arrays.deepEquals(block, msgs)) {
                found = true;
                break;
            }
        }
        if (!found) {
            copyrightMsgs.add(msgs);
            for (String m : msgs) tdb.addCopyright(m);
        }
    } catch (FileNotFoundException e) {
        throw new ExitException("Could not open " + filename + " when creating tdb file");
    } finally {
        Utils.closeFile(mapReader);
    }
}
Also used : MapReader(uk.me.parabola.imgfmt.app.map.MapReader) DetailMapBlock(uk.me.parabola.tdbfmt.DetailMapBlock) FileNotFoundException(java.io.FileNotFoundException) ExitException(uk.me.parabola.imgfmt.ExitException)

Example 4 with MapReader

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

the class MdrBuilder method onMapEnd.

/**
 * Adds a new map to the file.  We need to read in the img file and
 * extract all the information that can be indexed from it.
 *
 * @param info An interface to read the map.
 */
public void onMapEnd(FileInfo info) {
    if (!info.isImg())
        return;
    // Add the map name
    mdrFile.addMap(info.getHexname(), info.getCodePage());
    String filename = info.getFilename();
    MapReader mr = null;
    try {
        mr = new MapReader(filename);
        AreaMaps maps = new AreaMaps();
        maps.countries = addCountries(mr);
        maps.regions = addRegions(mr, maps);
        List<Mdr5Record> mdrCityList = fetchCities(mr, maps);
        maps.cityList = mdrCityList;
        addPoints(mr, maps);
        addCities(mdrCityList);
        addStreets(mr, mdrCityList);
        addZips(mr);
    } catch (FileNotFoundException e) {
        throw new ExitException("Could not open " + filename + " when creating mdr file");
    } finally {
        Utils.closeFile(mr);
    }
}
Also used : MapReader(uk.me.parabola.imgfmt.app.map.MapReader) Mdr5Record(uk.me.parabola.imgfmt.app.mdr.Mdr5Record) FileNotFoundException(java.io.FileNotFoundException) ExitException(uk.me.parabola.imgfmt.ExitException)

Example 5 with MapReader

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

MapReader (uk.me.parabola.imgfmt.app.map.MapReader)5 FileNotFoundException (java.io.FileNotFoundException)3 ExitException (uk.me.parabola.imgfmt.ExitException)3 Test (org.junit.Test)2 Point (uk.me.parabola.imgfmt.app.trergn.Point)2 Area (uk.me.parabola.imgfmt.app.Area)1 Mdr5Record (uk.me.parabola.imgfmt.app.mdr.Mdr5Record)1 RoadDef (uk.me.parabola.imgfmt.app.net.RoadDef)1 Polyline (uk.me.parabola.imgfmt.app.trergn.Polyline)1 Zoom (uk.me.parabola.imgfmt.app.trergn.Zoom)1 LevelInfo (uk.me.parabola.mkgmap.general.LevelInfo)1 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)1 DetailMapBlock (uk.me.parabola.tdbfmt.DetailMapBlock)1