use of rtree.IllegalValueException 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.IllegalValueException 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.IllegalValueException 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.IllegalValueException 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.IllegalValueException 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