Search in sources :

Example 1 with RouteSegmentPoint

use of net.osmand.router.BinaryRoutePlanner.RouteSegmentPoint in project Osmand by osmandapp.

the class GeocodingUtilities method reverseGeocodingSearch.

public List<GeocodingResult> reverseGeocodingSearch(RoutingContext ctx, double lat, double lon, boolean allowEmptyNames) throws IOException {
    RoutePlannerFrontEnd rp = new RoutePlannerFrontEnd(false);
    List<GeocodingResult> lst = new ArrayList<GeocodingUtilities.GeocodingResult>();
    List<RouteSegmentPoint> listR = new ArrayList<BinaryRoutePlanner.RouteSegmentPoint>();
    rp.findRouteSegment(lat, lon, ctx, listR);
    double distSquare = 0;
    TLongHashSet set = new TLongHashSet();
    Set<String> streetNames = new HashSet<String>();
    for (RouteSegmentPoint p : listR) {
        RouteDataObject road = p.getRoad();
        if (!set.add(road.getId())) {
            continue;
        }
        // System.out.println(road.toString() +  " " + Math.sqrt(p.distSquare));
        String name = Algorithms.isEmpty(road.getName()) ? road.getRef("", false, true) : road.getName();
        if (allowEmptyNames || !Algorithms.isEmpty(name)) {
            if (distSquare == 0 || distSquare > p.distSquare) {
                distSquare = p.distSquare;
            }
            GeocodingResult sr = new GeocodingResult();
            sr.searchPoint = new LatLon(lat, lon);
            sr.streetName = name == null ? "" : name;
            sr.point = p;
            sr.connectionPoint = new LatLon(MapUtils.get31LatitudeY(p.preciseY), MapUtils.get31LongitudeX(p.preciseX));
            sr.regionFP = road.region.getFilePointer();
            sr.regionLen = road.region.getLength();
            if (streetNames.add(sr.streetName)) {
                lst.add(sr);
            }
        }
        if (p.distSquare > STOP_SEARCHING_STREET_WITH_MULTIPLIER_RADIUS * STOP_SEARCHING_STREET_WITH_MULTIPLIER_RADIUS && distSquare != 0 && p.distSquare > THRESHOLD_MULTIPLIER_SKIP_STREETS_AFTER * distSquare) {
            break;
        }
        if (p.distSquare > STOP_SEARCHING_STREET_WITHOUT_MULTIPLIER_RADIUS * STOP_SEARCHING_STREET_WITHOUT_MULTIPLIER_RADIUS) {
            break;
        }
    }
    Collections.sort(lst, GeocodingUtilities.DISTANCE_COMPARATOR);
    return lst;
}
Also used : BinaryRoutePlanner(net.osmand.router.BinaryRoutePlanner) ArrayList(java.util.ArrayList) LatLon(net.osmand.data.LatLon) RouteSegmentPoint(net.osmand.router.BinaryRoutePlanner.RouteSegmentPoint) TLongHashSet(gnu.trove.set.hash.TLongHashSet) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd) HashSet(java.util.HashSet) TLongHashSet(gnu.trove.set.hash.TLongHashSet)

Example 2 with RouteSegmentPoint

use of net.osmand.router.BinaryRoutePlanner.RouteSegmentPoint in project Osmand by osmandapp.

the class RoutePlannerFrontEnd method needRequestPrivateAccessRouting.

private boolean needRequestPrivateAccessRouting(RoutingContext ctx, List<LatLon> points) throws IOException {
    boolean res = false;
    GeneralRouter router = (GeneralRouter) ctx.getRouter();
    if (router != null && !router.isAllowPrivate() && router.getParameters().containsKey(GeneralRouter.ALLOW_PRIVATE)) {
        ctx.unloadAllData();
        LinkedHashMap<String, String> mp = new LinkedHashMap<String, String>();
        mp.put(GeneralRouter.ALLOW_PRIVATE, "true");
        ctx.setRouter(new GeneralRouter(router.getProfile(), mp));
        for (LatLon latLon : points) {
            RouteSegmentPoint rp = findRouteSegment(latLon.getLatitude(), latLon.getLongitude(), ctx, null);
            if (rp != null && rp.road != null) {
                if (rp.road.hasPrivateAccess()) {
                    res = true;
                    break;
                }
            }
        }
        ctx.unloadAllData();
        ctx.setRouter(router);
    }
    return res;
}
Also used : LatLon(net.osmand.data.LatLon) RouteSegmentPoint(net.osmand.router.BinaryRoutePlanner.RouteSegmentPoint) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with RouteSegmentPoint

use of net.osmand.router.BinaryRoutePlanner.RouteSegmentPoint in project Osmand by osmandapp.

the class RoutePlannerFrontEnd method searchRoute.

private List<RouteSegmentResult> searchRoute(final RoutingContext ctx, List<RouteSegmentPoint> points, PrecalculatedRouteDirection routeDirection) throws IOException, InterruptedException {
    if (points.size() <= 2) {
        if (!useSmartRouteRecalculation) {
            ctx.previouslyCalculatedRoute = null;
        }
        return searchRoute(ctx, points.get(0), points.get(1), routeDirection);
    }
    ArrayList<RouteSegmentResult> firstPartRecalculatedRoute = null;
    ArrayList<RouteSegmentResult> restPartRecalculatedRoute = null;
    if (ctx.previouslyCalculatedRoute != null) {
        List<RouteSegmentResult> prev = ctx.previouslyCalculatedRoute;
        long id = points.get(1).getRoad().id;
        int ss = points.get(1).getSegmentStart();
        int px = points.get(1).getRoad().getPoint31XTile(ss);
        int py = points.get(1).getRoad().getPoint31YTile(ss);
        for (int i = 0; i < prev.size(); i++) {
            RouteSegmentResult rsr = prev.get(i);
            if (id == rsr.getObject().getId()) {
                if (MapUtils.getDistance(rsr.getPoint(rsr.getEndPointIndex()), MapUtils.get31LatitudeY(py), MapUtils.get31LongitudeX(px)) < 50) {
                    firstPartRecalculatedRoute = new ArrayList<RouteSegmentResult>(i + 1);
                    restPartRecalculatedRoute = new ArrayList<RouteSegmentResult>(prev.size() - i);
                    for (int k = 0; k < prev.size(); k++) {
                        if (k <= i) {
                            firstPartRecalculatedRoute.add(prev.get(k));
                        } else {
                            restPartRecalculatedRoute.add(prev.get(k));
                        }
                    }
                    System.out.println("Recalculate only first part of the route");
                    break;
                }
            }
        }
    }
    List<RouteSegmentResult> results = new ArrayList<RouteSegmentResult>();
    for (int i = 0; i < points.size() - 1; i++) {
        RoutingContext local = new RoutingContext(ctx);
        if (i == 0) {
            if (useSmartRouteRecalculation) {
                local.previouslyCalculatedRoute = firstPartRecalculatedRoute;
            }
        }
        local.visitor = ctx.visitor;
        local.calculationProgress = ctx.calculationProgress;
        List<RouteSegmentResult> res = searchRouteInternalPrepare(local, points.get(i), points.get(i + 1), routeDirection);
        results.addAll(res);
        ctx.distinctLoadedTiles += local.distinctLoadedTiles;
        ctx.loadedTiles += local.loadedTiles;
        ctx.visitedSegments += local.visitedSegments;
        ctx.loadedPrevUnloadedTiles += local.loadedPrevUnloadedTiles;
        ctx.timeToCalculate += local.timeToCalculate;
        ctx.timeToLoad += local.timeToLoad;
        ctx.timeToLoadHeaders += local.timeToLoadHeaders;
        ctx.relaxedSegments += local.relaxedSegments;
        ctx.routingTime += local.routingTime;
        local.unloadAllData(ctx);
        if (restPartRecalculatedRoute != null) {
            results.addAll(restPartRecalculatedRoute);
            break;
        }
    }
    ctx.unloadAllData();
    return results;
}
Also used : ArrayList(java.util.ArrayList) RouteSegmentPoint(net.osmand.router.BinaryRoutePlanner.RouteSegmentPoint) QuadPoint(net.osmand.data.QuadPoint)

Example 4 with RouteSegmentPoint

use of net.osmand.router.BinaryRoutePlanner.RouteSegmentPoint in project Osmand by osmandapp.

the class RoutePlannerFrontEnd method addSegment.

private boolean addSegment(LatLon s, RoutingContext ctx, int indexNotFound, List<RouteSegmentPoint> res) throws IOException {
    RouteSegmentPoint f = findRouteSegment(s.getLatitude(), s.getLongitude(), ctx, null);
    if (f == null) {
        ctx.calculationProgress.segmentNotFound = indexNotFound;
        return false;
    } else {
        log.info("Route segment found " + f.getRoad().id + " " + f.getRoad().getName());
        res.add(f);
        return true;
    }
}
Also used : RouteSegmentPoint(net.osmand.router.BinaryRoutePlanner.RouteSegmentPoint)

Example 5 with RouteSegmentPoint

use of net.osmand.router.BinaryRoutePlanner.RouteSegmentPoint in project Osmand by osmandapp.

the class RoutePlannerFrontEnd method findRouteSegment.

public RouteSegmentPoint findRouteSegment(double lat, double lon, RoutingContext ctx, List<RouteSegmentPoint> list) throws IOException {
    int px = MapUtils.get31TileNumberX(lon);
    int py = MapUtils.get31TileNumberY(lat);
    ArrayList<RouteDataObject> dataObjects = new ArrayList<RouteDataObject>();
    ctx.loadTileData(px, py, 17, dataObjects);
    if (dataObjects.isEmpty()) {
        ctx.loadTileData(px, py, 15, dataObjects);
    }
    if (list == null) {
        list = new ArrayList<BinaryRoutePlanner.RouteSegmentPoint>();
    }
    for (RouteDataObject r : dataObjects) {
        if (r.getPointsLength() > 1) {
            RouteSegmentPoint road = null;
            for (int j = 1; j < r.getPointsLength(); j++) {
                QuadPoint pr = MapUtils.getProjectionPoint31(px, py, r.getPoint31XTile(j - 1), r.getPoint31YTile(j - 1), r.getPoint31XTile(j), r.getPoint31YTile(j));
                double currentsDistSquare = squareDist((int) pr.x, (int) pr.y, px, py);
                if (road == null || currentsDistSquare < road.distSquare) {
                    RouteDataObject ro = new RouteDataObject(r);
                    road = new RouteSegmentPoint(ro, j, currentsDistSquare);
                    road.preciseX = (int) pr.x;
                    road.preciseY = (int) pr.y;
                }
            }
            if (road != null) {
                list.add(road);
            }
        }
    }
    Collections.sort(list, new Comparator<RouteSegmentPoint>() {

        @Override
        public int compare(RouteSegmentPoint o1, RouteSegmentPoint o2) {
            return Double.compare(o1.distSquare, o2.distSquare);
        }
    });
    if (list.size() > 0) {
        RouteSegmentPoint ps = list.get(0);
        ps.others = list;
        return ps;
    }
    return null;
}
Also used : RouteSegmentPoint(net.osmand.router.BinaryRoutePlanner.RouteSegmentPoint) QuadPoint(net.osmand.data.QuadPoint) ArrayList(java.util.ArrayList) RouteDataObject(net.osmand.binary.RouteDataObject) RouteSegmentPoint(net.osmand.router.BinaryRoutePlanner.RouteSegmentPoint) QuadPoint(net.osmand.data.QuadPoint)

Aggregations

RouteSegmentPoint (net.osmand.router.BinaryRoutePlanner.RouteSegmentPoint)7 ArrayList (java.util.ArrayList)4 QuadPoint (net.osmand.data.QuadPoint)4 LatLon (net.osmand.data.LatLon)3 TLongHashSet (gnu.trove.set.hash.TLongHashSet)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 RouteDataObject (net.osmand.binary.RouteDataObject)1 BinaryRoutePlanner (net.osmand.router.BinaryRoutePlanner)1 RouteSegment (net.osmand.router.BinaryRoutePlanner.RouteSegment)1 RoutePlannerFrontEnd (net.osmand.router.RoutePlannerFrontEnd)1