use of rtree.RTreeInsertException in project OsmAnd-tools by osmandapp.
the class IndexRouteCreator method addWayToIndex.
private void addWayToIndex(long id, List<Node> nodes, PreparedStatement insertStat, RTree rTree, TIntArrayList outTypes, TLongObjectHashMap<TIntArrayList> pointTypes, TLongObjectHashMap<TIntObjectHashMap<String>> pointNamesRaw, Map<MapRoutingTypes.MapRouteType, String> names) throws SQLException {
boolean init = false;
int minX = Integer.MAX_VALUE;
int maxX = 0;
int minY = Integer.MAX_VALUE;
int maxY = 0;
ByteArrayOutputStream bcoordinates = new ByteArrayOutputStream();
ByteArrayOutputStream bpointIds = new ByteArrayOutputStream();
ByteArrayOutputStream bpointTypes = new ByteArrayOutputStream();
ByteArrayOutputStream btypes = new ByteArrayOutputStream();
List<MapPointName> pointNamesEmp = new ArrayList<MapPointName>();
try {
for (int j = 0; j < outTypes.size(); j++) {
Algorithms.writeSmallInt(btypes, outTypes.get(j));
}
int pointIndex = 0;
for (Node n : nodes) {
if (n != null) {
// write id
Algorithms.writeLongInt(bpointIds, n.getId());
// write point type
TIntArrayList types = pointTypes.get(n.getId());
if (types != null) {
for (int j = 0; j < types.size(); j++) {
Algorithms.writeSmallInt(bpointTypes, types.get(j));
}
}
TIntObjectHashMap<String> namesP = pointNamesRaw.get(n.getId());
if (namesP != null) {
TIntObjectIterator<String> it = namesP.iterator();
while (it.hasNext()) {
it.advance();
MapPointName obj = new MapPointName(it.key(), pointIndex, it.value());
pointNamesEmp.add(obj);
}
}
Algorithms.writeSmallInt(bpointTypes, 0);
// write coordinates
int y = MapUtils.get31TileNumberY(n.getLatitude());
int x = MapUtils.get31TileNumberX(n.getLongitude());
minX = Math.min(minX, x);
maxX = Math.max(maxX, x);
minY = Math.min(minY, y);
maxY = Math.max(maxY, y);
init = true;
Algorithms.writeInt(bcoordinates, x);
Algorithms.writeInt(bcoordinates, y);
pointIndex++;
}
}
} catch (IOException est) {
throw new IllegalStateException(est);
}
if (init) {
// conn.prepareStatement("insert into route_objects(id, types, pointTypes, pointIds, pointCoordinates, name) values(?, ?, ?, ?, ?, ?, ?)");
insertStat.setLong(1, id);
insertStat.setBytes(2, btypes.toByteArray());
insertStat.setBytes(3, bpointTypes.toByteArray());
insertStat.setBytes(4, bpointIds.toByteArray());
insertStat.setBytes(5, bcoordinates.toByteArray());
insertStat.setString(6, encodeNames(names));
insertStat.setString(7, encodeListNames(pointNamesEmp));
addBatch(insertStat, false);
try {
rTree.insert(new LeafElement(new Rect(minX, minY, maxX, maxY), id));
} catch (RTreeInsertException e1) {
throw new IllegalArgumentException(e1);
} catch (IllegalValueException e1) {
throw new IllegalArgumentException(e1);
}
}
}
use of rtree.RTreeInsertException in project OsmAnd-tools by osmandapp.
the class IndexRouteCreator method appendMissingRoadsForBaseMap.
private void appendMissingRoadsForBaseMap(Connection conn, BinaryMapIndexReader reader) throws IOException, SQLException {
TLongObjectHashMap<RouteDataObject> map = new CheckRoadConnectivity().collectDisconnectedRoads(reader);
// to add
PreparedStatement ps = conn.prepareStatement(COPY_BASE);
for (RouteDataObject rdo : map.valueCollection()) {
// addWayToIndex(id, nodes, insertStat, rTree)
int minX = Integer.MAX_VALUE;
int maxX = 0;
int minY = Integer.MAX_VALUE;
int maxY = 0;
long id = rdo.getId();
for (int i = 0; i < rdo.getPointsLength(); i++) {
int x = rdo.getPoint31XTile(i);
int y = rdo.getPoint31YTile(i);
minX = Math.min(minX, x);
maxX = Math.max(maxX, x);
minY = Math.min(minY, y);
maxY = Math.max(maxY, y);
long point = (x << 31) + y;
registerBaseIntersectionPoint(point, false, id, i, i);
}
ps.setLong(1, id);
ps.execute();
try {
baserouteTree.insert(new LeafElement(new Rect(minX, minY, maxX, maxY), id));
} catch (RTreeInsertException e1) {
throw new IllegalArgumentException(e1);
} catch (IllegalValueException e1) {
throw new IllegalArgumentException(e1);
}
}
ps.close();
}
use of rtree.RTreeInsertException in project OsmAnd-tools by osmandapp.
the class IndexTransportCreator method writeRouteStops.
private void writeRouteStops(TransportRoute r, List<TransportStop> stops) throws SQLException {
int i = 0;
for (TransportStop s : stops) {
if (!visitedStops.contains(s.getId())) {
transStopsStat.setLong(1, s.getId());
transStopsStat.setDouble(2, s.getLocation().getLatitude());
transStopsStat.setDouble(3, s.getLocation().getLongitude());
transStopsStat.setString(4, s.getName());
transStopsStat.setString(5, s.getEnName(false));
int x = (int) MapUtils.getTileNumberX(24, s.getLocation().getLongitude());
int y = (int) MapUtils.getTileNumberY(24, s.getLocation().getLatitude());
addBatch(transStopsStat);
try {
transportStopsTree.insert(new LeafElement(new Rect(x, y, x, y), s.getId()));
} catch (RTreeInsertException e) {
throw new IllegalArgumentException(e);
} catch (IllegalValueException e) {
throw new IllegalArgumentException(e);
}
visitedStops.add(s.getId());
}
transRouteStopsStat.setLong(1, r.getId());
transRouteStopsStat.setLong(2, s.getId());
transRouteStopsStat.setInt(3, i++);
addBatch(transRouteStopsStat);
}
}
use of rtree.RTreeInsertException in project OsmAnd-tools by osmandapp.
the class IndexVectorMapCreator method insertBinaryMapRenderObjectIndex.
private void insertBinaryMapRenderObjectIndex(RTree mapTree, Collection<Node> nodes, List<List<Node>> innerWays, Map<MapRulType, String> names, long id, boolean area, TIntArrayList types, TIntArrayList addTypes, boolean commit) throws SQLException {
boolean init = false;
int minX = Integer.MAX_VALUE;
int maxX = 0;
int minY = Integer.MAX_VALUE;
int maxY = 0;
ByteArrayOutputStream bcoordinates = new ByteArrayOutputStream();
ByteArrayOutputStream binnercoord = new ByteArrayOutputStream();
ByteArrayOutputStream btypes = new ByteArrayOutputStream();
ByteArrayOutputStream badditionalTypes = new ByteArrayOutputStream();
try {
for (int j = 0; j < types.size(); j++) {
Algorithms.writeSmallInt(btypes, types.get(j));
}
for (int j = 0; j < addTypes.size(); j++) {
Algorithms.writeSmallInt(badditionalTypes, addTypes.get(j));
}
for (Node n : nodes) {
if (n != null) {
int y = MapUtils.get31TileNumberY(n.getLatitude());
int x = MapUtils.get31TileNumberX(n.getLongitude());
minX = Math.min(minX, x);
maxX = Math.max(maxX, x);
minY = Math.min(minY, y);
maxY = Math.max(maxY, y);
init = true;
Algorithms.writeInt(bcoordinates, x);
Algorithms.writeInt(bcoordinates, y);
}
}
if (innerWays != null) {
for (List<Node> ws : innerWays) {
boolean exist = false;
if (ws != null) {
for (Node n : ws) {
if (n != null) {
exist = true;
int y = MapUtils.get31TileNumberY(n.getLatitude());
int x = MapUtils.get31TileNumberX(n.getLongitude());
Algorithms.writeInt(binnercoord, x);
Algorithms.writeInt(binnercoord, y);
}
}
}
if (exist) {
Algorithms.writeInt(binnercoord, 0);
Algorithms.writeInt(binnercoord, 0);
}
}
}
} catch (IOException es) {
throw new IllegalStateException(es);
}
if (init) {
// conn.prepareStatement("insert into binary_map_objects(id, area, coordinates, innerPolygons, types, additionalTypes, name) values(?, ?, ?, ?, ?, ?, ?)");
mapBinaryStat.setLong(1, id);
mapBinaryStat.setBoolean(2, area);
mapBinaryStat.setBytes(3, bcoordinates.toByteArray());
mapBinaryStat.setBytes(4, binnercoord.toByteArray());
mapBinaryStat.setBytes(5, btypes.toByteArray());
mapBinaryStat.setBytes(6, badditionalTypes.toByteArray());
mapBinaryStat.setString(7, encodeNames(names));
addBatch(mapBinaryStat, commit);
try {
mapTree.insert(new LeafElement(new Rect(minX, minY, maxX, maxY), id));
} catch (RTreeInsertException e1) {
throw new IllegalArgumentException(e1);
} catch (IllegalValueException e1) {
throw new IllegalArgumentException(e1);
}
}
}
Aggregations