use of net.osmand.data.preparation.IndexRouteCreator.RouteWriteContext 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();
}
}
Aggregations