Search in sources :

Example 1 with Builder

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

the class CheckRoadConnectivity method clustering.

public void clustering(final ClusteringContext clusterCtx, BinaryMapIndexReader reader) throws IOException {
    RoutePlannerFrontEnd router = new RoutePlannerFrontEnd(false);
    Builder builder = RoutingConfiguration.getDefault();
    RoutingConfiguration config = builder.build("car", RoutingConfiguration.DEFAULT_MEMORY_LIMIT * 3);
    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);
    }
    List<Cluster> allClusters = new ArrayList<CheckRoadConnectivity.Cluster>();
    for (RoutingSubregionTile tile : tiles) {
        List<Cluster> clusters = processDataObjects(ctx, tile);
        allClusters.addAll(clusters);
    }
    combineClusters(allClusters, tiles);
}
Also used : RouteSubregion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion) Builder(net.osmand.router.RoutingConfiguration.Builder) ArrayList(java.util.ArrayList) RoutingContext(net.osmand.router.RoutingContext) RoutingConfiguration(net.osmand.router.RoutingConfiguration) RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd) RoutingSubregionTile(net.osmand.router.RoutingContext.RoutingSubregionTile)

Example 2 with Builder

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

the class DataExtractionSettings method getRoutingConfig.

public Builder getRoutingConfig() {
    Builder builder;
    String xmlPath = getRoutingXmlPath();
    if (xmlPath.equals("routing.xml")) {
        builder = RoutingConfiguration.getDefault();
    } else {
        try {
            builder = RoutingConfiguration.parseFromInputStream(new FileInputStream(xmlPath));
        } catch (IOException e) {
            throw new IllegalArgumentException("Error parsing routing.xml file", e);
        } catch (XmlPullParserException e) {
            throw new IllegalArgumentException("Error parsing routing.xml file", e);
        }
    }
    return builder;
}
Also used : Builder(net.osmand.router.RoutingConfiguration.Builder) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 3 with Builder

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

the class MapClusterLayer method clustering.

private List<RouteSegment> clustering(final ClusteringContext clusterCtx, double lat, double lon, final DataTileManager<Way> points) throws IOException {
    List<BinaryMapIndexReader> rs = new ArrayList<BinaryMapIndexReader>();
    for (File f : new File(DataExtractionSettings.getSettings().getBinaryFilesDir()).listFiles()) {
        if (f.getName().endsWith(".obf")) {
            // $NON-NLS-1$ //$NON-NLS-2$
            RandomAccessFile raf = new RandomAccessFile(f, "r");
            rs.add(new BinaryMapIndexReader(raf, f));
        }
    }
    RoutePlannerFrontEnd router = new RoutePlannerFrontEnd(true);
    Builder builder = RoutingConfiguration.getDefault();
    RoutingConfiguration config = builder.build("car", RoutingConfiguration.DEFAULT_MEMORY_LIMIT * 3);
    RoutingContext ctx = router.buildRoutingContext(config, NativeSwingRendering.getDefaultFromSettings(), rs.toArray(new BinaryMapIndexReader[rs.size()]), clusterCtx.BASEMAP_CLUSTERING ? RouteCalculationMode.BASE : RouteCalculationMode.NORMAL);
    // find closest way
    RouteSegment st = router.findRouteSegment(lat, lon, ctx, null);
    if (st != null) {
        RouteDataObject road = st.getRoad();
        String highway = getHighway(road);
        log.info(// road.getName() + " "
        "ROAD TO START " + highway + " " + +road.id);
    }
    map.setPoints(points);
    ctx.setVisitor(new RouteSegmentVisitor() {

        private List<RouteSegment> cache = new ArrayList<RouteSegment>();

        @Override
        public void visitSegment(RouteSegment s, int endSegment, boolean poll) {
            if (!clusterCtx.ANIMATE_CLUSTERING) {
                return;
            }
            cache.add(s);
            if (cache.size() < SIZE_OF_ROUTES_TO_ANIMATE) {
                return;
            }
            for (RouteSegment segment : cache) {
                Way way = new Way(-1);
                for (int i = 0; i < segment.getRoad().getPointsLength(); i++) {
                    net.osmand.osm.edit.Node n = new net.osmand.osm.edit.Node(MapUtils.get31LatitudeY(segment.getRoad().getPoint31YTile(i)), MapUtils.get31LongitudeX(segment.getRoad().getPoint31XTile(i)), -1);
                    way.addNode(n);
                }
                way.putTag("color", "white");
                LatLon n = way.getLatLon();
                points.registerObject(n.getLatitude(), n.getLongitude(), way);
            }
            cache.clear();
            try {
                SwingUtilities.invokeAndWait(new Runnable() {

                    @Override
                    public void run() {
                        map.prepareImage();
                    }
                });
            } catch (InterruptedException e1) {
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        }
    });
    List<RouteSegment> results = searchCluster(clusterCtx, ctx, st);
    return results;
}
Also used : Builder(net.osmand.router.RoutingConfiguration.Builder) ArrayList(java.util.ArrayList) RouteSegmentVisitor(net.osmand.router.BinaryRoutePlanner.RouteSegmentVisitor) Way(net.osmand.osm.edit.Way) RoutingContext(net.osmand.router.RoutingContext) RouteSegment(net.osmand.router.BinaryRoutePlanner.RouteSegment) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) Point(java.awt.Point) InvocationTargetException(java.lang.reflect.InvocationTargetException) LatLon(net.osmand.data.LatLon) RandomAccessFile(java.io.RandomAccessFile) RoutingConfiguration(net.osmand.router.RoutingConfiguration) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd) RouteDataObject(net.osmand.binary.RouteDataObject) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 4 with Builder

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

the class CheckRoadConnectivity method findAllBaseRoadIntersections.

private void findAllBaseRoadIntersections(BinaryMapIndexReader reader, TLongObjectHashMap<List<RouteDataObject>> all, TLongObjectHashMap<List<RouteDataObject>> onlyRoads, TLongHashSet registeredRoadIds) throws IOException {
    RoutePlannerFrontEnd router = new RoutePlannerFrontEnd(false);
    Builder builder = RoutingConfiguration.getDefault();
    RoutingConfiguration config = builder.build("car", RoutingConfiguration.DEFAULT_MEMORY_LIMIT * 3);
    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) 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 5 with Builder

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

the class DijkstraAlgorithm method main.

public static void main(String[] args) throws IOException, InterruptedException, XmlPullParserException {
    File fl = new File("/Users/victorshcherb/osmand/maps/Netherlands_europe_2.obf");
    // $NON-NLS-1$ //$NON-NLS-2$
    RandomAccessFile raf = new RandomAccessFile(fl, "r");
    RoutePlannerFrontEnd fe = new RoutePlannerFrontEnd(false);
    Builder builder = RoutingConfiguration.parseFromInputStream(new FileInputStream("/Users/victorshcherb/osmand/repos/resources/routing/routing.xml"));
    RoutingConfiguration config = builder.build("car", RoutingConfiguration.DEFAULT_MEMORY_LIMIT * 3);
    RoutingContext ctx = fe.buildRoutingContext(config, null, new BinaryMapIndexReader[] { new BinaryMapIndexReader(raf, fl) }, RouteCalculationMode.NORMAL);
    RouteResultPreparation.PRINT_TO_CONSOLE_ROUTE_INFORMATION_TO_TEST = true;
    List<RouteSegmentResult> route = fe.searchRoute(ctx, new LatLon(52.28283, 4.8622713), new LatLon(52.326496, 4.8753176), null);
}
Also used : LatLon(net.osmand.data.LatLon) RoutingContext(net.osmand.router.RoutingContext) RandomAccessFile(java.io.RandomAccessFile) RoutingConfiguration(net.osmand.router.RoutingConfiguration) Builder(net.osmand.router.RoutingConfiguration.Builder) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) FileInputStream(java.io.FileInputStream) RouteSegmentResult(net.osmand.router.RouteSegmentResult)

Aggregations

Builder (net.osmand.router.RoutingConfiguration.Builder)6 RoutePlannerFrontEnd (net.osmand.router.RoutePlannerFrontEnd)4 RoutingConfiguration (net.osmand.router.RoutingConfiguration)4 RoutingContext (net.osmand.router.RoutingContext)4 ArrayList (java.util.ArrayList)3 LatLon (net.osmand.data.LatLon)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 RandomAccessFile (java.io.RandomAccessFile)2 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)2 RouteRegion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion)2 RouteSubregion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion)2 RouteDataObject (net.osmand.binary.RouteDataObject)2 RouteSegment (net.osmand.router.BinaryRoutePlanner.RouteSegment)2 RoutingSubregionTile (net.osmand.router.RoutingContext.RoutingSubregionTile)2 Point (java.awt.Point)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Way (net.osmand.osm.edit.Way)1 FinalRouteSegment (net.osmand.router.BinaryRoutePlanner.FinalRouteSegment)1