use of net.osmand.binary.BinaryMapDataObject in project OsmAnd-tools by osmandapp.
the class GenerateRegionTags method iterateOverEntities.
private static void iterateOverEntities(Map<EntityId, Entity> ids, OsmandRegions or) throws IOException {
Map<EntityId, TreeSet<String>> mp = new LinkedHashMap<Entity.EntityId, TreeSet<String>>();
LOG.info("About to process " + ids.size() + " entities");
LOG.info("Processing nodes...");
long i = 0;
for (Entity e : ids.values()) {
if (e instanceof Node) {
i++;
printProgress(i, ids.size());
int y = MapUtils.get31TileNumberY(((Node) e).getLatitude());
int x = MapUtils.get31TileNumberX(((Node) e).getLongitude());
List<BinaryMapDataObject> l = or.query(x, y);
EntityId id = EntityId.valueOf(e);
TreeSet<String> lst = new TreeSet<String>();
mp.put(id, lst);
for (BinaryMapDataObject b : l) {
if (or.contain(b, x, y)) {
String dw = or.getDownloadName(b);
if (!Algorithms.isEmpty(dw) && or.isDownloadOfType(b, OsmandRegions.MAP_TYPE)) {
lst.add(dw);
}
}
}
if (!e.getTags().isEmpty()) {
e.putTag(MapRenderingTypesEncoder.OSMAND_REGION_NAME_TAG, serialize(lst));
}
}
}
LOG.info("Processing ways...");
for (Entity e : ids.values()) {
if (e instanceof Way) {
i++;
printProgress(i, ids.size());
Way w = (Way) e;
TreeSet<String> lst = new TreeSet<String>();
for (EntityId id : w.getEntityIds()) {
TreeSet<String> ls = mp.get(id);
if (ls != null) {
lst.addAll(ls);
}
}
if (!e.getTags().isEmpty()) {
e.putTag(MapRenderingTypesEncoder.OSMAND_REGION_NAME_TAG, serialize(lst));
}
}
}
}
use of net.osmand.binary.BinaryMapDataObject 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);
}
}
}
}
use of net.osmand.binary.BinaryMapDataObject in project OsmAnd-tools by osmandapp.
the class ObfFileInMemory method writeMapData.
private void writeMapData(BinaryMapIndexWriter writer, MapZoomPair mapZoomPair, TLongObjectHashMap<BinaryMapDataObject> objects, File fileToWrite, boolean doNotSimplify) throws IOException, RTreeException {
File nonpackRtree = new File(fileToWrite.getParentFile(), "nonpack" + mapZoomPair.getMinZoom() + "." + fileToWrite.getName() + ".rtree");
File packRtree = new File(fileToWrite.getParentFile(), "pack" + mapZoomPair.getMinZoom() + "." + fileToWrite.getName() + ".rtree");
RTree rtree = null;
try {
rtree = new RTree(nonpackRtree.getAbsolutePath());
for (long key : objects.keys()) {
BinaryMapDataObject obj = objects.get(key);
int minX = obj.getPoint31XTile(0);
int maxX = obj.getPoint31XTile(0);
int maxY = obj.getPoint31YTile(0);
int minY = obj.getPoint31YTile(0);
for (int i = 1; i < obj.getPointsLength(); i++) {
minX = Math.min(minX, obj.getPoint31XTile(i));
minY = Math.min(minY, obj.getPoint31YTile(i));
maxX = Math.max(maxX, obj.getPoint31XTile(i));
maxY = Math.max(maxY, obj.getPoint31YTile(i));
}
try {
rtree.insert(new LeafElement(new Rect(minX, minY, maxX, maxY), obj.getId()));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
rtree = AbstractIndexPartCreator.packRtreeFile(rtree, nonpackRtree.getAbsolutePath(), packRtree.getAbsolutePath());
TLongObjectHashMap<BinaryFileReference> treeHeader = new TLongObjectHashMap<BinaryFileReference>();
long rootIndex = rtree.getFileHdr().getRootIndex();
rtree.Node root = rtree.getReadNode(rootIndex);
Rect rootBounds = IndexUploader.calcBounds(root);
if (rootBounds != null) {
writer.startWriteMapLevelIndex(mapZoomPair.getMinZoom(), mapZoomPair.getMaxZoom(), rootBounds.getMinX(), rootBounds.getMaxX(), rootBounds.getMinY(), rootBounds.getMaxY());
IndexVectorMapCreator.writeBinaryMapTree(root, rootBounds, rtree, writer, treeHeader);
IndexUploader.writeBinaryMapBlock(root, rootBounds, rtree, writer, treeHeader, objects, mapZoomPair, doNotSimplify);
writer.endWriteMapLevelIndex();
}
} finally {
if (rtree != null) {
RandomAccessFile file = rtree.getFileHdr().getFile();
file.close();
}
nonpackRtree.delete();
packRtree.delete();
RTree.clearCache();
}
}
use of net.osmand.binary.BinaryMapDataObject in project OsmAnd-tools by osmandapp.
the class ObfFileInMemory method readBinaryMapData.
private TLongObjectHashMap<BinaryMapDataObject> readBinaryMapData(BinaryMapIndexReader index, MapIndex mi, int zoom) throws IOException {
final TLongObjectHashMap<BinaryMapDataObject> result = new TLongObjectHashMap<>();
final SearchRequest<BinaryMapDataObject> req = BinaryMapIndexReader.buildSearchRequest(MapUtils.get31TileNumberX(lonleft), MapUtils.get31TileNumberX(lonright), MapUtils.get31TileNumberY(lattop), MapUtils.get31TileNumberY(latbottom), zoom, new SearchFilter() {
@Override
public boolean accept(TIntArrayList types, MapIndex index) {
return true;
}
}, new ResultMatcher<BinaryMapDataObject>() {
@Override
public boolean publish(BinaryMapDataObject obj) {
result.put(obj.getId(), obj);
return false;
}
@Override
public boolean isCancelled() {
return false;
}
});
index.searchMapIndex(req, mi);
return result;
}
use of net.osmand.binary.BinaryMapDataObject in project OsmAnd-tools by osmandapp.
the class ObfRegionSplitter method splitRegionMapData.
private Map<String, Map<MapZoomPair, TLongObjectHashMap<BinaryMapDataObject>>> splitRegionMapData(ObfFileInMemory allMapObjects, OsmandRegions osmandRegions) throws IOException {
Map<String, Map<MapZoomPair, TLongObjectHashMap<BinaryMapDataObject>>> result = new HashMap<>();
for (MapZoomPair p : allMapObjects.getZooms()) {
TLongObjectHashMap<BinaryMapDataObject> objects = allMapObjects.get(p);
for (BinaryMapDataObject obj : objects.valueCollection()) {
int x = obj.getPoint31XTile(0);
int y = obj.getPoint31YTile(0);
List<BinaryMapDataObject> l = osmandRegions.query(x, y);
for (BinaryMapDataObject b : l) {
if (osmandRegions.contain(b, x, y)) {
String dw = osmandRegions.getDownloadName(b);
WorldRegion wr = osmandRegions.getRegionDataByDownloadName(dw);
if (dw == null || wr == null) {
continue;
}
if (!Algorithms.isEmpty(dw) && wr.isRegionMapDownload()) {
Map<MapZoomPair, TLongObjectHashMap<BinaryMapDataObject>> mp = result.get(dw);
if (mp == null) {
mp = new LinkedHashMap<>();
result.put(dw, mp);
}
TLongObjectHashMap<BinaryMapDataObject> list = mp.get(p);
if (list == null) {
list = new TLongObjectHashMap<>();
mp.put(p, list);
}
list.put(obj.getId(), obj);
}
}
}
}
}
return result;
}
Aggregations