Search in sources :

Example 6 with LeafElement

use of rtree.LeafElement in project OsmAnd-tools by osmandapp.

the class ObfFileInMemory method writeRouteData.

private void writeRouteData(BinaryMapIndexWriter writer, TLongObjectHashMap<RouteDataObject> routeObjs, File fileToWrite) throws IOException, RTreeException, SQLException {
    File nonpackRtree = new File(fileToWrite.getParentFile(), "nonpackroute." + fileToWrite.getName() + ".rtree");
    File packRtree = new File(fileToWrite.getParentFile(), "packroute." + fileToWrite.getName() + ".rtree");
    RTree rtree = null;
    try {
        rtree = new RTree(nonpackRtree.getAbsolutePath());
        for (long key : routeObjs.keys()) {
            RouteDataObject obj = routeObjs.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) {
            IndexRouteCreator.writeBinaryRouteTree(root, rootBounds, rtree, writer, treeHeader, false);
            RouteWriteContext wc = new RouteWriteContext(null, treeHeader, null, routeObjs);
            IndexRouteCreator.writeBinaryMapBlock(root, rootBounds, rtree, writer, wc, false);
        }
    } finally {
        if (rtree != null) {
            RandomAccessFile file = rtree.getFileHdr().getFile();
            file.close();
        }
        nonpackRtree.delete();
        packRtree.delete();
        RTree.clearCache();
    }
}
Also used : Rect(rtree.Rect) RouteWriteContext(net.osmand.data.preparation.IndexRouteCreator.RouteWriteContext) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) BinaryFileReference(net.osmand.data.preparation.BinaryFileReference) SQLException(java.sql.SQLException) RTreeException(rtree.RTreeException) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) RouteDataObject(net.osmand.binary.RouteDataObject) RTree(rtree.RTree) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) LeafElement(rtree.LeafElement)

Aggregations

LeafElement (rtree.LeafElement)6 Rect (rtree.Rect)6 IOException (java.io.IOException)4 IllegalValueException (rtree.IllegalValueException)4 RTreeInsertException (rtree.RTreeInsertException)4 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 RandomAccessFile (java.io.RandomAccessFile)2 SQLException (java.sql.SQLException)2 RouteDataObject (net.osmand.binary.RouteDataObject)2 BinaryFileReference (net.osmand.data.preparation.BinaryFileReference)2 Node (net.osmand.osm.edit.Node)2 RTree (rtree.RTree)2 RTreeException (rtree.RTreeException)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 TLongArrayList (gnu.trove.list.array.TLongArrayList)1 PreparedStatement (java.sql.PreparedStatement)1 ArrayList (java.util.ArrayList)1 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)1