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