Search in sources :

Example 6 with ExitException

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

the class SrtTextReader method sortForCodepage.

/**
 * Find and read in the default sort description for the given codepage.
 */
public static Sort sortForCodepage(int codepage) {
    String name = "sort/cp" + codepage + ".txt";
    InputStream is = Sort.class.getClassLoader().getResourceAsStream(name);
    if (is == null) {
        if (codepage == 1252)
            throw new ExitException("No sort description for code-page 1252 available");
        Sort defaultSort = SrtTextReader.sortForCodepage(1252);
        defaultSort.setCodepage(codepage);
        defaultSort.setDescription("Default sort");
        return defaultSort;
    }
    try {
        InputStreamReader r = new InputStreamReader(is, "utf-8");
        SrtTextReader sr = new SrtTextReader(r);
        return sr.getSort();
    } catch (IOException e) {
        return SrtTextReader.sortForCodepage(codepage);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Sort(uk.me.parabola.imgfmt.app.srt.Sort) IOException(java.io.IOException) ExitException(uk.me.parabola.imgfmt.ExitException)

Example 7 with ExitException

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

the class Sort method add.

public void add(int ch, int primary, int secondary, int tertiary, int flags) {
    ensurePage(ch >>> 8);
    if (getPrimary(ch) != 0)
        throw new ExitException(String.format("Repeated primary index 0x%x", ch & 0xff));
    setPrimary(ch, primary);
    setSecondary(ch, secondary);
    setTertiary(ch, tertiary);
    setFlags(ch, flags);
    int numExp = (flags >> 4) & 0xf;
    if (numExp + 1 > maxExpSize)
        maxExpSize = numExp + 1;
}
Also used : ExitException(uk.me.parabola.imgfmt.ExitException)

Example 8 with ExitException

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

the class MapBuilder method getMapInfo.

/**
 * Set all the information that appears in the header.
 */
private void getMapInfo() {
    if (licenseFileName != null) {
        List<String> licenseArray = new ArrayList<>();
        try {
            File file = new File(licenseFileName);
            licenseArray = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
        } catch (Exception e) {
            throw new ExitException("Error reading license file " + licenseFileName, e);
        }
        if ((licenseArray.size() > 0) && licenseArray.get(0).startsWith("\ufeff"))
            licenseArray.set(0, licenseArray.get(0).substring(1));
        UnaryOperator<String> replaceVariables = s -> s.replace("$MKGMAP_VERSION$", Version.VERSION).replace("$JAVA_VERSION$", System.getProperty("java.version")).replace("$YEAR$", Integer.toString(now.getYear())).replace("$LONGDATE$", now.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG))).replace("$SHORTDATE$", now.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT))).replace("$TIME$", now.toLocalTime().toString().substring(0, 5));
        licenseArray.replaceAll(replaceVariables);
        mapInfo.addAll(licenseArray);
    } else {
        mapInfo.add("Map data (c) OpenStreetMap and its contributors");
        mapInfo.add("http://www.openstreetmap.org/copyright");
        mapInfo.add("");
        mapInfo.add("This map data is made available under the Open Database License:");
        mapInfo.add("http://opendatacommons.org/licenses/odbl/1.0/");
        mapInfo.add("Any rights in individual contents of the database are licensed under the");
        mapInfo.add("Database Contents License: http://opendatacommons.org/licenses/dbcl/1.0/");
        mapInfo.add("");
        // Pad the version number with spaces so that version
        // strings that are different lengths do not change the size and
        // offsets of the following sections.
        mapInfo.add("Map created with mkgmap-r" + String.format("%-10s", Version.VERSION));
        mapInfo.add("Program released under the GPL");
    }
}
Also used : Arrays(java.util.Arrays) Polygon(uk.me.parabola.imgfmt.app.trergn.Polygon) OverviewMapDataSource(uk.me.parabola.mkgmap.reader.overview.OverviewMapDataSource) Overview(uk.me.parabola.imgfmt.app.trergn.Overview) Subdivision(uk.me.parabola.imgfmt.app.trergn.Subdivision) Rectangle2D(java.awt.geom.Rectangle2D) Highway(uk.me.parabola.imgfmt.app.lbl.Highway) UnaryOperator(java.util.function.UnaryOperator) MapFilter(uk.me.parabola.mkgmap.filters.MapFilter) HGTReader(uk.me.parabola.mkgmap.reader.hgt.HGTReader) DEMFile(uk.me.parabola.imgfmt.app.dem.DEMFile) RoundCoordsFilter(uk.me.parabola.mkgmap.filters.RoundCoordsFilter) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) Logger(uk.me.parabola.log.Logger) POIRecord(uk.me.parabola.imgfmt.app.lbl.POIRecord) RGNHeader(uk.me.parabola.imgfmt.app.trergn.RGNHeader) NETFile(uk.me.parabola.imgfmt.app.net.NETFile) Zip(uk.me.parabola.imgfmt.app.lbl.Zip) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) OverviewBuilder(uk.me.parabola.mkgmap.combiners.OverviewBuilder) MapExitPoint(uk.me.parabola.mkgmap.general.MapExitPoint) IdentityHashMap(java.util.IdentityHashMap) Java2DConverter(uk.me.parabola.util.Java2DConverter) SizeFilter(uk.me.parabola.mkgmap.filters.SizeFilter) City(uk.me.parabola.imgfmt.app.lbl.City) Set(java.util.Set) TREFile(uk.me.parabola.imgfmt.app.trergn.TREFile) TREHeader(uk.me.parabola.imgfmt.app.trergn.TREHeader) CityInfo(uk.me.parabola.mkgmap.general.CityInfo) InterpolationMethod(uk.me.parabola.mkgmap.reader.hgt.HGTConverter.InterpolationMethod) PolygonOverview(uk.me.parabola.imgfmt.app.trergn.PolygonOverview) LevelInfo(uk.me.parabola.mkgmap.general.LevelInfo) Zoom(uk.me.parabola.imgfmt.app.trergn.Zoom) RGNFile(uk.me.parabola.imgfmt.app.trergn.RGNFile) StandardCharsets(java.nio.charset.StandardCharsets) HGTConverter(uk.me.parabola.mkgmap.reader.hgt.HGTConverter) List(java.util.List) Configurable(uk.me.parabola.util.Configurable) DouglasPeuckerFilter(uk.me.parabola.mkgmap.filters.DouglasPeuckerFilter) MapLine(uk.me.parabola.mkgmap.general.MapLine) RoadDef(uk.me.parabola.imgfmt.app.net.RoadDef) PolygonSplitterFilter(uk.me.parabola.mkgmap.filters.PolygonSplitterFilter) ShapeMergeFilter(uk.me.parabola.mkgmap.filters.ShapeMergeFilter) ZipCodeInfo(uk.me.parabola.mkgmap.general.ZipCodeInfo) MapperBasedMapDataSource(uk.me.parabola.mkgmap.reader.MapperBasedMapDataSource) RouteCenter(uk.me.parabola.imgfmt.app.net.RouteCenter) FormatStyle(java.time.format.FormatStyle) PolylineOverview(uk.me.parabola.imgfmt.app.trergn.PolylineOverview) LocalDateTime(java.time.LocalDateTime) MapDataSource(uk.me.parabola.mkgmap.general.MapDataSource) HashMap(java.util.HashMap) Point(uk.me.parabola.imgfmt.app.trergn.Point) ExitException(uk.me.parabola.imgfmt.ExitException) LBLFile(uk.me.parabola.imgfmt.app.lbl.LBLFile) PointOverview(uk.me.parabola.imgfmt.app.trergn.PointOverview) ExitFacility(uk.me.parabola.imgfmt.app.lbl.ExitFacility) ArrayList(java.util.ArrayList) Exit(uk.me.parabola.imgfmt.app.Exit) Label(uk.me.parabola.imgfmt.app.Label) Region(uk.me.parabola.imgfmt.app.lbl.Region) EnhancedProperties(uk.me.parabola.util.EnhancedProperties) MapShape(uk.me.parabola.mkgmap.general.MapShape) LineSplitterFilter(uk.me.parabola.mkgmap.filters.LineSplitterFilter) Utils(uk.me.parabola.imgfmt.Utils) Coord(uk.me.parabola.imgfmt.app.Coord) Map(uk.me.parabola.imgfmt.app.map.Map) Numbers(uk.me.parabola.imgfmt.app.net.Numbers) Version(uk.me.parabola.mkgmap.Version) MapRoad(uk.me.parabola.mkgmap.general.MapRoad) Files(java.nio.file.Files) NODFile(uk.me.parabola.imgfmt.app.net.NODFile) MapElement(uk.me.parabola.mkgmap.general.MapElement) MapFailedException(uk.me.parabola.imgfmt.MapFailedException) RemoveEmpty(uk.me.parabola.mkgmap.filters.RemoveEmpty) MapFilterChain(uk.me.parabola.mkgmap.filters.MapFilterChain) RemoveObsoletePointsFilter(uk.me.parabola.mkgmap.filters.RemoveObsoletePointsFilter) File(java.io.File) Polyline(uk.me.parabola.imgfmt.app.trergn.Polyline) Path2D(java.awt.geom.Path2D) ExtTypeAttributes(uk.me.parabola.imgfmt.app.trergn.ExtTypeAttributes) FilterConfig(uk.me.parabola.mkgmap.filters.FilterConfig) LinePreparerFilter(uk.me.parabola.mkgmap.filters.LinePreparerFilter) LoadableMapDataSource(uk.me.parabola.mkgmap.general.LoadableMapDataSource) RoadNetwork(uk.me.parabola.imgfmt.app.net.RoadNetwork) DateTimeFormatter(java.time.format.DateTimeFormatter) LineMergeFilter(uk.me.parabola.mkgmap.filters.LineMergeFilter) Country(uk.me.parabola.imgfmt.app.lbl.Country) BaseFilter(uk.me.parabola.mkgmap.filters.BaseFilter) Comparator(java.util.Comparator) Collections(java.util.Collections) Area(uk.me.parabola.imgfmt.app.Area) ArrayList(java.util.ArrayList) DEMFile(uk.me.parabola.imgfmt.app.dem.DEMFile) NETFile(uk.me.parabola.imgfmt.app.net.NETFile) TREFile(uk.me.parabola.imgfmt.app.trergn.TREFile) RGNFile(uk.me.parabola.imgfmt.app.trergn.RGNFile) LBLFile(uk.me.parabola.imgfmt.app.lbl.LBLFile) NODFile(uk.me.parabola.imgfmt.app.net.NODFile) File(java.io.File) ExitException(uk.me.parabola.imgfmt.ExitException) ExitException(uk.me.parabola.imgfmt.ExitException) MapFailedException(uk.me.parabola.imgfmt.MapFailedException)

Example 9 with ExitException

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

the class GmapiBuilder method copyToFile.

private static void copyToFile(ImgChannel f, Path dest) {
    ByteBuffer buf = ByteBuffer.allocate(8 * 1024);
    try (ByteChannel outchan = Files.newByteChannel(dest, CREATE, WRITE, TRUNCATE_EXISTING)) {
        while (f.read(buf) > 0) {
            buf.flip();
            outchan.write(buf);
            buf.compact();
        }
    } catch (IOException e) {
        throw new ExitException("Cannot write file " + e);
    }
}
Also used : ByteChannel(java.nio.channels.ByteChannel) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) ExitException(uk.me.parabola.imgfmt.ExitException)

Example 10 with ExitException

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

the class OverviewBuilder method writeOverviewMap.

/**
 * Write out the overview map.
 */
private void writeOverviewMap() {
    if (overviewSource.mapLevels() == null)
        return;
    MapBuilder mb = new MapBuilder();
    mb.setEnableLineCleanFilters(false);
    FileSystemParam params = new FileSystemParam();
    params.setMapDescription(areaName);
    mb.setCopyrights(creMsgList(copyrightMsgs));
    mb.setMapInfo(creMsgList(licenseInfos));
    try {
        if (codepage == null) {
            // should not happen
            codepage = 0;
        }
        Sort sort = SrtTextReader.sortForCodepage(codepage);
        Map map = Map.createMap(overviewMapname, outputDir, params, overviewMapnumber, sort);
        if (!demProps.isEmpty()) {
            map.config(demProps);
            mb.config(demProps);
        }
        if (encodingType != null) {
            map.getLblFile().setEncoder(encodingType, codepage);
        }
        mb.makeMap(map, overviewSource);
        map.close();
    } catch (FileExistsException e) {
        throw new ExitException("Could not create overview map", e);
    } catch (FileNotWritableException e) {
        throw new ExitException("Could not write to overview map", e);
    }
}
Also used : FileSystemParam(uk.me.parabola.imgfmt.FileSystemParam) FileNotWritableException(uk.me.parabola.imgfmt.FileNotWritableException) Sort(uk.me.parabola.imgfmt.app.srt.Sort) MapBuilder(uk.me.parabola.mkgmap.build.MapBuilder) Map(uk.me.parabola.imgfmt.app.map.Map) ExitException(uk.me.parabola.imgfmt.ExitException) FileExistsException(uk.me.parabola.imgfmt.FileExistsException)

Aggregations

ExitException (uk.me.parabola.imgfmt.ExitException)25 IOException (java.io.IOException)10 FileNotFoundException (java.io.FileNotFoundException)9 File (java.io.File)7 ArrayList (java.util.ArrayList)5 FileInputStream (java.io.FileInputStream)4 Zoom (uk.me.parabola.imgfmt.app.trergn.Zoom)4 InputStream (java.io.InputStream)3 ByteBuffer (java.nio.ByteBuffer)3 Map (uk.me.parabola.imgfmt.app.map.Map)3 LevelInfo (uk.me.parabola.mkgmap.general.LevelInfo)3 OutOfMemoryError (java.lang.OutOfMemoryError)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Files (java.nio.file.Files)2 LocalDateTime (java.time.LocalDateTime)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 FormatStyle (java.time.format.FormatStyle)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2