use of rtree.RTree in project OsmAnd-tools by osmandapp.
the class IndexUploader method copyMapIndex.
private static void copyMapIndex(File roadOnlyFile, MapIndex part, BinaryMapIndexReader index, CodedOutputStream ous, RandomAccessFile routf) throws IOException, RTreeException {
final List<MapRoot> rts = part.getRoots();
BinaryMapIndexWriter writer = new BinaryMapIndexWriter(routf, ous);
writer.startWriteMapIndex(part.getName());
boolean first = true;
for (MapRoot r : rts) {
final TLongObjectHashMap<BinaryMapDataObject> objects = new TLongObjectHashMap<BinaryMapDataObject>();
File nonpackRtree = new File(roadOnlyFile.getParentFile(), "nonpack" + r.getMinZoom() + "." + roadOnlyFile.getName() + ".rtree");
File packRtree = new File(roadOnlyFile.getParentFile(), "pack" + r.getMinZoom() + "." + roadOnlyFile.getName() + ".rtree");
RTree rtree = null;
try {
rtree = new RTree(nonpackRtree.getAbsolutePath());
final SearchRequest<BinaryMapDataObject> req = buildSearchRequest(r, objects, rtree);
index.searchMapIndex(req, part);
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 = calcBounds(root);
if (rootBounds != null) {
if (first) {
writer.writeMapEncodingRules(part.decodingRules);
first = false;
}
writer.startWriteMapLevelIndex(r.getMinZoom(), r.getMaxZoom(), rootBounds.getMinX(), rootBounds.getMaxX(), rootBounds.getMinY(), rootBounds.getMaxY());
IndexVectorMapCreator.writeBinaryMapTree(root, rootBounds, rtree, writer, treeHeader);
writeBinaryMapBlock(root, rootBounds, rtree, writer, treeHeader, objects, r.getMapZoom(), false);
writer.endWriteMapLevelIndex();
}
} finally {
if (rtree != null) {
RandomAccessFile file = rtree.getFileHdr().getFile();
file.close();
}
nonpackRtree.delete();
packRtree.delete();
RTree.clearCache();
}
}
writer.endWriteMapIndex();
}
use of rtree.RTree 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);
}
}
use of rtree.RTree in project OsmAnd-tools by osmandapp.
the class IndexTransportCreator method createDatabaseStructure.
public void createDatabaseStructure(Connection conn, DBDialect dialect, String rtreeStopsFileName) throws SQLException, IOException {
Statement stat = conn.createStatement();
stat.executeUpdate("create table transport_route (id bigint primary key, type varchar(1024), operator varchar(1024)," + "ref varchar(1024), name varchar(1024), name_en varchar(1024), dist int, color varchar(1024))");
stat.executeUpdate("create index transport_route_id on transport_route (id)");
stat.executeUpdate("create table transport_route_stop (stop bigint, route bigint, ord int, primary key (route, ord))");
stat.executeUpdate("create index transport_route_stop_stop on transport_route_stop (stop)");
stat.executeUpdate("create index transport_route_stop_route on transport_route_stop (route)");
stat.executeUpdate("create table transport_route_geometry (geometry bytes, route bigint)");
stat.executeUpdate("create index transport_route_geometry_route on transport_route_geometry (route)");
stat.executeUpdate("create table transport_stop (id bigint primary key, latitude double, longitude double, name varchar(1024), name_en varchar(1024))");
stat.executeUpdate("create index transport_stop_id on transport_stop (id)");
stat.executeUpdate("create index transport_stop_location on transport_stop (latitude, longitude)");
// if(dialect == DBDialect.SQLITE){
// stat.execute("PRAGMA user_version = " + IndexConstants.TRANSPORT_TABLE_VERSION); //$NON-NLS-1$
// }
stat.close();
try {
File file = new File(rtreeStopsFileName);
if (file.exists()) {
file.delete();
}
transportStopsTree = new RTree(file.getAbsolutePath());
} catch (RTreeException e) {
throw new IOException(e);
}
transRouteStat = conn.prepareStatement("insert into transport_route(id, type, operator, ref, name, name_en, dist, color) values(?, ?, ?, ?, ?, ?, ?, ?)");
transRouteStopsStat = conn.prepareStatement("insert into transport_route_stop(route, stop, ord) values(?, ?, ?)");
transStopsStat = conn.prepareStatement("insert into transport_stop(id, latitude, longitude, name, name_en) values(?, ?, ?, ?, ?)");
transRouteGeometryStat = conn.prepareStatement("insert into transport_route_geometry(route, geometry) values(?, ?)");
pStatements.put(transRouteStat, 0);
pStatements.put(transRouteStopsStat, 0);
pStatements.put(transStopsStat, 0);
pStatements.put(transRouteGeometryStat, 0);
}
use of rtree.RTree in project OsmAnd-tools by osmandapp.
the class IndexVectorMapCreator method writeBinaryMapIndex.
public void writeBinaryMapIndex(BinaryMapIndexWriter writer, String regionName) throws IOException, SQLException {
closePreparedStatements(mapBinaryStat, mapLowLevelBinaryStat);
mapConnection.commit();
try {
writer.startWriteMapIndex(regionName);
// write map encoding rules
writer.writeMapEncodingRules(renderingTypes.getEncodingRuleTypes());
PreparedStatement selectData = mapConnection.prepareStatement("SELECT area, coordinates, innerPolygons, types, additionalTypes, name FROM binary_map_objects WHERE id = ?");
// write map levels and map index
TLongObjectHashMap<BinaryFileReference> treeHeader = new TLongObjectHashMap<BinaryFileReference>();
for (int i = 0; i < mapZooms.size(); i++) {
RTree rtree = mapTree[i];
long rootIndex = rtree.getFileHdr().getRootIndex();
rtree.Node root = rtree.getReadNode(rootIndex);
Rect rootBounds = calcBounds(root);
if (rootBounds != null) {
writer.startWriteMapLevelIndex(mapZooms.getLevel(i).getMinZoom(), mapZooms.getLevel(i).getMaxZoom(), rootBounds.getMinX(), rootBounds.getMaxX(), rootBounds.getMinY(), rootBounds.getMaxY());
writeBinaryMapTree(root, rootBounds, rtree, writer, treeHeader);
writeBinaryMapBlock(root, rootBounds, rtree, writer, selectData, treeHeader, new LinkedHashMap<String, Integer>(), new LinkedHashMap<MapRulType, String>(), mapZooms.getLevel(i));
writer.endWriteMapLevelIndex();
}
}
selectData.close();
writer.endWriteMapIndex();
writer.flush();
} catch (RTreeException e) {
throw new IllegalStateException(e);
}
}
use of rtree.RTree in project OsmAnd-tools by osmandapp.
the class IndexVectorMapCreator method createDatabaseStructure.
public void createDatabaseStructure(Connection mapConnection, DBDialect dialect, String rtreeMapIndexNonPackFileName) throws SQLException, IOException {
createMapIndexStructure(mapConnection);
this.mapConnection = mapConnection;
mapBinaryStat = createStatementMapBinaryInsert(mapConnection);
mapLowLevelBinaryStat = createStatementLowLevelMapBinaryInsert(mapConnection);
try {
mapTree = new RTree[mapZooms.size()];
for (int i = 0; i < mapZooms.size(); i++) {
File file = new File(rtreeMapIndexNonPackFileName + i);
if (file.exists()) {
file.delete();
}
mapTree[i] = new RTree(rtreeMapIndexNonPackFileName + i);
// very slow
// mapTree[i].getFileHdr().setBufferPolicy(true);
}
} catch (RTreeException e) {
throw new IOException(e);
}
pStatements.put(mapBinaryStat, 0);
pStatements.put(mapLowLevelBinaryStat, 0);
}
Aggregations