Search in sources :

Example 11 with RouteSegment

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;
}
Also used : TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) RouteSegment(net.osmand.router.BinaryRoutePlanner.RouteSegment) FinalRouteSegment(net.osmand.router.BinaryRoutePlanner.FinalRouteSegment)

Example 12 with RouteSegment

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);
    }
}
Also used : ArrayList(java.util.ArrayList) TLongArrayList(gnu.trove.list.array.TLongArrayList) RouteDataObject(net.osmand.binary.RouteDataObject) RoutingSubregionTile(net.osmand.router.RoutingContext.RoutingSubregionTile) RouteSegment(net.osmand.router.BinaryRoutePlanner.RouteSegment) LinkedHashMap(java.util.LinkedHashMap)

Example 13 with RouteSegment

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));
    }
}
Also used : RouteSegment(net.osmand.router.BinaryRoutePlanner.RouteSegment)

Example 14 with RouteSegment

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();
}
Also used : Point(java.awt.Point) IOException(java.io.IOException) Way(net.osmand.osm.edit.Way) Point(java.awt.Point) LatLon(net.osmand.data.LatLon) DataTileManager(net.osmand.data.DataTileManager) RouteSegment(net.osmand.router.BinaryRoutePlanner.RouteSegment)

Example 15 with RouteSegment

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);
}
Also used : RouteSegment(net.osmand.router.BinaryRoutePlanner.RouteSegment)

Aggregations

RouteSegment (net.osmand.router.BinaryRoutePlanner.RouteSegment)22 ArrayList (java.util.ArrayList)10 FinalRouteSegment (net.osmand.router.BinaryRoutePlanner.FinalRouteSegment)9 RouteDataObject (net.osmand.binary.RouteDataObject)8 Point (java.awt.Point)5 LatLon (net.osmand.data.LatLon)5 PriorityQueue (java.util.PriorityQueue)3 Way (net.osmand.osm.edit.Way)3 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)2 TLongHashSet (gnu.trove.set.hash.TLongHashSet)2 DataTileManager (net.osmand.data.DataTileManager)2 QuadPoint (net.osmand.data.QuadPoint)2 RouteSegmentPoint (net.osmand.router.BinaryRoutePlanner.RouteSegmentPoint)2 RouteSegmentVisitor (net.osmand.router.BinaryRoutePlanner.RouteSegmentVisitor)2 Builder (net.osmand.router.RoutingConfiguration.Builder)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 TLongArrayList (gnu.trove.list.array.TLongArrayList)1 File (java.io.File)1 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1