Search in sources :

Example 26 with BinaryMapDataObject

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));
            }
        }
    }
}
Also used : Entity(net.osmand.osm.edit.Entity) Node(net.osmand.osm.edit.Node) Way(net.osmand.osm.edit.Way) LinkedHashMap(java.util.LinkedHashMap) EntityId(net.osmand.osm.edit.Entity.EntityId) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) TreeSet(java.util.TreeSet)

Example 27 with BinaryMapDataObject

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

Example 28 with BinaryMapDataObject

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();
    }
}
Also used : Rect(rtree.Rect) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) BinaryFileReference(net.osmand.data.preparation.BinaryFileReference) SQLException(java.sql.SQLException) RTreeException(rtree.RTreeException) IOException(java.io.IOException) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) RandomAccessFile(java.io.RandomAccessFile) RTree(rtree.RTree) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) LeafElement(rtree.LeafElement)

Example 29 with BinaryMapDataObject

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;
}
Also used : BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) SearchFilter(net.osmand.binary.BinaryMapIndexReader.SearchFilter) MapIndex(net.osmand.binary.BinaryMapIndexReader.MapIndex) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Example 30 with BinaryMapDataObject

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;
}
Also used : WorldRegion(net.osmand.map.WorldRegion) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) MapZoomPair(net.osmand.binary.MapZooms.MapZoomPair) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) Map(java.util.Map)

Aggregations

BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)41 IOException (java.io.IOException)12 LinkedHashMap (java.util.LinkedHashMap)11 ArrayList (java.util.ArrayList)10 WorldRegion (net.osmand.map.WorldRegion)10 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)9 File (java.io.File)9 MapIndex (net.osmand.binary.BinaryMapIndexReader.MapIndex)8 TagValuePair (net.osmand.binary.BinaryMapIndexReader.TagValuePair)8 Paint (android.graphics.Paint)7 TIntArrayList (gnu.trove.list.array.TIntArrayList)7 LinkedList (java.util.LinkedList)7 OsmandRegions (net.osmand.map.OsmandRegions)7 HashMap (java.util.HashMap)6 TreeSet (java.util.TreeSet)6 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)6 QuadRect (net.osmand.data.QuadRect)6 TextPaint (android.text.TextPaint)5 RandomAccessFile (java.io.RandomAccessFile)5 Map (java.util.Map)5