Search in sources :

Example 1 with TagsTransformer

use of net.osmand.data.preparation.TagsTransformer 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

TLongArrayList (gnu.trove.list.array.TLongArrayList)1 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 TagsTransformer (net.osmand.data.preparation.TagsTransformer)1 OsmandRegions (net.osmand.map.OsmandRegions)1 MapRenderingTypesEncoder (net.osmand.osm.MapRenderingTypesEncoder)1 Entity (net.osmand.osm.edit.Entity)1 EntityId (net.osmand.osm.edit.Entity.EntityId)1 Relation (net.osmand.osm.edit.Relation)1 Way (net.osmand.osm.edit.Way)1 OsmBaseStorage (net.osmand.osm.io.OsmBaseStorage)1 OsmStorageWriter (net.osmand.osm.io.OsmStorageWriter)1