Search in sources :

Example 6 with MapFailedException

use of uk.me.parabola.imgfmt.MapFailedException in project mkgmap by openstreetmap.

the class RoadDef method writeRgnOffsets.

/**
 * Write into the RGN the offset in net1 of this road.
 * @param rgn A writer for the rgn file.
 */
void writeRgnOffsets(ImgFileWriter rgn) {
    if (offsetNet1 >= 0x400000)
        throw new MapFailedException("Overflow of the NET1. The tile (" + log.threadTag() + ") must be split so that there are fewer roads in it");
    for (Offset off : rgnOffsets) {
        rgn.position(off.getPosition());
        rgn.put3(offsetNet1 | off.getFlags());
    }
}
Also used : MapFailedException(uk.me.parabola.imgfmt.MapFailedException)

Example 7 with MapFailedException

use of uk.me.parabola.imgfmt.MapFailedException 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 8 with MapFailedException

use of uk.me.parabola.imgfmt.MapFailedException in project mkgmap by openstreetmap.

the class Main method mainStart.

/**
 * The main program to make or combine maps.  We now use a two pass process,
 * first going through the arguments and make any maps and collect names
 * to be used for creating summary files like the TDB and gmapsupp.
 *
 * @param args The command line arguments.
 */
private static int mainStart(String... args) {
    Instant start = Instant.now();
    System.out.println("Time started: " + new Date());
    // We need at least one argument.
    if (args.length < 1) {
        printUsage();
        printHelp(System.err, getLang(), "options");
        return 0;
    }
    Main mm = new Main();
    int numExitExceptions = 0;
    try {
        // Read the command line arguments and process each filename found.
        CommandArgsReader commandArgs = new CommandArgsReader(mm);
        commandArgs.setValidOptions(getValidOptions(System.err));
        commandArgs.readArgs(args);
    } catch (OutOfMemoryError e) {
        ++numExitExceptions;
        System.err.println(e);
        if (mm.maxJobs > 1)
            System.err.println("Try using the mkgmap --max-jobs option with a value less than " + mm.maxJobs + " to reduce the memory requirement, or use the Java -Xmx option to increase the available heap memory.");
        else
            System.err.println("Try using the Java -Xmx option to increase the available heap memory.");
    } catch (MapFailedException e) {
        // one of the combiners failed
        e.printStackTrace();
        ++numExitExceptions;
    } catch (ExitException e) {
        ++numExitExceptions;
        String message = e.getMessage();
        Throwable cause = e.getCause();
        while (cause != null) {
            message += "\r\n" + cause.toString();
            cause = cause.getCause();
        }
        System.err.println(message);
    }
    System.out.println("Number of ExitExceptions: " + numExitExceptions);
    System.out.println("Time finished: " + new Date());
    Duration duration = Duration.between(start, Instant.now());
    long seconds = duration.getSeconds();
    if (seconds > 0) {
        long hours = seconds / 3600;
        seconds -= hours * 3600;
        long minutes = seconds / 60;
        seconds -= minutes * 60;
        System.out.println("Total time taken: " + (hours > 0 ? hours + (hours > 1 ? " hours " : " hour ") : "") + (minutes > 0 ? minutes + (minutes > 1 ? " minutes " : " minute ") : "") + (seconds > 0 ? seconds + (seconds > 1 ? " seconds" : " second") : ""));
    } else
        System.out.println("Total time taken: " + duration.getNano() / 1000000 + " ms");
    if (numExitExceptions > 0 || mm.getProgramRC() != 0) {
        return 1;
    }
    return 0;
}
Also used : CommandArgsReader(uk.me.parabola.mkgmap.CommandArgsReader) MapFailedException(uk.me.parabola.imgfmt.MapFailedException) Instant(java.time.Instant) Duration(java.time.Duration) ExitException(uk.me.parabola.imgfmt.ExitException) Date(java.util.Date) OutOfMemoryError(java.lang.OutOfMemoryError)

Example 9 with MapFailedException

use of uk.me.parabola.imgfmt.MapFailedException in project mkgmap by openstreetmap.

the class MapMaker method makeMap.

/**
 * Make a map from the given map data source.
 *
 * @param args User supplied arguments.
 * @param src The data source to load.
 * @param mapNameExt
 * @return The output filename for the map.
 */
private String makeMap(CommandArgs args, LoadableMapDataSource src, String mapNamePrefix) {
    if (src.getBounds().isEmpty())
        return null;
    FileSystemParam params = new FileSystemParam();
    params.setBlockSize(args.getBlockSize());
    params.setMapDescription(args.getDescription());
    log.info("Started making", args.getMapname(), "(" + args.getDescription() + ")");
    try {
        Map map = Map.createMap(mapNamePrefix + args.getMapname(), args.getOutputDir(), params, args.getMapname(), sort);
        setOptions(map, args);
        MapBuilder builder = new MapBuilder();
        builder.config(args.getProperties());
        if (!OverviewBuilder.OVERVIEW_PREFIX.equals(mapNamePrefix)) {
            if (args.getProperties().containsKey("route") || args.getProperties().containsKey("net"))
                builder.setDoRoads(true);
        }
        builder.makeMap(map, src);
        // Collect information on map complete.
        String outName = map.getFilename();
        log.info("finished making map", outName, "closing");
        map.close();
        return outName;
    } catch (FileExistsException e) {
        throw new MapFailedException("File exists already", e);
    } catch (FileNotWritableException e) {
        throw new MapFailedException("Could not create or write to file", e);
    }
}
Also used : FileSystemParam(uk.me.parabola.imgfmt.FileSystemParam) MapFailedException(uk.me.parabola.imgfmt.MapFailedException) FileNotWritableException(uk.me.parabola.imgfmt.FileNotWritableException) MapBuilder(uk.me.parabola.mkgmap.build.MapBuilder) Map(uk.me.parabola.imgfmt.app.map.Map) FileExistsException(uk.me.parabola.imgfmt.FileExistsException)

Example 10 with MapFailedException

use of uk.me.parabola.imgfmt.MapFailedException in project mkgmap by openstreetmap.

the class TypCompiler method standAloneRun.

private void standAloneRun(String in, String out) {
    CharsetProbe probe = new CharsetProbe();
    String readCharset = probe.probeCharset(in);
    TypData data;
    try {
        data = compile(in, readCharset, null);
    } catch (SyntaxException e) {
        System.out.println(e.getMessage());
        return;
    } catch (FileNotFoundException e) {
        throw new MapFailedException("Could not open TYP file " + in + " to read");
    }
    try {
        writeTyp(data, new File(out));
    } catch (IOException e) {
        System.out.println("Error writing file: " + e.getMessage());
    }
}
Also used : TypData(uk.me.parabola.imgfmt.app.typ.TypData) MapFailedException(uk.me.parabola.imgfmt.MapFailedException) SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) TYPFile(uk.me.parabola.imgfmt.app.typ.TYPFile) File(java.io.File)

Aggregations

MapFailedException (uk.me.parabola.imgfmt.MapFailedException)22 IOException (java.io.IOException)11 File (java.io.File)4 FileNotFoundException (java.io.FileNotFoundException)4 TypData (uk.me.parabola.imgfmt.app.typ.TypData)3 SyntaxException (uk.me.parabola.mkgmap.scan.SyntaxException)3 FileInputStream (java.io.FileInputStream)2 OutOfMemoryError (java.lang.OutOfMemoryError)2 ExitException (uk.me.parabola.imgfmt.ExitException)2 FileNotWritableException (uk.me.parabola.imgfmt.FileNotWritableException)2 TYPFile (uk.me.parabola.imgfmt.app.typ.TYPFile)2 Path2D (java.awt.geom.Path2D)1 Rectangle2D (java.awt.geom.Rectangle2D)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)1 MemoryUsage (java.lang.management.MemoryUsage)1 ByteBuffer (java.nio.ByteBuffer)1