Search in sources :

Example 16 with RelationMember

use of net.osmand.osm.edit.Relation.RelationMember in project OsmAnd-tools by osmandapp.

the class AugmentedDiffsInspector method prepareRegions.

private void prepareRegions(Context ctx, Map<EntityId, Entity> ids, Map<String, Set<EntityId>> regionsMap, OsmandRegions osmandRegions) throws IOException {
    Map<EntityId, Set<String>> mp = new HashMap<Entity.EntityId, Set<String>>();
    for (Entity e : ids.values()) {
        if (e instanceof Node) {
            int y = MapUtils.get31TileNumberY(((Node) e).getLatitude());
            int x = MapUtils.get31TileNumberX(((Node) e).getLongitude());
            EntityId id = EntityId.valueOf(e);
            TreeSet<String> lst = new TreeSet<String>();
            mp.put(id, lst);
            if (osmandRegions == null) {
                addEntityToRegion(regionsMap, id, lst, DEFAULT_REGION);
            } else {
                List<BinaryMapDataObject> l = osmandRegions.query(x, y);
                for (BinaryMapDataObject b : l) {
                    if (osmandRegions.contain(b, x, y)) {
                        String dw = osmandRegions.getDownloadName(b);
                        if (!Algorithms.isEmpty(dw) && osmandRegions.isDownloadOfType(b, OsmandRegions.MAP_TYPE)) {
                            addEntityToRegion(regionsMap, id, lst, dw);
                        }
                    }
                }
            }
        }
    }
    // 2. add ways and complete ways with missing nodes
    for (Entity e : ids.values()) {
        if (e instanceof Way) {
            Way w = (Way) e;
            EntityId wid = EntityId.valueOf(w);
            TreeSet<String> lst = new TreeSet<String>();
            mp.put(wid, lst);
            for (EntityId it : w.getEntityIds()) {
                Set<String> countries = mp.get(it);
                for (String cnt : countries) {
                    regionsMap.get(cnt).add(wid);
                }
                lst.addAll(countries);
            }
            // complete ways with missing nodes
            for (EntityId it : w.getEntityIds()) {
                mp.get(it).addAll(lst);
                for (String s : lst) {
                    regionsMap.get(s).add(it);
                }
            }
        }
    }
    // 3. add relations (not complete with ways or nodes)
    for (Entity e : ids.values()) {
        if (e instanceof Relation) {
            Relation r = (Relation) e;
            EntityId rid = EntityId.valueOf(r);
            TreeSet<String> lst = new TreeSet<String>();
            mp.put(rid, lst);
            for (RelationMember it : r.getMembers()) {
                Set<String> countries = mp.get(it.getEntityId());
                for (String cnt : countries) {
                    regionsMap.get(cnt).add(rid);
                }
                lst.addAll(countries);
            }
        }
    }
}
Also used : Entity(net.osmand.osm.edit.Entity) TreeSet(java.util.TreeSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(net.osmand.osm.edit.Node) Way(net.osmand.osm.edit.Way) EntityId(net.osmand.osm.edit.Entity.EntityId) Relation(net.osmand.osm.edit.Relation) RelationMember(net.osmand.osm.edit.Relation.RelationMember) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) TreeSet(java.util.TreeSet)

Aggregations

Relation (net.osmand.osm.edit.Relation)16 RelationMember (net.osmand.osm.edit.Relation.RelationMember)16 Way (net.osmand.osm.edit.Way)11 Node (net.osmand.osm.edit.Node)9 Entity (net.osmand.osm.edit.Entity)7 EntityId (net.osmand.osm.edit.Entity.EntityId)7 LinkedHashMap (java.util.LinkedHashMap)5 TLongArrayList (gnu.trove.list.array.TLongArrayList)3 ArrayList (java.util.ArrayList)3 LinkedHashSet (java.util.LinkedHashSet)3 MultipolygonBuilder (net.osmand.data.MultipolygonBuilder)2 TransportStop (net.osmand.data.TransportStop)2 MapRulType (net.osmand.osm.MapRenderingTypes.MapRulType)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1