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);
}
}
}
}
Aggregations