Search in sources :

Example 11 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class RouteProvider method calculateOsmAndRouteWithIntermediatePoints.

private RouteCalculationResult calculateOsmAndRouteWithIntermediatePoints(RouteCalculationParams routeParams, final List<Location> intermediates) throws IOException {
    RouteCalculationParams rp = new RouteCalculationParams();
    rp.calculationProgress = routeParams.calculationProgress;
    rp.ctx = routeParams.ctx;
    rp.mode = routeParams.mode;
    rp.start = routeParams.start;
    rp.end = routeParams.end;
    rp.leftSide = routeParams.leftSide;
    rp.type = routeParams.type;
    rp.fast = routeParams.fast;
    rp.onlyStartPointChanged = routeParams.onlyStartPointChanged;
    rp.previousToRecalculate = routeParams.previousToRecalculate;
    rp.intermediates = new ArrayList<LatLon>();
    int closest = 0;
    double maxDist = Double.POSITIVE_INFINITY;
    for (int i = 0; i < intermediates.size(); i++) {
        Location loc = intermediates.get(i);
        double dist = MapUtils.getDistance(loc.getLatitude(), loc.getLongitude(), rp.start.getLatitude(), rp.start.getLongitude());
        if (dist <= maxDist) {
            closest = i;
            maxDist = dist;
        }
    }
    for (int i = closest; i < intermediates.size(); i++) {
        Location w = intermediates.get(i);
        rp.intermediates.add(new LatLon(w.getLatitude(), w.getLongitude()));
    }
    return findVectorMapsRoute(rp, false);
}
Also used : LatLon(net.osmand.data.LatLon) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LocationPoint(net.osmand.data.LocationPoint) Location(net.osmand.Location)

Example 12 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class RouteProvider method createLocation.

private static Location createLocation(WptPt pt) {
    Location loc = new Location("OsmandRouteProvider");
    loc.setLatitude(pt.lat);
    loc.setLongitude(pt.lon);
    loc.setSpeed((float) pt.speed);
    if (!Double.isNaN(pt.ele)) {
        loc.setAltitude(pt.ele);
    }
    loc.setTime(pt.time);
    if (!Double.isNaN(pt.hdop)) {
        loc.setAccuracy((float) pt.hdop);
    }
    return loc;
}
Also used : Location(net.osmand.Location)

Example 13 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class RouteProvider method insertFinalSegment.

private void insertFinalSegment(RouteCalculationParams routeParams, List<Location> points, List<RouteDirectionInfo> directions, boolean calculateOsmAndRouteParts) {
    if (points.size() > 0) {
        Location routeEnd = points.get(points.size() - 1);
        LatLon e = routeEnd == null ? null : new LatLon(routeEnd.getLatitude(), routeEnd.getLongitude());
        LatLon finalEnd = routeParams.end;
        if (finalEnd != null && MapUtils.getDistance(finalEnd, e) > 60) {
            RouteCalculationResult newRes = null;
            if (calculateOsmAndRouteParts) {
                newRes = findOfflineRouteSegment(routeParams, routeEnd, finalEnd);
            }
            List<Location> loct;
            List<RouteDirectionInfo> dt;
            if (newRes != null && newRes.isCalculated()) {
                loct = newRes.getImmutableAllLocations();
                dt = newRes.getImmutableAllDirections();
            } else {
                loct = new ArrayList<Location>();
                Location l = new Location("");
                l.setLatitude(finalEnd.getLatitude());
                l.setLongitude(finalEnd.getLongitude());
                loct.add(l);
                dt = new ArrayList<RouteDirectionInfo>();
            }
            for (RouteDirectionInfo i : dt) {
                i.routePointOffset += points.size();
            }
            points.addAll(loct);
            directions.addAll(dt);
        }
    }
}
Also used : LatLon(net.osmand.data.LatLon) Location(net.osmand.Location)

Example 14 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class RouteProvider method findVectorMapsRoute.

protected RouteCalculationResult findVectorMapsRoute(final RouteCalculationParams params, boolean calcGPXRoute) throws IOException {
    BinaryMapIndexReader[] files = params.ctx.getResourceManager().getRoutingMapFiles();
    RoutePlannerFrontEnd router = new RoutePlannerFrontEnd(false);
    OsmandSettings settings = params.ctx.getSettings();
    router.setUseFastRecalculation(settings.USE_FAST_RECALCULATION.get());
    RoutingConfiguration.Builder config = params.ctx.getDefaultRoutingConfig();
    GeneralRouter generalRouter = SettingsNavigationActivity.getRouter(config, params.mode);
    if (generalRouter == null) {
        return applicationModeNotSupported(params);
    }
    RoutingConfiguration cf = initOsmAndRoutingConfig(config, params, settings, generalRouter);
    if (cf == null) {
        return applicationModeNotSupported(params);
    }
    PrecalculatedRouteDirection precalculated = null;
    if (calcGPXRoute) {
        ArrayList<Location> sublist = findStartAndEndLocationsFromRoute(params.gpxRoute.points, params.start, params.end, null, null);
        LatLon[] latLon = new LatLon[sublist.size()];
        for (int k = 0; k < latLon.length; k++) {
            latLon[k] = new LatLon(sublist.get(k).getLatitude(), sublist.get(k).getLongitude());
        }
        precalculated = PrecalculatedRouteDirection.build(latLon, generalRouter.getMaxDefaultSpeed());
        precalculated.setFollowNext(true);
    // cf.planRoadDirection = 1;
    }
    // BUILD context
    NativeOsmandLibrary lib = settings.SAFE_MODE.get() ? null : NativeOsmandLibrary.getLoadedLibrary();
    // check loaded files
    int leftX = MapUtils.get31TileNumberX(params.start.getLongitude());
    int rightX = leftX;
    int bottomY = MapUtils.get31TileNumberY(params.start.getLatitude());
    int topY = bottomY;
    if (params.intermediates != null) {
        for (LatLon l : params.intermediates) {
            leftX = Math.min(MapUtils.get31TileNumberX(l.getLongitude()), leftX);
            rightX = Math.max(MapUtils.get31TileNumberX(l.getLongitude()), rightX);
            bottomY = Math.max(MapUtils.get31TileNumberY(l.getLatitude()), bottomY);
            topY = Math.min(MapUtils.get31TileNumberY(l.getLatitude()), topY);
        }
    }
    LatLon l = params.end;
    leftX = Math.min(MapUtils.get31TileNumberX(l.getLongitude()), leftX);
    rightX = Math.max(MapUtils.get31TileNumberX(l.getLongitude()), rightX);
    bottomY = Math.max(MapUtils.get31TileNumberY(l.getLatitude()), bottomY);
    topY = Math.min(MapUtils.get31TileNumberY(l.getLatitude()), topY);
    params.ctx.getResourceManager().getRenderer().checkInitialized(15, lib, leftX, rightX, bottomY, topY);
    RoutingContext ctx = router.buildRoutingContext(cf, lib, files, RouteCalculationMode.NORMAL);
    RoutingContext complexCtx = null;
    boolean complex = params.mode.isDerivedRoutingFrom(ApplicationMode.CAR) && !settings.DISABLE_COMPLEX_ROUTING.get() && precalculated == null;
    ctx.leftSideNavigation = params.leftSide;
    ctx.calculationProgress = params.calculationProgress;
    if (params.previousToRecalculate != null && params.onlyStartPointChanged) {
        int currentRoute = params.previousToRecalculate.getCurrentRoute();
        List<RouteSegmentResult> originalRoute = params.previousToRecalculate.getOriginalRoute();
        if (originalRoute != null && currentRoute < originalRoute.size()) {
            ctx.previouslyCalculatedRoute = originalRoute.subList(currentRoute, originalRoute.size());
        }
    }
    if (complex && router.getRecalculationEnd(ctx) != null) {
        complex = false;
    }
    if (complex) {
        complexCtx = router.buildRoutingContext(cf, lib, files, RouteCalculationMode.COMPLEX);
        complexCtx.calculationProgress = params.calculationProgress;
        complexCtx.leftSideNavigation = params.leftSide;
        complexCtx.previouslyCalculatedRoute = ctx.previouslyCalculatedRoute;
    }
    LatLon st = new LatLon(params.start.getLatitude(), params.start.getLongitude());
    LatLon en = new LatLon(params.end.getLatitude(), params.end.getLongitude());
    List<LatLon> inters = new ArrayList<LatLon>();
    if (params.intermediates != null) {
        inters = new ArrayList<LatLon>(params.intermediates);
    }
    return calcOfflineRouteImpl(params, router, ctx, complexCtx, st, en, inters, precalculated);
}
Also used : PrecalculatedRouteDirection(net.osmand.router.PrecalculatedRouteDirection) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) ArrayList(java.util.ArrayList) GeneralRouter(net.osmand.router.GeneralRouter) OsmandSettings(net.osmand.plus.OsmandSettings) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LocationPoint(net.osmand.data.LocationPoint) LatLon(net.osmand.data.LatLon) RoutingContext(net.osmand.router.RoutingContext) Builder(net.osmand.router.RoutingConfiguration.Builder) RoutingConfiguration(net.osmand.router.RoutingConfiguration) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd) NativeOsmandLibrary(net.osmand.plus.render.NativeOsmandLibrary) RouteSegmentResult(net.osmand.router.RouteSegmentResult) Location(net.osmand.Location)

Example 15 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class RouteProvider method findBROUTERRoute.

protected RouteCalculationResult findBROUTERRoute(RouteCalculationParams params) throws MalformedURLException, IOException, ParserConfigurationException, FactoryConfigurationError, SAXException {
    int numpoints = 2 + (params.intermediates != null ? params.intermediates.size() : 0);
    double[] lats = new double[numpoints];
    double[] lons = new double[numpoints];
    int index = 0;
    String mode;
    lats[index] = params.start.getLatitude();
    lons[index] = params.start.getLongitude();
    index++;
    if (params.intermediates != null && params.intermediates.size() > 0) {
        for (LatLon il : params.intermediates) {
            lats[index] = il.getLatitude();
            lons[index] = il.getLongitude();
            index++;
        }
    }
    lats[index] = params.end.getLatitude();
    lons[index] = params.end.getLongitude();
    if (ApplicationMode.PEDESTRIAN == params.mode) {
        // $NON-NLS-1$
        mode = "foot";
    } else if (ApplicationMode.BICYCLE == params.mode) {
        // $NON-NLS-1$
        mode = "bicycle";
    } else {
        // $NON-NLS-1$
        mode = "motorcar";
    }
    Bundle bpars = new Bundle();
    bpars.putDoubleArray("lats", lats);
    bpars.putDoubleArray("lons", lons);
    bpars.putString("fast", params.fast ? "1" : "0");
    bpars.putString("v", mode);
    bpars.putString("trackFormat", "gpx");
    OsmandApplication ctx = (OsmandApplication) params.ctx;
    List<Location> res = new ArrayList<Location>();
    IBRouterService brouterService = ctx.getBRouterService();
    if (brouterService == null) {
        return new RouteCalculationResult("BRouter service is not available");
    }
    try {
        String gpxMessage = brouterService.getTrackFromParams(bpars);
        if (gpxMessage == null)
            gpxMessage = "no result from brouter";
        if (!gpxMessage.startsWith("<")) {
            return new RouteCalculationResult(gpxMessage);
        }
        GPXFile gpxFile = GPXUtilities.loadGPXFile(ctx, new ByteArrayInputStream(gpxMessage.getBytes("UTF-8")));
        for (Track track : gpxFile.tracks) {
            for (TrkSegment ts : track.segments) {
                for (WptPt p : ts.points) {
                    // $NON-NLS-1$
                    Location l = new Location("router");
                    l.setLatitude(p.lat);
                    l.setLongitude(p.lon);
                    if (p.ele != Double.NaN) {
                        l.setAltitude(p.ele);
                    }
                    res.add(l);
                }
            }
        }
    } catch (Exception e) {
        // $NON-NLS-1$
        return new RouteCalculationResult("Exception calling BRouter: " + e);
    }
    return new RouteCalculationResult(res, null, params, null, true);
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) OsmandApplication(net.osmand.plus.OsmandApplication) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) TrkSegment(net.osmand.plus.GPXUtilities.TrkSegment) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LocationPoint(net.osmand.data.LocationPoint) JSONException(org.json.JSONException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) LatLon(net.osmand.data.LatLon) ByteArrayInputStream(java.io.ByteArrayInputStream) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) IBRouterService(btools.routingapp.IBRouterService) Track(net.osmand.plus.GPXUtilities.Track) Location(net.osmand.Location)

Aggregations

Location (net.osmand.Location)105 LatLon (net.osmand.data.LatLon)37 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)29 ArrayList (java.util.ArrayList)21 LocationPoint (net.osmand.data.LocationPoint)21 View (android.view.View)13 OsmandApplication (net.osmand.plus.OsmandApplication)12 Paint (android.graphics.Paint)11 TextView (android.widget.TextView)11 ImageView (android.widget.ImageView)10 RouteDataObject (net.osmand.binary.RouteDataObject)9 WptPt (net.osmand.plus.GPXUtilities.WptPt)9 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)8 TargetPointsHelper (net.osmand.plus.TargetPointsHelper)7 PointDescription (net.osmand.data.PointDescription)6 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)6 TIntArrayList (gnu.trove.list.array.TIntArrayList)5 IOException (java.io.IOException)5 QuadPoint (net.osmand.data.QuadPoint)5 MapActivity (net.osmand.plus.activities.MapActivity)5