Search in sources :

Example 16 with ExitException

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

the class Mdr15 method writeSectData.

public void writeSectData(ImgFileWriter writer) {
    FileInputStream stream = null;
    try {
        stream = new FileInputStream(tempFile);
        FileChannel channel = stream.getChannel();
        ByteBuffer buf = ByteBuffer.allocate(32 * 1024);
        while (channel.read(buf) > 0) {
            buf.flip();
            writer.put(buf);
            buf.compact();
        }
    } catch (IOException e) {
        throw new ExitException("Could not write string section of index");
    } finally {
        Utils.closeFile(stream);
    }
}
Also used : FileChannel(java.nio.channels.FileChannel) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) ExitException(uk.me.parabola.imgfmt.ExitException) FileInputStream(java.io.FileInputStream)

Example 17 with ExitException

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

the class MdrConfig method genTypesForRange.

/**
 * Create all POI types for a given range.
 * @param set set of integers. Generated types are added to it.
 * @param start first type
 * @param stop last type (included)
 */
private void genTypesForRange(Set<Integer> set, String start, String stop) {
    GType[] types = new GType[2];
    String[] ranges = { start, stop };
    boolean ok = true;
    for (int i = 0; i < 2; i++) {
        try {
            types[i] = new GType(FeatureKind.POINT, ranges[i]);
        } catch (ExitException e) {
            ok = false;
        }
        if (!ok || !GType.checkType(types[i].getFeatureKind(), types[i].getType())) {
            throw new SyntaxException("invalid type " + ranges[i] + " for " + FeatureKind.POINT + " in option " + Arrays.toString(ranges));
        }
    }
    if (types[0].getType() > types[1].getType()) {
        GType gt = types[0];
        types[0] = types[1];
        types[1] = gt;
    }
    for (int i = types[0].getType(); i <= types[1].getType(); i++) {
        if ((i & 0xff) > 0x1f)
            i = ((i >> 8) + 1) << 8;
        set.add(i);
    }
}
Also used : GType(uk.me.parabola.mkgmap.reader.osm.GType) SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) ExitException(uk.me.parabola.imgfmt.ExitException)

Example 18 with ExitException

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

the class MapBuilder method makeMapAreas.

/**
 * Drive the map generation by stepping through the levels, generating the
 * subdivisions for the level and filling in the map elements that should
 * go into the area.
 *
 * This is fairly complex: you need to divide into subdivisions depending on
 * their size and the number of elements that will be contained.
 *
 * @param map The map.
 * @param src The data for the map.
 */
private void makeMapAreas(Map map, LoadableMapDataSource src) {
    // The top level has to cover the whole map without subdividing, so
    // do a special check to make sure.
    LevelInfo[] levels = null;
    if (src instanceof OverviewMapDataSource) {
        mergeLines = true;
        prepShapesForMerge(src.getShapes());
        mergeShapes = true;
        levels = src.mapLevels();
    } else {
        if (OverviewBuilder.isOverviewImg(map.getFilename())) {
            levels = src.overviewMapLevels();
        } else {
            levels = src.mapLevels();
        }
    }
    if (levels == null) {
        throw new ExitException("no info about levels available.");
    }
    LevelInfo levelInfo = levels[0];
    // If there is already a top level zoom, then we shouldn't add our own
    Subdivision topdiv;
    if (levelInfo.isTop()) {
        // There is already a top level definition.  So use the values from it and
        // then remove it from the levels definition.
        levels = Arrays.copyOfRange(levels, 1, levels.length);
        Zoom zoom = map.createZoom(levelInfo.getLevel(), levelInfo.getBits());
        topdiv = makeTopArea(src, map, zoom);
    } else {
        // We have to automatically create the definition for the top zoom level.
        int maxBits = getMaxBits(src);
        // decrease it so that it is less.
        if (levelInfo.getBits() <= maxBits)
            maxBits = levelInfo.getBits() - 1;
        // Create the empty top level
        Zoom zoom = map.createZoom(levelInfo.getLevel() + 1, maxBits);
        topdiv = makeTopArea(src, map, zoom);
    }
    // We start with one map data source.
    List<SourceSubdiv> srcList = Collections.singletonList(new SourceSubdiv(src, topdiv));
    // Now the levels filled with features.
    for (LevelInfo linfo : levels) {
        List<SourceSubdiv> nextList = new ArrayList<>();
        Zoom zoom = map.createZoom(linfo.getLevel(), linfo.getBits());
        for (SourceSubdiv srcDivPair : srcList) {
            MapSplitter splitter = new MapSplitter(srcDivPair.getSource(), zoom);
            MapArea[] areas = splitter.split(orderByDecreasingArea);
            log.info("Map region", srcDivPair.getSource().getBounds(), "split into", areas.length, "areas at resolution", zoom.getResolution());
            for (MapArea area : areas) {
                Subdivision parent = srcDivPair.getSubdiv();
                Subdivision div = makeSubdivision(map, parent, area, zoom);
                if (log.isDebugEnabled())
                    log.debug("ADD parent-subdiv", parent, srcDivPair.getSource(), ", z=", zoom, " new=", div);
                nextList.add(new SourceSubdiv(area, div));
            }
            if (nextList.size() > 0) {
                Subdivision lastdiv = nextList.get(nextList.size() - 1).getSubdiv();
                lastdiv.setLast(true);
            }
        }
        srcList = nextList;
    }
}
Also used : LevelInfo(uk.me.parabola.mkgmap.general.LevelInfo) ArrayList(java.util.ArrayList) Subdivision(uk.me.parabola.imgfmt.app.trergn.Subdivision) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) MapExitPoint(uk.me.parabola.mkgmap.general.MapExitPoint) Point(uk.me.parabola.imgfmt.app.trergn.Point) Zoom(uk.me.parabola.imgfmt.app.trergn.Zoom) ExitException(uk.me.parabola.imgfmt.ExitException) OverviewMapDataSource(uk.me.parabola.mkgmap.reader.overview.OverviewMapDataSource)

Example 19 with ExitException

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

the class GmapiBuilder method writeXmlFile.

/**
 * An xml file contains similar information that is contained in the windows registry.
 *
 * @param gDir The directory where the Info.xml file will be created.
 */
private void writeXmlFile(Path gDir) {
    Path infoFile = gDir.resolve("Info.xml");
    XMLOutputFactory factory = XMLOutputFactory.newFactory();
    try (Writer stream = Files.newBufferedWriter(infoFile)) {
        XMLStreamWriter writer = factory.createXMLStreamWriter(stream);
        writer.writeStartDocument("UTF-8", "1.0");
        writer.setDefaultNamespace(NS);
        writer.writeCharacters("\n");
        writer.writeStartElement(NS, "MapProduct");
        writer.writeDefaultNamespace(NS);
        writer.writeCharacters("\n");
        xmlElement(writer, "Name", familyName);
        xmlElement(writer, "DataVersion", String.valueOf(productVersion));
        xmlElement(writer, "DataFormat", "Original");
        xmlElement(writer, "ID", String.valueOf(familyId));
        if (combinerMap.containsKey("mdx")) {
            String mdxFile = getFilenameFor("mdx");
            File file = new File(mdxFile);
            xmlElement(writer, "IDX", file.getName());
        }
        if (combinerMap.containsKey("mdr")) {
            String mdrName = getFilenameFor("mdr");
            File file = new File(mdrName);
            xmlElement(writer, "MDR", nameWithoutExtension(file));
        }
        if (typFile != null) {
            File file = new File(typFile);
            xmlElement(writer, "TYP", file.getName());
        }
        for (ProductInfo prod : productMap.values()) {
            writer.writeStartElement(NS, "SubProduct");
            writer.writeCharacters("\n");
            xmlElement(writer, "Name", prod.seriesName);
            xmlElement(writer, "ID", String.valueOf(prod.id));
            xmlElement(writer, "BaseMap", prod.overviewName);
            xmlElement(writer, "TDB", String.format("%s.tdb", prod.overviewName));
            xmlElement(writer, "Directory", String.format("Product%s", prod.id));
            writer.writeEndElement();
            writer.writeCharacters("\n");
        }
        writer.writeEndElement();
        writer.writeEndDocument();
        writer.flush();
    } catch (XMLStreamException | IOException e) {
        throw new ExitException("Could not create file " + infoFile + "; " + e);
    }
}
Also used : Path(java.nio.file.Path) XMLOutputFactory(javax.xml.stream.XMLOutputFactory) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) IOException(java.io.IOException) File(java.io.File) ExitException(uk.me.parabola.imgfmt.ExitException) Writer(java.io.Writer) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Example 20 with ExitException

use of uk.me.parabola.imgfmt.ExitException 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)

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