Search in sources :

Example 1 with RGNFile

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

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

the class Map method createMap.

/**
 * Create a complete map.  This consists of (at least) three
 * files that all have the same basename and different extensions.
 *
 * @param mapname The name of the map.  This is an 8 digit number as a
 * string.
 * @param params Parameters that describe the file system that the map
 * will be created in.
 * @return A map object that holds together all the files that make it up.
 * @throws FileExistsException If the file already exists and we do not
 * want to overwrite it.
 * @throws FileNotWritableException If the file cannot
 * be opened for write.
 */
public static Map createMap(String mapname, String outputdir, FileSystemParam params, String mapnumber, Sort sort) throws FileExistsException, FileNotWritableException {
    Map m = new Map();
    m.mapName = mapname;
    String outFilename = Utils.joinPath(outputdir, mapname, "img");
    FileSystem fs = ImgFS.createFs(outFilename, params);
    m.filename = outFilename;
    m.fileSystem = fs;
    m.rgnFile = new RGNFile(m.fileSystem.create(mapnumber + ".RGN"));
    m.treFile = new TREFile(m.fileSystem.create(mapnumber + ".TRE"));
    m.lblFile = new LBLFile(m.fileSystem.create(mapnumber + ".LBL"), sort);
    int mapid;
    try {
        mapid = Integer.parseInt(mapnumber);
    } catch (NumberFormatException e) {
        mapid = 0;
    }
    m.mapId = mapid;
    m.treFile.setMapId(mapid);
    m.fileSystem = fs;
    return m;
}
Also used : TREFile(uk.me.parabola.imgfmt.app.trergn.TREFile) RGNFile(uk.me.parabola.imgfmt.app.trergn.RGNFile) FileSystem(uk.me.parabola.imgfmt.fs.FileSystem) LBLFile(uk.me.parabola.imgfmt.app.lbl.LBLFile)

Aggregations

RGNFile (uk.me.parabola.imgfmt.app.trergn.RGNFile)2 TREFile (uk.me.parabola.imgfmt.app.trergn.TREFile)2 Path2D (java.awt.geom.Path2D)1 Rectangle2D (java.awt.geom.Rectangle2D)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 LBLFile (uk.me.parabola.imgfmt.app.lbl.LBLFile)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 FileSystem (uk.me.parabola.imgfmt.fs.FileSystem)1 MapperBasedMapDataSource (uk.me.parabola.mkgmap.reader.MapperBasedMapDataSource)1 OverviewMapDataSource (uk.me.parabola.mkgmap.reader.overview.OverviewMapDataSource)1