Search in sources :

Example 6 with ConsoleProgressImplementation

use of net.osmand.impl.ConsoleProgressImplementation in project OsmAnd-tools by osmandapp.

the class CountryOcbfGeneration method createFile.

private void createFile(CountryRegion global, Map<String, Set<TranslateEntity>> translates, Map<String, File> polygonFiles, String targetObf, String targetOsmXml) throws IOException, SQLException, InterruptedException, XmlPullParserException {
    File osm = new File(targetOsmXml);
    XmlSerializer serializer = new org.kxml2.io.KXmlSerializer();
    FileOutputStream fous = new FileOutputStream(osm);
    serializer.setOutput(fous, "UTF-8");
    serializer.startDocument("UTF-8", true);
    serializer.startTag(null, "osm");
    serializer.attribute(null, "version", "0.6");
    serializer.attribute(null, "generator", "OsmAnd");
    serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    for (CountryRegion r : global.children) {
        r.parent = null;
        processRegion(r, translates, polygonFiles, targetObf, targetOsmXml, "", serializer);
    }
    serializer.endDocument();
    serializer.flush();
    fous.close();
    // $NON-NLS-1$
    IndexCreator creator = new IndexCreator(new File(targetObf).getParentFile());
    creator.setMapFileName(new File(targetObf).getName());
    creator.setIndexMap(true);
    creator.setIndexAddress(false);
    creator.setIndexPOI(false);
    creator.setIndexTransport(false);
    creator.setIndexRouting(false);
    MapZooms zooms = MapZooms.parseZooms("5-6");
    creator.generateIndexes(osm, new ConsoleProgressImplementation(1), null, zooms, new MapRenderingTypesEncoder("regions"), log);
}
Also used : MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) FileOutputStream(java.io.FileOutputStream) MapZooms(net.osmand.binary.MapZooms) IndexCreator(net.osmand.data.preparation.IndexCreator) File(java.io.File) ConsoleProgressImplementation(net.osmand.impl.ConsoleProgressImplementation) XmlSerializer(org.xmlpull.v1.XmlSerializer)

Example 7 with ConsoleProgressImplementation

use of net.osmand.impl.ConsoleProgressImplementation in project OsmAnd-tools by osmandapp.

the class FixAdminLevel0 method process.

private static void process(File read, File write) throws IOException, XMLStreamException, XmlPullParserException {
    OsmBaseStorage storage = new OsmBaseStorage();
    storage.parseOSM(new FileInputStream(read), new ConsoleProgressImplementation());
    Map<EntityId, Entity> entities = new HashMap<EntityId, Entity>(storage.getRegisteredEntities());
    long id = -1;
    for (EntityId e : entities.keySet()) {
        Entity es = storage.getRegisteredEntities().get(e);
        if (e.getId() < id) {
            id = e.getId() - 1;
        }
        if (e.getType() == EntityType.WAY) {
            processWay((Way) es);
        }
    }
    for (String country : countryNames.keySet()) {
        List<Way> list = countryNames.get(country);
        for (Way w : list) {
            LatLon latLon = OsmMapUtils.getMathWeightCenterForNodes(w.getNodes());
            // LatLon latLon = w.getLatLon();
            Node node = new Node(latLon.getLatitude(), latLon.getLongitude(), id--);
            node.putTag("name", country);
            node.putTag("place", "country");
            storage.getRegisteredEntities().put(EntityId.valueOf(node), node);
        }
    }
    OsmStorageWriter writer = new OsmStorageWriter();
    writer.saveStorage(new FileOutputStream(write), storage, null, true);
}
Also used : OsmStorageWriter(net.osmand.osm.io.OsmStorageWriter) Entity(net.osmand.osm.edit.Entity) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(net.osmand.osm.edit.Node) ConsoleProgressImplementation(net.osmand.impl.ConsoleProgressImplementation) FileInputStream(java.io.FileInputStream) Way(net.osmand.osm.edit.Way) EntityId(net.osmand.osm.edit.Entity.EntityId) LatLon(net.osmand.data.LatLon) OsmBaseStorage(net.osmand.osm.io.OsmBaseStorage) FileOutputStream(java.io.FileOutputStream)

Example 8 with ConsoleProgressImplementation

use of net.osmand.impl.ConsoleProgressImplementation in project OsmAnd-tools by osmandapp.

the class GenerateDailyObf method generateCountry.

public static void generateCountry(String name, File targetObfZip, File[] array, long targetTimestamp, File nodesFile) throws IOException, SQLException, InterruptedException, XmlPullParserException {
    boolean exception = true;
    try {
        RTree.clearCache();
        IndexCreator ic = new IndexCreator(targetObfZip.getParentFile());
        ic.setIndexAddress(false);
        ic.setIndexPOI(true);
        ic.setIndexRouting(true);
        ic.setIndexMap(true);
        ic.setLastModifiedDate(targetTimestamp);
        ic.setGenerateLowLevelIndexes(false);
        ic.setDialects(DBDialect.SQLITE, DBDialect.SQLITE_IN_MEMORY);
        ic.setLastModifiedDate(targetTimestamp);
        ic.setRegionName(Algorithms.capitalizeFirstLetterAndLowercase(name));
        ic.setNodesDBFile(nodesFile);
        ic.setDeleteOsmDB(false);
        ic.generateIndexes(array, new ConsoleProgressImplementation(), null, MapZooms.parseZooms("13-14;15-"), new MapRenderingTypesEncoder(name), log, false, true);
        File targetFile = new File(targetObfZip.getParentFile(), ic.getMapFileName());
        targetFile.setLastModified(targetTimestamp);
        FileInputStream fis = new FileInputStream(targetFile);
        GZIPOutputStream gzout = new GZIPOutputStream(new FileOutputStream(targetObfZip));
        Algorithms.streamCopy(fis, gzout);
        fis.close();
        gzout.close();
        targetObfZip.setLastModified(targetTimestamp);
        targetFile.delete();
        exception = false;
    } finally {
        if (exception) {
            nodesFile.delete();
            nodesFile.deleteOnExit();
        }
    }
}
Also used : MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) IndexCreator(net.osmand.data.preparation.IndexCreator) ConsoleProgressImplementation(net.osmand.impl.ConsoleProgressImplementation) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 9 with ConsoleProgressImplementation

use of net.osmand.impl.ConsoleProgressImplementation in project OsmAnd-tools by osmandapp.

the class MainUtilities method generateObf.

private static void generateObf(String[] subArgsArray, IndexCreator ic) throws IOException, SQLException, InterruptedException, XmlPullParserException {
    String fn = DataExtractionSettings.getSettings().getMapRenderingTypesFile();
    String regionName = subArgsArray[0];
    MapRenderingTypesEncoder types = new MapRenderingTypesEncoder(fn, regionName);
    ic.generateIndexes(new File(subArgsArray[0]), new ConsoleProgressImplementation(), null, MapZooms.getDefault(), types, log);
}
Also used : MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) File(java.io.File) ConsoleProgressImplementation(net.osmand.impl.ConsoleProgressImplementation)

Example 10 with ConsoleProgressImplementation

use of net.osmand.impl.ConsoleProgressImplementation in project OsmAnd-tools by osmandapp.

the class GenerateRegionTags method process.

private static void process(File inputFile, File targetFile, OsmandRegions or) throws IOException, XmlPullParserException, XMLStreamException {
    InputStream fis = new FileInputStream(inputFile);
    if (inputFile.getName().endsWith(".gz")) {
        fis = new GZIPInputStream(fis);
    } else if (inputFile.getName().endsWith(".bz2")) {
        if (fis.read() != 'B' || fis.read() != 'Z') {
            throw new RuntimeException(// $NON-NLS-1$
            "The source stream must start with the characters BZ if it is to be read as a BZip2 stream.");
        }
        fis = new CBZip2InputStream(fis);
    }
    OsmBaseStorage bs = new OsmBaseStorage();
    bs.parseOSM(fis, new ConsoleProgressImplementation());
    LOG.info("File was read");
    iterateOverEntities(bs.getRegisteredEntities(), or);
    OsmStorageWriter w = new OsmStorageWriter();
    OutputStream output = new FileOutputStream(targetFile);
    if (targetFile.getName().endsWith(".gz")) {
        output = new GZIPOutputStream(output);
    } else if (targetFile.getName().endsWith(".bz2")) {
        output.write("BZ".getBytes());
        output = new CBZip2OutputStream(output);
    }
    LOG.info("Entities processed. About to save the file.");
    w.saveStorage(output, bs, null, true);
    output.close();
    fis.close();
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) OsmStorageWriter(net.osmand.osm.io.OsmStorageWriter) CBZip2OutputStream(org.apache.tools.bzip2.CBZip2OutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) GZIPInputStream(java.util.zip.GZIPInputStream) CBZip2InputStream(org.apache.tools.bzip2.CBZip2InputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OsmBaseStorage(net.osmand.osm.io.OsmBaseStorage) CBZip2InputStream(org.apache.tools.bzip2.CBZip2InputStream) OutputStream(java.io.OutputStream) CBZip2OutputStream(org.apache.tools.bzip2.CBZip2OutputStream) FileOutputStream(java.io.FileOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) ConsoleProgressImplementation(net.osmand.impl.ConsoleProgressImplementation) FileInputStream(java.io.FileInputStream)

Aggregations

ConsoleProgressImplementation (net.osmand.impl.ConsoleProgressImplementation)16 File (java.io.File)10 MapRenderingTypesEncoder (net.osmand.osm.MapRenderingTypesEncoder)10 FileInputStream (java.io.FileInputStream)8 FileOutputStream (java.io.FileOutputStream)8 IndexCreator (net.osmand.data.preparation.IndexCreator)5 OsmBaseStorage (net.osmand.osm.io.OsmBaseStorage)5 MapZooms (net.osmand.binary.MapZooms)4 LatLon (net.osmand.data.LatLon)4 OsmStorageWriter (net.osmand.osm.io.OsmStorageWriter)4 LinkedHashMap (java.util.LinkedHashMap)3 GZIPOutputStream (java.util.zip.GZIPOutputStream)3 Entity (net.osmand.osm.edit.Entity)3 EntityId (net.osmand.osm.edit.Entity.EntityId)3 Node (net.osmand.osm.edit.Node)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 RandomAccessFile (java.io.RandomAccessFile)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2