Search in sources :

Example 1 with RouteDataObject

use of net.osmand.binary.RouteDataObject 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();
}
Also used : RTreeInsertException(rtree.RTreeInsertException) Rect(rtree.Rect) CheckRoadConnectivity(net.osmand.osm.util.CheckRoadConnectivity) IllegalValueException(rtree.IllegalValueException) RouteDataObject(net.osmand.binary.RouteDataObject) PreparedStatement(java.sql.PreparedStatement) LeafElement(rtree.LeafElement)

Example 2 with RouteDataObject

use of net.osmand.binary.RouteDataObject in project OsmAnd-tools by osmandapp.

the class ManyToOneRoadCalculation method initSegments.

private TLongObjectHashMap<ManyToManySegment> initSegments(int stop, int sbottom, RoutingContext ctx, List<RoutingSubregionTile> tiles, List<ManyToManySegment> topIntersects, List<ManyToManySegment> bottomIntersects) {
    TLongObjectHashMap<ManyToManySegment> res = new TLongObjectHashMap<ManyToManySegment>();
    List<RouteDataObject> startObjects = new ArrayList<RouteDataObject>();
    for (RoutingSubregionTile st : tiles) {
        if (st.subregion.top <= sbottom && st.subregion.bottom >= stop) {
            ctx.loadSubregionTile(st, false, startObjects, null);
        }
    }
    System.out.println("Roads in layer " + startObjects.size());
    for (RouteDataObject ro : startObjects) {
        boolean topCheck = false, bottomCheck = false;
        for (int i = 0; i < ro.getPointsLength(); i++) {
            ManyToManySegment sg = new ManyToManySegment();
            sg.road = ro;
            sg.segmentIndex = i;
            int px = ro.getPoint31XTile(i);
            int py = ro.getPoint31YTile(i);
            if (i > 0) {
                int prevX = ro.getPoint31XTile(i - 1);
                int prevY = ro.getPoint31YTile(i - 1);
                if (checkIntersection(prevX, prevY, px, py, 0, Integer.MAX_VALUE, stop, stop) && !topCheck) {
                    topIntersects.add(sg);
                    topCheck = true;
                }
                if (checkIntersection(prevX, prevY, px, py, 0, Integer.MAX_VALUE, sbottom, sbottom) && !bottomCheck) {
                    bottomIntersects.add(sg);
                    bottomCheck = true;
                }
            }
            long key = calcLong(px, py);
            ManyToManySegment sm = res.get(key);
            if (sm != null) {
                while (sm.next != null) {
                    sm = sm.next;
                }
                sm.next = sg;
            } else {
                res.put(key, sg);
            }
        }
    }
    return res;
}
Also used : ArrayList(java.util.ArrayList) TLongArrayList(gnu.trove.list.array.TLongArrayList) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) RouteDataObject(net.osmand.binary.RouteDataObject) RoutingSubregionTile(net.osmand.router.RoutingContext.RoutingSubregionTile)

Example 3 with RouteDataObject

use of net.osmand.binary.RouteDataObject in project OsmAnd-tools by osmandapp.

the class CheckRoadConnectivity method processSegment.

private RouteSegment processSegment(RoutingContext ctx, RouteSegment segment, PriorityQueue<RouteSegment> queue, TLongHashSet visited, TLongObjectHashMap<List<RouteDataObject>> all, boolean direction, boolean start) {
    int ind = segment.getSegmentStart();
    RouteDataObject road = segment.getRoad();
    final long pid = calcPointIdUnique(segment.getRoad(), ind);
    if (visited.contains(pid)) {
        return null;
    }
    visited.add(pid);
    double distFromStart = segment.getDistanceFromStart();
    while (true) {
        int py = road.getPoint31YTile(ind);
        int px = road.getPoint31XTile(ind);
        if (direction) {
            ind++;
        } else {
            ind--;
        }
        if (ind < 0 || ind >= segment.getRoad().getPointsLength()) {
            break;
        }
        if (all.contains(calcPointId(segment.getRoad(), ind)) && !start) {
            return segment;
        }
        visited.add(calcPointIdUnique(segment.getRoad(), ind));
        int x = road.getPoint31XTile(ind);
        int y = road.getPoint31YTile(ind);
        distFromStart += MapUtils.squareDist31TileMetric(px, py, x, y) / ctx.getRouter().defineRoutingSpeed(road) * ctx.getRouter().defineSpeedPriority(road);
        RouteSegment rs = ctx.loadRouteSegment(x, y, 0);
        while (rs != null) {
            if (!visited.contains(calcPointIdUnique(rs.getRoad(), rs.getSegmentStart()))) {
                if (!queue.contains(rs) || rs.getDistanceFromStart() > distFromStart) {
                    rs.setDistanceFromStart((float) distFromStart);
                    rs.setParentSegmentEnd(ind);
                    rs.setParentRoute(segment);
                    queue.remove(rs);
                    queue.add(rs);
                }
            }
            rs = rs.getNext();
        }
    }
    return null;
}
Also used : RouteDataObject(net.osmand.binary.RouteDataObject) RouteSegment(net.osmand.router.BinaryRoutePlanner.RouteSegment)

Example 4 with RouteDataObject

use of net.osmand.binary.RouteDataObject in project OsmAnd-tools by osmandapp.

the class CheckRoadConnectivity method processDataObjects.

private List<Cluster> processDataObjects(RoutingContext ctx, RoutingSubregionTile tl) {
    ArrayList<RouteDataObject> dataObjects = new ArrayList<RouteDataObject>();
    ctx.loadSubregionTile(tl, false, dataObjects, null);
    TLongObjectHashMap<List<RouteDataObject>> clusterPoints = new TLongObjectHashMap<List<RouteDataObject>>();
    for (RouteDataObject rdo : dataObjects) {
        for (int i = 0; i < rdo.getPointsLength(); i++) {
            long pointId = calcPointId(rdo, i);
            List<RouteDataObject> list = clusterPoints.get(pointId);
            if (list == null) {
                list = new LinkedList<RouteDataObject>();
                clusterPoints.put(pointId, list);
            }
            list.add(rdo);
        }
    }
    HashSet<RouteDataObject> toVisit = new HashSet<RouteDataObject>(dataObjects);
    List<Cluster> clusters = new ArrayList<Cluster>();
    while (!toVisit.isEmpty()) {
        RouteDataObject firstObject = toVisit.iterator().next();
        LinkedList<RouteDataObject> queue = new LinkedList<RouteDataObject>();
        queue.add(firstObject);
        Cluster c = new Cluster();
        c.initalRoadId = firstObject.id;
        clusters.add(c);
        while (!queue.isEmpty()) {
            RouteDataObject rdo = queue.poll();
            if (!toVisit.contains(rdo)) {
                continue;
            }
            c.roadsIncluded++;
            c.roadIds.add(rdo.id);
            String hw = rdo.getHighway();
            if (hw == null) {
                hw = rdo.getRoute();
            }
            c.highways.add(hw);
            toVisit.remove(rdo);
            for (int i = 0; i < rdo.getPointsLength(); i++) {
                long pointId = calcPointId(rdo, i);
                c.points.add(pointId);
                List<RouteDataObject> list = clusterPoints.get(pointId);
                for (RouteDataObject r : list) {
                    if (r.id != rdo.id && toVisit.contains(r)) {
                        queue.add(r);
                    }
                }
            }
        }
    }
    return clusters;
}
Also used : ArrayList(java.util.ArrayList) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) LinkedList(java.util.LinkedList) RouteDataObject(net.osmand.binary.RouteDataObject) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) HashSet(java.util.HashSet) TLongHashSet(gnu.trove.set.hash.TLongHashSet)

Example 5 with RouteDataObject

use of net.osmand.binary.RouteDataObject in project OsmAnd-tools by osmandapp.

the class CheckRoadConnectivity method findConnectedRoads.

private List<RouteDataObject> findConnectedRoads(RoutingContext ctx, RouteDataObject initial, boolean begin, TLongObjectHashMap<List<RouteDataObject>> all) {
    PriorityQueue<RouteSegment> queue = new PriorityQueue<RouteSegment>(10, new Comparator<RouteSegment>() {

        @Override
        public int compare(RouteSegment o1, RouteSegment o2) {
            return Double.compare(o1.getDistanceFromStart(), o2.getDistanceFromStart());
        }
    });
    VehicleRouter router = ctx.getRouter();
    ArrayList<RouteDataObject> next = new ArrayList<RouteDataObject>();
    ctx.loadTileData(initial.getPoint31XTile(0), initial.getPoint31YTile(0), 17, next);
    for (RouteDataObject n : next) {
        if (n.id == initial.id) {
            initial = n;
            break;
        }
    }
    queue.add(new RouteSegment(initial, begin ? 1 : initial.getPointsLength() - 2));
    TLongHashSet visited = new TLongHashSet();
    RouteSegment finalSegment = null;
    while (!queue.isEmpty() && finalSegment == null) {
        RouteSegment segment = queue.poll();
        int oneWay = router.isOneWay(segment.getRoad());
        boolean start = initial.id == segment.getRoad().id;
        if (start) {
            oneWay = begin ? -1 : 1;
        }
        if (oneWay >= 0) {
            finalSegment = processSegment(ctx, segment, queue, visited, all, true, start);
        }
        if (oneWay <= 0) {
            finalSegment = processSegment(ctx, segment, queue, visited, all, false, start);
        }
    }
    if (finalSegment == null) {
        if (TRACE) {
            System.out.println("Isolated " + initial.id);
        }
    } else {
        StringBuilder b = new StringBuilder("Route for " + initial.id + " : ");
        RouteSegment s = finalSegment;
        List<RouteDataObject> rdoToAdd = new ArrayList<RouteDataObject>();
        while (s != null) {
            if (s.getRoad().id != initial.id) {
                b.append(s.getRoad().id).append(", ");
                rdoToAdd.add(s.getRoad());
            }
            s = s.getParentRoute();
        }
        if (TRACE) {
            System.out.println(b);
        }
        return rdoToAdd;
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) PriorityQueue(java.util.PriorityQueue) TLongHashSet(gnu.trove.set.hash.TLongHashSet) RouteDataObject(net.osmand.binary.RouteDataObject) VehicleRouter(net.osmand.router.VehicleRouter) RouteSegment(net.osmand.router.BinaryRoutePlanner.RouteSegment)

Aggregations

RouteDataObject (net.osmand.binary.RouteDataObject)49 ArrayList (java.util.ArrayList)13 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)9 Location (net.osmand.Location)9 RouteSegment (net.osmand.router.BinaryRoutePlanner.RouteSegment)8 TLongHashSet (gnu.trove.set.hash.TLongHashSet)7 LatLon (net.osmand.data.LatLon)6 IOException (java.io.IOException)5 RouteSubregion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion)4 QuadPoint (net.osmand.data.QuadPoint)4 File (java.io.File)3 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)3 RouteRegion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion)3 RoutePlannerFrontEnd (net.osmand.router.RoutePlannerFrontEnd)3 RoutingConfiguration (net.osmand.router.RoutingConfiguration)3 RoutingContext (net.osmand.router.RoutingContext)3 TLongArrayList (gnu.trove.list.array.TLongArrayList)2 Point (java.awt.Point)2