Search in sources :

Example 6 with RoutingMemoryLimits

use of net.osmand.router.RoutingConfiguration.RoutingMemoryLimits in project OsmAnd-tools by osmandapp.

the class ManyToOneRoadCalculation method cut.

private void cut(BinaryMapIndexReader reader) throws IOException {
    RoutePlannerFrontEnd frontEnd = new RoutePlannerFrontEnd();
    RoutingMemoryLimits memoryLimit = new RoutingMemoryLimits(1000, RoutingConfiguration.DEFAULT_NATIVE_MEMORY_LIMIT * 10);
    RoutingConfiguration config = RoutingConfiguration.getDefault().build("car", memoryLimit);
    RouteCalculationMode mode = RouteCalculationMode.BASE;
    RoutingContext ctx = frontEnd.buildRoutingContext(config, null, new BinaryMapIndexReader[] { reader }, mode);
    RouteRegion reg = reader.getRoutingIndexes().get(0);
    List<RouteSubregion> baseSubregions = reg.getBaseSubregions();
    List<RoutingSubregionTile> tiles = new ArrayList<RoutingContext.RoutingSubregionTile>();
    for (RouteSubregion s : baseSubregions) {
        List<RoutingSubregionTile> loadTiles = ctx.loadAllSubregionTiles(reader, s);
        tiles.addAll(loadTiles);
    }
    int zoom = 9;
    int ty = (int) MapUtils.getTileNumberY(zoom, reg.getTopLatitude());
    int by = (int) MapUtils.getTileNumberY(zoom, reg.getBottomLatitude()) + 1;
    int lx = (int) MapUtils.getTileNumberX(zoom, reg.getLeftLongitude());
    int rx = (int) MapUtils.getTileNumberX(zoom, reg.getRightLongitude()) + 1;
    for (int ky = ty + 1; ky < by; ky++) {
        for (int kx = lx + 1; kx < rx; kx++) {
            cutByQuadrant((kx - 1) << (31 - zoom), (ky - 1) << (31 - zoom), kx << (31 - zoom), ky << (31 - zoom), ctx, tiles);
        }
    }
}
Also used : RoutingMemoryLimits(net.osmand.router.RoutingConfiguration.RoutingMemoryLimits) RoutingContext(net.osmand.router.RoutingContext) RouteSubregion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion) RoutingConfiguration(net.osmand.router.RoutingConfiguration) RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd) RouteCalculationMode(net.osmand.router.RoutePlannerFrontEnd.RouteCalculationMode) ArrayList(java.util.ArrayList) TLongArrayList(gnu.trove.list.array.TLongArrayList) RoutingSubregionTile(net.osmand.router.RoutingContext.RoutingSubregionTile)

Example 7 with RoutingMemoryLimits

use of net.osmand.router.RoutingConfiguration.RoutingMemoryLimits in project OsmAnd-tools by osmandapp.

the class ImproveRoadConnectivity method findAllBaseRoadIntersections.

private void findAllBaseRoadIntersections(BinaryMapIndexReader reader, TLongObjectHashMap<List<RouteDataObject>> all, TLongObjectHashMap<List<RouteDataObject>> onlyRoads, TLongHashSet registeredRoadIds) throws IOException {
    RoutePlannerFrontEnd router = new RoutePlannerFrontEnd();
    Builder builder = RoutingConfiguration.getDefault();
    RoutingMemoryLimits memoryLimit = new RoutingMemoryLimits(RoutingConfiguration.DEFAULT_MEMORY_LIMIT * 3, RoutingConfiguration.DEFAULT_NATIVE_MEMORY_LIMIT);
    RoutingConfiguration config = builder.build("car", memoryLimit);
    RoutingContext ctx = router.buildRoutingContext(config, null, new BinaryMapIndexReader[] { reader }, RouteCalculationMode.BASE);
    if (reader.getRoutingIndexes().size() != 1) {
        throw new UnsupportedOperationException();
    }
    RouteRegion reg = reader.getRoutingIndexes().get(0);
    List<RouteSubregion> baseSubregions = reg.getBaseSubregions();
    List<RoutingSubregionTile> tiles = new ArrayList<RoutingContext.RoutingSubregionTile>();
    for (RouteSubregion s : baseSubregions) {
        List<RoutingSubregionTile> loadTiles = ctx.loadAllSubregionTiles(reader, s);
        tiles.addAll(loadTiles);
    }
    for (RoutingSubregionTile tile : tiles) {
        ArrayList<RouteDataObject> dataObjects = new ArrayList<RouteDataObject>();
        ctx.loadSubregionTile(tile, false, dataObjects, null);
        for (RouteDataObject o : dataObjects) {
            registeredRoadIds.add(o.getId());
            int len = o.getPointsLength() - 1;
            double dist = MapUtils.squareRootDist31(o.getPoint31XTile(0), o.getPoint31YTile(0), o.getPoint31XTile(len), o.getPoint31YTile(len));
            boolean shortFerry = "ferry".equals(o.getRoute()) && dist < 1000;
            if (shortFerry) {
                continue;
            }
            boolean link = o.getHighway() != null && (o.getHighway().endsWith("link"));
            long b = calcPointId(o, 0);
            long e = calcPointId(o, len);
            if (!link) {
                addPoint(onlyRoads, o, b);
                addPoint(onlyRoads, o, e);
            }
            for (int i = 0; i < o.getPointsLength(); i++) {
                addPoint(all, o, calcPointId(o, i));
            }
        }
    }
}
Also used : RouteSubregion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion) Builder(net.osmand.router.RoutingConfiguration.Builder) ArrayList(java.util.ArrayList) RoutingMemoryLimits(net.osmand.router.RoutingConfiguration.RoutingMemoryLimits) RoutingContext(net.osmand.router.RoutingContext) RoutingConfiguration(net.osmand.router.RoutingConfiguration) RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd) RouteDataObject(net.osmand.binary.RouteDataObject) RoutingSubregionTile(net.osmand.router.RoutingContext.RoutingSubregionTile)

Example 8 with RoutingMemoryLimits

use of net.osmand.router.RoutingConfiguration.RoutingMemoryLimits in project OsmAnd-tools by osmandapp.

the class MapRouterLayer method selfRoute.

public List<Entity> selfRoute(LatLon start, LatLon end, List<LatLon> intermediates, boolean gpx, List<RouteSegmentResult> previousRoute, RouteCalculationMode rm) {
    this.gpx = gpx;
    List<Entity> res = new ArrayList<Entity>();
    long time = System.currentTimeMillis();
    final boolean animateRoutingCalculation = DataExtractionSettings.getSettings().isAnimateRouting();
    if (animateRoutingCalculation) {
        nextTurn.setVisible(true);
        playPauseButton.setVisible(true);
        stopButton.setVisible(true);
        pause = true;
        playPauseButton.setText("Play");
    }
    stop = false;
    System.out.println("Self made route from " + start + " to " + end);
    if (start != null && end != null) {
        try {
            BinaryMapIndexReader[] files = DataExtractionSettings.getSettings().getObfReaders();
            if (files.length == 0) {
                JOptionPane.showMessageDialog(OsmExtractionUI.MAIN_APP.getFrame(), "Please specify obf file in settings", "Obf file not found", JOptionPane.ERROR_MESSAGE);
                return null;
            }
            String m = DataExtractionSettings.getSettings().getRouteMode();
            String[] props = m.split("\\,");
            RoutePlannerFrontEnd router = new RoutePlannerFrontEnd();
            Map<String, String> paramsR = new LinkedHashMap<String, String>();
            for (String p : props) {
                if (p.contains("=")) {
                    paramsR.put(p.split("=")[0], p.split("=")[1]);
                } else {
                    paramsR.put(p, "true");
                }
            }
            RoutingMemoryLimits memoryLimit = new RoutingMemoryLimits(2000, DEFAULT_NATIVE_MEMORY_LIMIT * 10);
            RoutingConfiguration config = DataExtractionSettings.getSettings().getRoutingConfig().setDirectionPoints(directionPointsFile).build(props[0], /* RoutingConfiguration.DEFAULT_MEMORY_LIMIT */
            memoryLimit, paramsR);
            PrecalculatedRouteDirection precalculatedRouteDirection = null;
            // config.ZOOM_TO_LOAD_TILES = 14;
            try {
                config.routeCalculationTime = new SimpleDateFormat("dd.MM.yyyy HH:mm", Locale.US).parse("19.07.2019 12:40").getTime();
            } catch (Exception e) {
            }
            config.routeCalculationTime = System.currentTimeMillis();
            final RoutingContext ctx = router.buildRoutingContext(config, DataExtractionSettings.getSettings().useNativeRouting() ? NativeSwingRendering.getDefaultFromSettings() : null, files, rm);
            ctx.leftSideNavigation = false;
            ctx.previouslyCalculatedRoute = previousRoute;
            log.info("Use " + config.routerName + " mode for routing");
            final DataTileManager<Entity> points = map.getPoints();
            map.setPoints(points);
            ctx.setVisitor(createSegmentVisitor(animateRoutingCalculation, points));
            // Choose native or not native
            long nt = System.nanoTime();
            startProgressThread(ctx);
            try {
                GpxRouteApproximation gctx = new GpxRouteApproximation(ctx);
                List<GpxPoint> gpxPoints = router.generateGpxPoints(gctx, new LocationsHolder(intermediates));
                List<RouteSegmentResult> searchRoute = gpx ? getGpxAproximation(router, gctx, gpxPoints) : router.searchRoute(ctx, start, end, intermediates, precalculatedRouteDirection);
                throwExceptionIfRouteNotFound(ctx, searchRoute);
                System.out.println("Routing time " + (System.nanoTime() - nt) / 1.0e9f);
                if (animateRoutingCalculation) {
                    playPauseButton.setVisible(false);
                    nextTurn.setText("FINISH");
                    waitNextPress();
                    nextTurn.setText(">>");
                }
                this.previousRoute = searchRoute;
                calculateResult(res, searchRoute);
            } finally {
                if (ctx.calculationProgress != null) {
                    ctx.calculationProgress.isCancelled = true;
                }
            }
        } catch (Exception e) {
            ExceptionHandler.handle(e);
        } finally {
            playPauseButton.setVisible(false);
            nextTurn.setVisible(false);
            stopButton.setVisible(false);
            if (map.getPoints() != null) {
                map.getPoints().clear();
            }
        }
        System.out.println("!!! Finding self route: " + res.size() + " " + (System.currentTimeMillis() - time) + " ms");
    }
    return res;
}
Also used : Entity(net.osmand.osm.edit.Entity) LocationsHolder(net.osmand.LocationsHolder) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) GpxPoint(net.osmand.router.RoutePlannerFrontEnd.GpxPoint) RoutingMemoryLimits(net.osmand.router.RoutingConfiguration.RoutingMemoryLimits) RoutingContext(net.osmand.router.RoutingContext) GpxRouteApproximation(net.osmand.router.RoutePlannerFrontEnd.GpxRouteApproximation) RouteSegmentResult(net.osmand.router.RouteSegmentResult) PrecalculatedRouteDirection(net.osmand.router.PrecalculatedRouteDirection) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) JSONException(org.json.JSONException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) RoutingConfiguration(net.osmand.router.RoutingConfiguration) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

RoutingConfiguration (net.osmand.router.RoutingConfiguration)8 RoutingMemoryLimits (net.osmand.router.RoutingConfiguration.RoutingMemoryLimits)8 RoutingContext (net.osmand.router.RoutingContext)8 RoutePlannerFrontEnd (net.osmand.router.RoutePlannerFrontEnd)7 ArrayList (java.util.ArrayList)6 RouteRegion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion)4 RouteSubregion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion)4 RoutingSubregionTile (net.osmand.router.RoutingContext.RoutingSubregionTile)4 RouteCalculationMode (net.osmand.router.RoutePlannerFrontEnd.RouteCalculationMode)3 TLongArrayList (gnu.trove.list.array.TLongArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)2 RouteDataObject (net.osmand.binary.RouteDataObject)2 Entity (net.osmand.osm.edit.Entity)2 GpxPoint (net.osmand.router.RoutePlannerFrontEnd.GpxPoint)2 Builder (net.osmand.router.RoutingConfiguration.Builder)2 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)1 TLongHashSet (gnu.trove.set.hash.TLongHashSet)1 Point (java.awt.Point)1 File (java.io.File)1