Search in sources :

Example 1 with OsmStorageWriter

use of net.osmand.osm.io.OsmStorageWriter 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 2 with OsmStorageWriter

use of net.osmand.osm.io.OsmStorageWriter in project OsmAnd-tools by osmandapp.

the class OceanTilesCreator method createJOSMFile.

public static void createJOSMFile(String[] args) throws XMLStreamException, IOException {
    String fileLocation = args.length == 0 ? "oceanTiles.osm" : args[0];
    int z = TILE_ZOOMLEVEL;
    BasemapProcessor bmp = new BasemapProcessor();
    bmp.constructBitSetInfo(args.length > 1 ? args[1] : null);
    OsmBaseStorage st = new OsmBaseStorage();
    Set<Entity.EntityId> s = new LinkedHashSet();
    TLongHashSet nodeIds = new TLongHashSet();
    int minzoom = 4;
    BasemapProcessor.SimplisticQuadTree quadTree = bmp.constructTilesQuadTree(z);
    for (int zm = minzoom; zm <= z; zm++) {
        int pz = 1 << zm;
        for (int x = 0; x < pz; x++) {
            for (int y = 0; y < pz; y++) {
                // if((quadTree.getOrCreateSubTree(i, j, z).seaCharacteristic < 0.9 && !bmp.isWaterTile(i, j, z))||
                // bmp.isLandTile(i, j, z) ) {
                boolean parentWater = bmp.isWaterTile(x >> 1, y >> 1, zm - 1);
                boolean parentLand = bmp.isLandTile(x >> 1, y >> 1, zm - 1);
                if (zm > minzoom && (parentLand || parentWater)) {
                    continue;
                }
                boolean landTile = bmp.isLandTile(x, y, zm);
                boolean waterTile = bmp.isWaterTile(x, y, zm);
                if (waterTile || landTile) {
                    Way w = new Way(-getNodeId(x, y, zm));
                    addNode(w, nodeIds, x, y, zm);
                    addNode(w, nodeIds, x, y + 1, zm);
                    addNode(w, nodeIds, x + 1, y + 1, zm);
                    addNode(w, nodeIds, x + 1, y, zm);
                    addNode(w, nodeIds, x, y, zm);
                    if (waterTile) {
                        w.putTag("natural", "water");
                    } else if (landTile) {
                        w.putTag("landuse", "grass");
                    }
                    w.putTag("name", x + " " + y + " " + zm + " " + (waterTile ? 1 : 0));
                    s.addAll(w.getEntityIds());
                    s.add(Entity.EntityId.valueOf(w));
                    st.registerEntity(w, null);
                }
            }
        }
    }
    for (long l : nodeIds.toArray()) {
        st.registerEntity(getNode(l), null);
    }
    new OsmStorageWriter().saveStorage(new FileOutputStream(fileLocation), st, s, true);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) OsmStorageWriter(net.osmand.osm.io.OsmStorageWriter) Way(net.osmand.osm.edit.Way) OsmBaseStorage(net.osmand.osm.io.OsmBaseStorage) TLongHashSet(gnu.trove.set.hash.TLongHashSet) FileOutputStream(java.io.FileOutputStream)

Example 3 with OsmStorageWriter

use of net.osmand.osm.io.OsmStorageWriter in project OsmAnd-tools by osmandapp.

the class AugmentedDiffsInspector method writeFile.

private File writeFile(File targetDir, String prefix, Map<EntityId, Entity> octx, Set<EntityId> oset, Map<EntityId, Entity> nctx, Set<EntityId> nset, long lastModified) throws XMLStreamException, IOException, FileNotFoundException {
    List<Node> nodes = new ArrayList<Node>();
    List<Way> ways = new ArrayList<Way>();
    List<Relation> relations = new ArrayList<Relation>();
    groupObjects(octx, oset, nodes, ways, relations);
    groupObjects(nctx, nset, nodes, ways, relations);
    File f = new File(targetDir, prefix + ".osm.gz");
    FileOutputStream fous = new FileOutputStream(f);
    GZIPOutputStream gz = new GZIPOutputStream(fous);
    new OsmStorageWriter().writeOSM(gz, new HashMap<Entity.EntityId, EntityInfo>(), nodes, ways, relations, true);
    gz.close();
    fous.close();
    f.setLastModified(lastModified);
    return f;
}
Also used : OsmStorageWriter(net.osmand.osm.io.OsmStorageWriter) Node(net.osmand.osm.edit.Node) ArrayList(java.util.ArrayList) Way(net.osmand.osm.edit.Way) EntityId(net.osmand.osm.edit.Entity.EntityId) Relation(net.osmand.osm.edit.Relation) GZIPOutputStream(java.util.zip.GZIPOutputStream) EntityInfo(net.osmand.osm.edit.EntityInfo) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 4 with OsmStorageWriter

use of net.osmand.osm.io.OsmStorageWriter 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)

Example 5 with OsmStorageWriter

use of net.osmand.osm.io.OsmStorageWriter in project OsmAnd-tools by osmandapp.

the class FixBasemapRoads method process.

private void process(File read, File write, List<File> relationFiles) throws IOException, XMLStreamException, XmlPullParserException, SQLException {
    MapRenderingTypesEncoder renderingTypes = new MapRenderingTypesEncoder("basemap");
    OsmandRegions or = prepareRegions();
    TagsTransformer transformer = new TagsTransformer();
    for (File relFile : relationFiles) {
        LOG.info("Parse relations file " + relFile.getName());
        OsmBaseStorage storage = parseOsmFile(relFile);
        int total = 0;
        for (EntityId e : storage.getRegisteredEntities().keySet()) {
            if (e.getType() == EntityType.RELATION) {
                total++;
                if (total % 1000 == 0) {
                    LOG.info("Processed " + total + " relations");
                }
                Relation es = (Relation) storage.getRegisteredEntities().get(e);
                transformer.handleRelationPropogatedTags(es, renderingTypes, null, EntityConvertApplyType.MAP);
            }
        }
    }
    LOG.info("Parse main file " + read.getName());
    OsmBaseStorage storage = parseOsmFile(read);
    Map<EntityId, Entity> entities = new HashMap<EntityId, Entity>(storage.getRegisteredEntities());
    int total = 0;
    for (EntityId e : entities.keySet()) {
        if (e.getType() == EntityType.WAY) {
            Way es = (Way) storage.getRegisteredEntities().get(e);
            total++;
            if (total % 1000 == 0) {
                LOG.info("Processed " + total + " ways");
            }
            addRegionTag(or, es);
            transformer.addPropogatedTags(es);
            Map<String, String> ntags = renderingTypes.transformTags(es.getModifiableTags(), EntityType.WAY, EntityConvertApplyType.MAP);
            if (es.getModifiableTags() != ntags) {
                es.getModifiableTags().putAll(ntags);
            }
            processWay(es);
        }
    }
    List<EntityId> toWrite = new ArrayList<EntityId>();
    processRegion(toWrite);
    OsmStorageWriter writer = new OsmStorageWriter();
    LOG.info("Writing file... ");
    writer.saveStorage(new FileOutputStream(write), storage, toWrite, true);
    LOG.info("DONE");
}
Also used : OsmStorageWriter(net.osmand.osm.io.OsmStorageWriter) Entity(net.osmand.osm.edit.Entity) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) TagsTransformer(net.osmand.data.preparation.TagsTransformer) ArrayList(java.util.ArrayList) TLongArrayList(gnu.trove.list.array.TLongArrayList) Way(net.osmand.osm.edit.Way) EntityId(net.osmand.osm.edit.Entity.EntityId) Relation(net.osmand.osm.edit.Relation) MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) OsmandRegions(net.osmand.map.OsmandRegions) OsmBaseStorage(net.osmand.osm.io.OsmBaseStorage) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Aggregations

FileOutputStream (java.io.FileOutputStream)8 OsmStorageWriter (net.osmand.osm.io.OsmStorageWriter)8 OsmBaseStorage (net.osmand.osm.io.OsmBaseStorage)6 EntityId (net.osmand.osm.edit.Entity.EntityId)5 Way (net.osmand.osm.edit.Way)5 FileInputStream (java.io.FileInputStream)4 ConsoleProgressImplementation (net.osmand.impl.ConsoleProgressImplementation)4 Entity (net.osmand.osm.edit.Entity)4 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 LatLon (net.osmand.data.LatLon)3 Node (net.osmand.osm.edit.Node)3 File (java.io.File)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 ArrayList (java.util.ArrayList)2 GZIPOutputStream (java.util.zip.GZIPOutputStream)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 EntityInfo (net.osmand.osm.edit.EntityInfo)2 Relation (net.osmand.osm.edit.Relation)2