use of rtree.Element in project OsmAnd-tools by osmandapp.
the class IndexRouteCreator method writeBinaryMapBlock.
public static void writeBinaryMapBlock(rtree.Node parent, Rect parentBounds, RTree r, BinaryMapIndexWriter writer, RouteWriteContext wc, boolean basemap) throws IOException, RTreeException, SQLException {
Element[] e = parent.getAllElements();
RouteDataBlock.Builder dataBlock = null;
BinaryFileReference ref = wc.treeHeader.get(parent.getNodeIndex());
wc.wayMapIds.clear();
wc.wayMapIdsCache.clear();
wc.pointMapIds.clear();
for (int i = 0; i < parent.getTotalElements(); i++) {
if (e[i].getElementType() == rtree.Node.LEAF_NODE) {
long id = e[i].getPtr();
// IndexRouteCreator.SELECT_STAT;
// "SELECT types, pointTypes, pointIds, pointCoordinates, name FROM route_objects WHERE id = ?"
boolean retrieveObject = wc.retrieveObject(id);
if (retrieveObject) {
if (dataBlock == null) {
dataBlock = RouteDataBlock.newBuilder();
wc.stringTable.clear();
wc.wayMapIds.clear();
wc.wayMapIdsCache.clear();
wc.pointMapIds.clear();
}
int cid = wc.registerWayMapId(id);
TLongArrayList restrictions = wc.highwayRestrictions.get(id);
if (!basemap && restrictions != null) {
for (int li = 0; li < restrictions.size(); li++) {
Builder restriction = RestrictionData.newBuilder();
restriction.setFrom(cid);
int toId = wc.registerWayMapId(restrictions.get(li) >> 3);
restriction.setTo(toId);
restriction.setType((int) (restrictions.get(li) & 0x7));
dataBlock.addRestrictions(restriction.build());
}
}
RouteData routeData = writer.writeRouteData(cid, parentBounds.getMinX(), parentBounds.getMinY(), wc.wayTypes, wc.points.toArray(new RoutePointToWrite[wc.points.size()]), wc.wayNames, wc.stringTable, wc.pointNames, dataBlock, true, false);
if (routeData != null) {
dataBlock.addDataObjects(routeData);
}
} else {
if (wc.logMapDataWarn != null) {
// $NON-NLS-1$
wc.logMapDataWarn.error("Something goes wrong with id = " + id);
} else {
System.err.println("Something goes wrong with id = " + id);
}
}
}
}
if (dataBlock != null) {
IdTable.Builder idTable = IdTable.newBuilder();
long prev = 0;
for (int i = 0; i < wc.wayMapIds.size(); i++) {
idTable.addRouteId(wc.wayMapIds.getQuick(i) - prev);
prev = wc.wayMapIds.getQuick(i);
}
// if (WRITE_POINT_ID) {
// prev = 0;
// for (int i = 0; i < pointMapIds.size(); i++) {
// prev = pointMapIds.getQuick(i);
// }
// }
dataBlock.setIdTable(idTable.build());
writer.writeRouteDataBlock(dataBlock, wc.stringTable, 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, wc, basemap);
}
}
}
use of rtree.Element in project OsmAnd-tools by osmandapp.
the class IndexTransportCreator method writeBinaryTransportTree.
public void writeBinaryTransportTree(rtree.Node parent, RTree r, BinaryMapIndexWriter writer, PreparedStatement selectTransportStop, PreparedStatement selectTransportRouteStop, Map<Long, Long> transportRoutes, Map<String, Integer> stringTable) throws IOException, RTreeException, SQLException {
Element[] e = parent.getAllElements();
List<Long> routes = null;
for (int i = 0; i < parent.getTotalElements(); i++) {
Rect re = e[i].getRect();
if (e[i].getElementType() == rtree.Node.LEAF_NODE) {
long id = e[i].getPtr();
selectTransportStop.setLong(1, id);
selectTransportRouteStop.setLong(1, id);
ResultSet rs = selectTransportStop.executeQuery();
if (rs.next()) {
int x24 = (int) MapUtils.getTileNumberX(24, rs.getDouble(3));
int y24 = (int) MapUtils.getTileNumberY(24, rs.getDouble(2));
String name = rs.getString(4);
String nameEn = rs.getString(5);
if (nameEn != null && nameEn.equals(Junidecode.unidecode(name))) {
nameEn = null;
}
ResultSet rset = selectTransportRouteStop.executeQuery();
if (routes == null) {
routes = new ArrayList<Long>();
} else {
routes.clear();
}
while (rset.next()) {
Long route = transportRoutes.get(rset.getLong(1));
if (route == null) {
// $NON-NLS-1$
log.error("Something goes wrong with transport route id = " + rset.getLong(1));
} else {
routes.add(route);
}
}
rset.close();
writer.writeTransportStop(id, x24, y24, name, nameEn, stringTable, routes);
} else {
// $NON-NLS-1$
log.error("Something goes wrong with transport id = " + id);
}
} else {
long ptr = e[i].getPtr();
rtree.Node ns = r.getReadNode(ptr);
writer.startTransportTreeElement(re.getMinX(), re.getMaxX(), re.getMinY(), re.getMaxY());
writeBinaryTransportTree(ns, r, writer, selectTransportStop, selectTransportRouteStop, transportRoutes, stringTable);
writer.endWriteTransportTreeElement();
}
}
}
use of rtree.Element in project OsmAnd-tools by osmandapp.
the class SdTree method cleanUpRec.
/**
* This method adjusts all the seed node MBRs to the grown subtrees. It also delets the slot node and
* makes the root node of the underneath substree as the slot node.
*/
private // sd
Rect cleanUpRec(// sd
Node node, // sd
int level) throws NodeWriteException, FileNotFoundException, IllegalValueException, IOException, NodeReadException, RTreeException {
Element[] elmts = node.getAllElements();
if (level == slotLvl) {
// if level is the slot
if (elmts[0].getPtr() == Node.NOT_DEFINED) {
// this slot was never supplied a child node
node.deleteNode();
// a null rect
return new Rect();
} else {
// a slot that does have child node
// remove this slot node and make the parent element point to the child of this slot node
// sd
Node parentNode = chdNodes.getNode(fileHdr.getFile(), fileName, node.getParent(), fileHdr);
int index = parentNode.getElementIndex(node.getNodeIndex());
parentNode.modifyElement(index, elmts[0].getPtr());
// sd
Node subRoot = chdNodes.getNode(fileHdr.getFile(), fileName, elmts[0].getPtr(), fileHdr);
subRoot.setParent(node.getParent());
node.deleteNode();
return (subRoot.getNodeMBR());
}
// else
} else {
// it is not slot node but a seed node
// remebeer we may have a situation where we do not get any Rect from down below this node...we delete
// this node as well.
Rect rect = new Rect();
for (int i = node.getTotalElements() - 1; i > -1; i--) {
// for each element in this seed node
// sd
Node chNode = chdNodes.getNode(fileHdr.getFile(), fileName, elmts[i].getPtr(), fileHdr);
Rect chRect = cleanUpRec(chNode, level + 1);
// get child node's rect
rect.expandToInclude(chRect);
if (chRect.isNull()) {
// situation where child node does not have grown subtrees underneath
node.deleteElement(i, false);
} else {
// we do have a child Rect
node.modifyElement(i, chRect);
}
// else
}
// for
if (rect.isNull()) {
// situation where there are no grown subtrees underneath this node
node.deleteNode();
}
return rect;
}
// else
}
use of rtree.Element in project OsmAnd-tools by osmandapp.
the class IndexRouteCreator 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 IndexTransportCreator method calcBounds.
private 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;
}
Aggregations