Search in sources :

Example 1 with RTreeException

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

the class SdTree method seed.

/**
 *     Start seeding - take the root node, copy it to this tree, keep on copying until the slot level.
 *     This method overwrites the root irrespective of its existance or nonexistence.
 */
private void seed() throws RTreeException {
    try {
        long sdingRoot = sdingTree.getFileHdr().getRootIndex();
        // somehow remove all the nodes of this tree from the cache and since we have a write lock
        // nobody can get this tree's nodes on to the buufer if we don't
        Node sdingNode = sdingTree.getReadNode(sdingRoot);
        seedRec(sdingNode, // sd
        chdNodes.getNode(// sd
        fileHdr.getFile(), // sd
        fileName, // sd
        Node.NOT_DEFINED, sdingNode.getElementType(), fileHdr), 0);
    } catch (Exception e) {
        e.printStackTrace();
        throw new RTreeException(e.getMessage());
    }
}
Also used : RTreeException(rtree.RTreeException) Node(rtree.Node) RTreeException(rtree.RTreeException) NodeFullException(rtree.NodeFullException) IOException(java.io.IOException) NodeReadException(rtree.NodeReadException) FileNotFoundException(java.io.FileNotFoundException) IllegalValueException(rtree.IllegalValueException) NodeWriteException(rtree.NodeWriteException)

Example 2 with RTreeException

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

the class SdTree method growLeaf.

public void growLeaf(Element elmt) throws RTreeException {
    if (slotLvl == Node.NOT_DEFINED) {
        try {
            insert(elmt);
        } catch (Exception e) {
            throw new RTreeException(e.getMessage());
        }
    } else {
        fileHdr.lockWrite();
        try {
            long root = fileHdr.getRootIndex();
            // Long slotIndex = null;
            LongWraper slotIndex = new LongWraper();
            // sd
            Node node = this.chooseLeaf(elmt, slotIndex);
            if (slotIndex == null)
                throw new NullPointerException();
            long nodeParent = node.getParent();
            Node[] newNodes = new Node[2];
            try {
                // if another insert is possible
                node.insertElement(elmt);
                newNodes[0] = node;
                newNodes[1] = null;
            } catch (NodeFullException e) {
                // if another insert is not possible
                newNodes = node.splitNode(elmt, slotIndex.val);
            }
            Node newRoot = adjustTree(newNodes, slotIndex.val);
            // if we got a new root node then we have to set the slot's child to point to this new root
            if (newRoot != null) {
                // sd
                Node slot = chdNodes.getNode(fileHdr.getFile(), fileName, newRoot.getParent(), fileHdr);
                slot.modifyElement(0, newRoot.getNodeIndex());
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new RTreeException(e.getMessage());
        } finally {
            fileHdr.unlock();
        }
    }
}
Also used : RTreeException(rtree.RTreeException) Node(rtree.Node) NodeFullException(rtree.NodeFullException) RTreeException(rtree.RTreeException) NodeFullException(rtree.NodeFullException) IOException(java.io.IOException) NodeReadException(rtree.NodeReadException) FileNotFoundException(java.io.FileNotFoundException) IllegalValueException(rtree.IllegalValueException) NodeWriteException(rtree.NodeWriteException)

Example 3 with RTreeException

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

the class SdTree method cleanUp.

/**
 * The clean up pahse is the last method that should be called after all the data have been grown.
 * This method basically adjusts all the slot nodes after all the insertions are made
 */
public void cleanUp() throws RTreeException {
    try {
        fileHdr.lockWrite();
        if (slotLvl == Node.NOT_DEFINED)
            return;
        long root = fileHdr.getRootIndex();
        // sd
        Node node = chdNodes.getNode(fileHdr.getFile(), fileName, root, fileHdr);
        cleanUpRec(node, 0);
    } catch (Exception e) {
        e.printStackTrace();
        throw new RTreeException(e.getMessage());
    } finally {
        fileHdr.unlock();
    }
}
Also used : RTreeException(rtree.RTreeException) Node(rtree.Node) RTreeException(rtree.RTreeException) NodeFullException(rtree.NodeFullException) IOException(java.io.IOException) NodeReadException(rtree.NodeReadException) FileNotFoundException(java.io.FileNotFoundException) IllegalValueException(rtree.IllegalValueException) NodeWriteException(rtree.NodeWriteException)

Example 4 with RTreeException

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

the class IndexRouteCreator method writeBinaryRouteIndex.

public void writeBinaryRouteIndex(File fl, BinaryMapIndexWriter writer, String regionName, boolean generateLowLevel) throws IOException, SQLException {
    closePreparedStatements(mapRouteInsertStat);
    if (basemapRouteInsertStat != null) {
        closePreparedStatements(basemapRouteInsertStat);
    }
    mapConnection.commit();
    try {
        writer.startWriteRouteIndex(regionName);
        // write map encoding rules
        // save position
        writer.writeRouteEncodingRules(routeTypes.getEncodingRuleTypes());
        RandomAccessFile raf = writer.getRaf();
        writer.flush();
        long fp = raf.getFilePointer();
        // 1st write
        writeRouteSections(writer);
        String fname = null;
        if (baserouteTree != null) {
            // prewrite end of file to read it
            writer.simulateWriteEndRouteIndex();
            writer.preclose();
            writer.flush();
            // use file to recalulate tree
            raf.seek(0);
            appendMissingRoadsForBaseMap(mapConnection, new BinaryMapIndexReader(raf, fl));
            // repack
            fname = baserouteTree.getFileName();
            baserouteTree = packRtreeFile(baserouteTree, fname, fname + "p");
            // seek to previous position
            raf.seek(fp);
            raf.getChannel().truncate(fp);
            // 2nd write
            writeRouteSections(writer);
        }
        writer.endWriteRouteIndex();
        writer.flush();
        if (generateLowLevel) {
            baserouteTree = null;
            new File(fname + "p").delete();
        }
    } catch (RTreeException e) {
        throw new IllegalStateException(e);
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) RTreeException(rtree.RTreeException) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 5 with RTreeException

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

the class IndexRouteCreator method createDatabaseStructure.

public void createDatabaseStructure(Connection mapConnection, DBDialect dialect, String rtreeMapIndexNonPackFileName) throws SQLException, IOException {
    this.mapConnection = mapConnection;
    Statement stat = mapConnection.createStatement();
    stat.executeUpdate("create table " + TABLE_ROUTE + CREATETABLE);
    stat.executeUpdate("create table " + TABLE_BASEROUTE + CREATETABLE);
    stat.executeUpdate("create index " + TABLE_ROUTE + CREATE_IND);
    stat.executeUpdate("create index " + TABLE_BASEROUTE + CREATE_IND);
    stat.close();
    mapRouteInsertStat = createStatementRouteObjInsert(mapConnection, false);
    try {
        routeTree = new RTree(rtreeMapIndexNonPackFileName);
    } catch (RTreeException e) {
        throw new IOException(e);
    }
    pStatements.put(mapRouteInsertStat, 0);
    if (generateLowLevel) {
        basemapRouteInsertStat = createStatementRouteObjInsert(mapConnection, true);
        try {
            baserouteTree = new RTree(rtreeMapIndexNonPackFileName + "b");
        } catch (RTreeException e) {
            throw new IOException(e);
        }
        pStatements.put(basemapRouteInsertStat, 0);
    }
}
Also used : RTreeException(rtree.RTreeException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) RTree(rtree.RTree) IOException(java.io.IOException)

Aggregations

RTreeException (rtree.RTreeException)15 IOException (java.io.IOException)12 File (java.io.File)8 RTree (rtree.RTree)7 RandomAccessFile (java.io.RandomAccessFile)6 FileNotFoundException (java.io.FileNotFoundException)5 IllegalValueException (rtree.IllegalValueException)5 PreparedStatement (java.sql.PreparedStatement)4 Node (rtree.Node)4 NodeFullException (rtree.NodeFullException)4 NodeReadException (rtree.NodeReadException)4 NodeWriteException (rtree.NodeWriteException)4 Rect (rtree.Rect)4 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)3 SQLException (java.sql.SQLException)3 LeafElement (rtree.LeafElement)3 Statement (java.sql.Statement)2 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)2 BinaryFileReference (net.osmand.data.preparation.BinaryFileReference)2 JSchException (com.jcraft.jsch.JSchException)1