Search in sources :

Example 6 with RoutePlannerFrontEnd

use of net.osmand.router.RoutePlannerFrontEnd 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 7 with RoutePlannerFrontEnd

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

the class ManyToOneRoadCalculation method manyToManyCalculation.

private void manyToManyCalculation(BinaryMapIndexReader reader, double top, double bottom) throws IOException {
    RoutePlannerFrontEnd frontEnd = new RoutePlannerFrontEnd(false);
    RoutingConfiguration config = RoutingConfiguration.getDefault().build("car", 1000);
    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 st = MapUtils.get31TileNumberY(top);
    int sb = MapUtils.get31TileNumberY(bottom);
    List<ManyToManySegment> topIntersects = new ArrayList<ManyToManySegment>();
    List<ManyToManySegment> bottomIntersects = new ArrayList<ManyToManySegment>();
    TLongObjectHashMap<ManyToManySegment> allSegments = initSegments(st, sb, ctx, tiles, topIntersects, bottomIntersects);
    filterDisconnected(ctx, allSegments, topIntersects);
    filterDisconnected(ctx, allSegments, topIntersects);
    System.out.println("TOP " + topIntersects.size());
    System.out.println("BOTTOM " + bottomIntersects.size());
    calculateManyToMany(ctx, allSegments, topIntersects, bottomIntersects, st, sb);
}
Also used : RouteSubregion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion) ArrayList(java.util.ArrayList) TLongArrayList(gnu.trove.list.array.TLongArrayList) RoutingContext(net.osmand.router.RoutingContext) RoutingConfiguration(net.osmand.router.RoutingConfiguration) RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd) RouteCalculationMode(net.osmand.router.RoutePlannerFrontEnd.RouteCalculationMode) RoutingSubregionTile(net.osmand.router.RoutingContext.RoutingSubregionTile)

Example 8 with RoutePlannerFrontEnd

use of net.osmand.router.RoutePlannerFrontEnd 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 9 with RoutePlannerFrontEnd

use of net.osmand.router.RoutePlannerFrontEnd 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 10 with RoutePlannerFrontEnd

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

the class CheckRoadConnectivity method calculateDisconnectedRoadsToAddAndDelete.

private TLongObjectHashMap<RouteDataObject> calculateDisconnectedRoadsToAddAndDelete(TLongObjectHashMap<List<RouteDataObject>> mapOfObjectToCheck, TLongObjectHashMap<List<RouteDataObject>> all, BinaryMapIndexReader reader, TLongHashSet setToRemove, TLongHashSet registeredIds) {
    RoutePlannerFrontEnd frontEnd = new RoutePlannerFrontEnd(false);
    RoutingConfiguration config = RoutingConfiguration.getDefault().build("car", 1000);
    long[] keys = mapOfObjectToCheck.keys();
    TLongObjectHashMap<RouteDataObject> toAdd = new TLongObjectHashMap<RouteDataObject>();
    TLongHashSet beginIsolated = new TLongHashSet();
    TLongHashSet endIsolated = new TLongHashSet();
    for (int k = 0; k < keys.length; k++) {
        long point = keys[k];
        if (all.get(point).size() == 1) {
            RouteDataObject rdo = all.get(keys[k]).get(0);
            boolean begin = calcPointId(rdo, 0) == point;
            RoutingContext ctx = frontEnd.buildRoutingContext(config, null, new BinaryMapIndexReader[] { reader }, RouteCalculationMode.NORMAL);
            List<RouteDataObject> result = findConnectedRoads(ctx, rdo, begin, all);
            if (result == null) {
                if (begin) {
                    beginIsolated.add(rdo.getId());
                } else {
                    endIsolated.add(rdo.getId());
                }
            } else {
                for (RouteDataObject obj : result) {
                    if (!registeredIds.contains(obj.id)) {
                        toAdd.put(obj.id, obj);
                    }
                }
            }
        }
    }
    int begSize = beginIsolated.size();
    int endSize = endIsolated.size();
    beginIsolated.retainAll(endIsolated);
    int intersectionSize = beginIsolated.size();
    if (setToRemove != null) {
        setToRemove.addAll(beginIsolated);
    }
    System.out.println("All objects in base file " + mapOfObjectToCheck.size() + " to keep isolated " + (begSize + endSize - 2 * intersectionSize) + " to add " + toAdd.size() + " to remove " + beginIsolated.size());
    return toAdd;
}
Also used : RoutingContext(net.osmand.router.RoutingContext) RoutingConfiguration(net.osmand.router.RoutingConfiguration) TLongHashSet(gnu.trove.set.hash.TLongHashSet) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) RouteDataObject(net.osmand.binary.RouteDataObject)

Aggregations

RoutePlannerFrontEnd (net.osmand.router.RoutePlannerFrontEnd)13 RoutingConfiguration (net.osmand.router.RoutingConfiguration)12 RoutingContext (net.osmand.router.RoutingContext)10 ArrayList (java.util.ArrayList)9 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)7 Builder (net.osmand.router.RoutingConfiguration.Builder)5 File (java.io.File)4 RandomAccessFile (java.io.RandomAccessFile)4 RouteRegion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion)4 RouteSubregion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion)4 LatLon (net.osmand.data.LatLon)4 RoutingSubregionTile (net.osmand.router.RoutingContext.RoutingSubregionTile)4 Point (java.awt.Point)3 RouteDataObject (net.osmand.binary.RouteDataObject)3 RouteSegmentResult (net.osmand.router.RouteSegmentResult)3 TLongArrayList (gnu.trove.list.array.TLongArrayList)2 TLongHashSet (gnu.trove.set.hash.TLongHashSet)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Entity (net.osmand.osm.edit.Entity)2 Way (net.osmand.osm.edit.Way)2