use of net.osmand.router.BinaryRoutePlanner.RouteSegment in project Osmand by osmandapp.
the class RouteResultPreparation method convertFinalSegmentToResults.
private List<RouteSegmentResult> convertFinalSegmentToResults(RoutingContext ctx, FinalRouteSegment finalSegment) {
List<RouteSegmentResult> result = new ArrayList<RouteSegmentResult>();
if (finalSegment != null) {
ctx.routingTime = finalSegment.distanceFromStart;
println("Routing calculated time distance " + finalSegment.distanceFromStart);
// Get results from opposite direction roads
RouteSegment segment = finalSegment.reverseWaySearch ? finalSegment : finalSegment.opposite.getParentRoute();
int parentSegmentStart = finalSegment.reverseWaySearch ? finalSegment.opposite.getSegmentStart() : finalSegment.opposite.getParentSegmentEnd();
float parentRoutingTime = -1;
while (segment != null) {
RouteSegmentResult res = new RouteSegmentResult(segment.road, parentSegmentStart, segment.getSegmentStart());
parentRoutingTime = calcRoutingTime(parentRoutingTime, finalSegment, segment, res);
parentSegmentStart = segment.getParentSegmentEnd();
segment = segment.getParentRoute();
addRouteSegmentToResult(ctx, result, res, false);
}
// reverse it just to attach good direction roads
Collections.reverse(result);
segment = finalSegment.reverseWaySearch ? finalSegment.opposite.getParentRoute() : finalSegment;
int parentSegmentEnd = finalSegment.reverseWaySearch ? finalSegment.opposite.getParentSegmentEnd() : finalSegment.opposite.getSegmentStart();
parentRoutingTime = -1;
while (segment != null) {
RouteSegmentResult res = new RouteSegmentResult(segment.road, segment.getSegmentStart(), parentSegmentEnd);
parentRoutingTime = calcRoutingTime(parentRoutingTime, finalSegment, segment, res);
parentSegmentEnd = segment.getParentSegmentEnd();
segment = segment.getParentRoute();
// happens in smart recalculation
addRouteSegmentToResult(ctx, result, res, true);
}
Collections.reverse(result);
// checkTotalRoutingTime(result);
}
return result;
}
use of net.osmand.router.BinaryRoutePlanner.RouteSegment in project OsmAnd-tools by osmandapp.
the class ManyToOneRoadCalculation method cutByQuadrant.
private void cutByQuadrant(int px, int py, int sx, int sy, RoutingContext ctx, List<RoutingSubregionTile> tiles) {
int bc = 0;
int rc = 0;
Map<String, Integer> counts = new LinkedHashMap<String, Integer>();
for (RoutingSubregionTile st : tiles) {
if (st.subregion.left <= sx && st.subregion.right >= px && st.subregion.top <= sy && st.subregion.bottom >= py) {
List<RouteDataObject> startObjects = new ArrayList<RouteDataObject>();
ctx.loadSubregionTile(st, false, startObjects, null);
List<RouteSegment> res = filterIntersections(px, sx, sy, sy, startObjects);
bc += res.size();
updateCounts(counts, res);
res = filterIntersections(sx, sx, py, sy, startObjects);
rc += res.size();
updateCounts(counts, res);
}
}
if (bc + rc > 0) {
System.out.println("Q " + ((float) MapUtils.get31LatitudeY(sy) + " " + (float) MapUtils.get31LongitudeX(sx)) + " \t B=" + bc + " R=" + rc + " " + counts);
}
}
use of net.osmand.router.BinaryRoutePlanner.RouteSegment in project OsmAnd-tools by osmandapp.
the class ManyToOneRoadCalculation method updateCounts.
private void updateCounts(Map<String, Integer> counts, List<RouteSegment> res) {
for (RouteSegment r : res) {
String key = r.getRoad().getHighway();
if (key == null) {
key = r.getRoad().getRoute();
}
Integer c = counts.get(key);
if (c == null) {
c = 0;
}
counts.put(key, (Integer) (++c));
}
}
use of net.osmand.router.BinaryRoutePlanner.RouteSegment in project OsmAnd-tools by osmandapp.
the class MapClusterLayer method clusteringRoadActions.
private void clusteringRoadActions() {
Point popupMenuPoint = map.getPopupMenuPoint();
double fy = (popupMenuPoint.y - map.getCenterPointY()) / map.getTileSize();
double fx = (popupMenuPoint.x - map.getCenterPointX()) / map.getTileSize();
final double latitude = MapUtils.getLatitudeFromTile(map.getZoom(), map.getYTile() + fy);
final double longitude = MapUtils.getLongitudeFromTile(map.getZoom(), map.getXTile() + fx);
final ClusteringContext clusterCtx = new ClusteringContext();
new Thread(new Runnable() {
@Override
public void run() {
try {
DataTileManager<Way> points = new DataTileManager<Way>(11);
List<RouteSegment> ways = clustering(clusterCtx, latitude, longitude, points);
for (RouteSegment s : ways) {
Way w = new Way(-1);
int st = s.getSegmentStart();
int end = s.getParentSegmentEnd();
if (st > end) {
int t = st;
st = end;
end = t;
for (int i = st; i <= end; i++) {
net.osmand.osm.edit.Node n = new net.osmand.osm.edit.Node(MapUtils.get31LatitudeY(s.getRoad().getPoint31YTile(i)), MapUtils.get31LongitudeX(s.getRoad().getPoint31XTile(i)), -1);
w.addNode(n);
}
LatLon n = w.getLatLon();
points.registerObject(n.getLatitude(), n.getLongitude(), w);
}
}
map.setPoints(points);
map.repaint();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
}
use of net.osmand.router.BinaryRoutePlanner.RouteSegment in project OsmAnd-tools by osmandapp.
the class MapClusterLayer method addSegmentResult.
private void addSegmentResult(List<RouteSegment> result, RouteSegment sgm, int segmentSt, int segmentEnd) {
RouteSegment r = new RouteSegment(sgm.getRoad(), segmentSt);
r.setParentSegmentEnd(segmentEnd);
result.add(r);
}
Aggregations