use of rtree.Element in project OsmAnd-tools by osmandapp.
the class IndexVectorMapCreator method calcBounds.
public Rect calcBounds(rtree.Node n) {
Rect r = null;
Element[] e = n.getAllElements();
for (int i = 0; i < n.getTotalElements(); i++) {
Rect re = e[i].getRect();
if (r == null) {
try {
r = new Rect(re.getMinX(), re.getMinY(), re.getMaxX(), re.getMaxY());
} catch (IllegalValueException ex) {
}
} else {
r.expandToInclude(re);
}
}
return r;
}
use of rtree.Element in project OsmAnd-tools by osmandapp.
the class IndexVectorMapCreator method writeBinaryMapBlock.
public void writeBinaryMapBlock(rtree.Node parent, Rect parentBounds, RTree r, BinaryMapIndexWriter writer, PreparedStatement selectData, TLongObjectHashMap<BinaryFileReference> bounds, Map<String, Integer> tempStringTable, LinkedHashMap<MapRulType, String> tempNames, MapZoomPair level) throws IOException, RTreeException, SQLException {
Element[] e = parent.getAllElements();
MapDataBlock.Builder dataBlock = null;
BinaryFileReference ref = bounds.get(parent.getNodeIndex());
long baseId = 0;
for (int i = 0; i < parent.getTotalElements(); i++) {
if (e[i].getElementType() == rtree.Node.LEAF_NODE) {
long id = e[i].getPtr();
selectData.setLong(1, id);
// selectData = mapConnection.prepareStatement("SELECT area, coordinates, innerPolygons, types, additionalTypes, name FROM binary_map_objects WHERE id = ?");
ResultSet rs = selectData.executeQuery();
if (rs.next()) {
long cid = convertGeneratedIdToObfWrite(id);
if (dataBlock == null) {
baseId = cid;
dataBlock = writer.createWriteMapDataBlock(baseId);
tempStringTable.clear();
}
tempNames.clear();
decodeNames(rs.getString(6), tempNames);
byte[] types = rs.getBytes(4);
int[] typeUse = new int[types.length / 2];
for (int j = 0; j < types.length; j += 2) {
int ids = Algorithms.parseSmallIntFromBytes(types, j);
typeUse[j / 2] = renderingTypes.getTypeByInternalId(ids).getTargetId();
}
byte[] addTypes = rs.getBytes(5);
int[] addtypeUse = null;
if (addTypes != null) {
addtypeUse = new int[addTypes.length / 2];
for (int j = 0; j < addTypes.length; j += 2) {
int ids = Algorithms.parseSmallIntFromBytes(addTypes, j);
addtypeUse[j / 2] = renderingTypes.getTypeByInternalId(ids).getTargetId();
}
}
MapData mapData = writer.writeMapData(cid - baseId, parentBounds.getMinX(), parentBounds.getMinY(), rs.getBoolean(1), rs.getBytes(2), rs.getBytes(3), typeUse, addtypeUse, tempNames, null, tempStringTable, dataBlock, level.getMaxZoom() > 15);
if (mapData != null) {
dataBlock.addDataObjects(mapData);
}
} else {
// $NON-NLS-1$
logMapDataWarn.error("Something goes wrong with id = " + id);
}
}
}
if (dataBlock != null) {
writer.writeMapDataBlock(dataBlock, tempStringTable, ref);
}
for (int i = 0; i < parent.getTotalElements(); i++) {
if (e[i].getElementType() != rtree.Node.LEAF_NODE) {
long ptr = e[i].getPtr();
rtree.Node ns = r.getReadNode(ptr);
writeBinaryMapBlock(ns, e[i].getRect(), r, writer, selectData, bounds, tempStringTable, tempNames, level);
}
}
}
use of rtree.Element in project OsmAnd-tools by osmandapp.
the class SdTree method seedRec.
/**
* @param sdingNode The seeding node from which to copy (source).
* @param level The height at which this node falls in the tree.
*/
private // sd
void seedRec(// sd
Node sdingNode, // sd
Node sdNode, // sd
int level) throws Exception {
if (sdingNode.getElementType() == Node.LEAF_NODE)
throw new IllegalArgumentException("SdTree.seedRec : Cannot seed a leaf node");
// make the child nodes before hand so that we know their indices in file
// sd
Node[] chNodes = null;
if (// we do not need to alocate new nodes if we are at slot level
level != slotLvl)
// sd
chNodes = new Node[sdingNode.getTotalElements()];
Element[] elmts = sdingNode.getAllElements();
// elements for non-slot levels
Element[] newElmts;
if (level != slotLvl)
// non slots have multiple elements
newElmts = new Element[sdingNode.getTotalElements()];
else {
// slot has only one element
newElmts = new Element[1];
// element for slot level
newElmts[0] = new NonLeafElement(new Rect(), Node.NOT_DEFINED);
}
for (int i = 0; i < sdingNode.getTotalElements(); i++) {
if (level != slotLvl) {
// we do not seed leaf elements
newElmts[i] = (NonLeafElement) ((NonLeafElement) elmts[i]).clone();
chNodes[i] = // sd
chdNodes.getNode(// sd
fileHdr.getFile(), // sd
fileName, // sd
sdNode.getNodeIndex(), sdingNode.getElementType(), fileHdr);
// update the child pointers for new node
newElmts[i].setPtr(chNodes[i].getNodeIndex());
seedRec(sdingTree.getReadNode(elmts[i].getPtr()), chNodes[i], level + 1);
} else {
// this is the slot level
/*What we do here is that we put only one element into the slot node instead of all the elements.
This would result in a single element in the node which represents all the seding node elements
with a null pointer.
*/
newElmts[0].getRect().expandToInclude(elmts[i].getRect());
}
// else
}
// for
// copy the non-slot elements now //sd
sdNode.insertElement(newElmts, false);
}
use of rtree.Element in project OsmAnd-tools by osmandapp.
the class SdTree method chooseLeaf.
/**
* This method is a copy of <code>RTree.chooseLeaf</code> with minor modifications.
* In fact there are number of changes , most important is that this method will just not get the new
* Node, but also change the parent's (slot node) child pointer.
* Remeber that if there are no leaf node associated with a slot selected, this method creates one
* returns this new Node after doing the process described above.
* but if there is a leaf node present then that node is returned just as in simple rtrees.
*/
private // sd
Node chooseLeaf(// sd
Element elmt, // sd
LongWraper slotIndex) throws RTreeException, IOException {
/*TODO : we may also have to traverse non seed node, i.e grown nodes.*/
try {
// get the root node
long root = fileHdr.getRootIndex();
int level = 0;
// sd
Node sltNode = chdNodes.getNode(fileHdr.getFile(), fileName, root, fileHdr);
// repeat till you reach a slot node
while (sltNode.getElementType() != Node.LEAF_NODE) {
// (level != slotLvl){
// get the best fitting rect from the node
Element nextElmt = sltNode.getLeastEnlargement(elmt);
if (level == slotLvl) {
slotIndex.val = sltNode.getNodeIndex();
if (nextElmt.getPtr() == Node.NOT_DEFINED) {
// the first leaf node for this slot node
Node rtNode = // sd
chdNodes.getNode(// sd
fileHdr.getFile(), // sd
fileName, // sd
sltNode.getNodeIndex(), Node.LEAF_NODE, fileHdr);
sltNode.modifyElement(0, rtNode.getNodeIndex());
nextElmt.setPtr(rtNode.getNodeIndex());
return rtNode;
}
}
// if are here then we are not at a slot that has no childs
// sd
sltNode = chdNodes.getNode(fileHdr.getFile(), fileName, nextElmt.getPtr(), fileHdr);
level++;
}
// if we are here then we reached a proper leaf node rather than a slot node
return sltNode;
} catch (Exception e) {
e.printStackTrace();
throw new RTreeException(e.getMessage());
}
}
Aggregations