Search in sources :

Example 11 with RouteRegion

use of net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion in project Osmand by osmandapp.

the class RoutePlannerFrontEnd method runNativeRouting.

private List<RouteSegmentResult> runNativeRouting(final RoutingContext ctx, RouteSegment recalculationEnd) throws IOException {
    refreshProgressDistance(ctx);
    RouteRegion[] regions = ctx.reverseMap.keySet().toArray(new BinaryMapRouteReaderAdapter.RouteRegion[ctx.reverseMap.size()]);
    ctx.checkOldRoutingFiles(ctx.startX, ctx.startY);
    ctx.checkOldRoutingFiles(ctx.targetX, ctx.targetY);
    long time = System.currentTimeMillis();
    RouteSegmentResult[] res = ctx.nativeLib.runNativeRouting(ctx.startX, ctx.startY, ctx.targetX, ctx.targetY, ctx.config, regions, ctx.calculationProgress, ctx.precalculatedRouteDirection, ctx.calculationMode == RouteCalculationMode.BASE);
    log.info("Native routing took " + (System.currentTimeMillis() - time) / 1000f + " seconds");
    ArrayList<RouteSegmentResult> result = new ArrayList<RouteSegmentResult>(Arrays.asList(res));
    if (recalculationEnd != null) {
        log.info("Native routing use precalculated route");
        RouteSegment current = recalculationEnd;
        while (current.getParentRoute() != null) {
            RouteSegment pr = current.getParentRoute();
            result.add(new RouteSegmentResult(pr.getRoad(), current.getParentSegmentEnd(), pr.getSegmentStart()));
            current = pr;
        }
    }
    ctx.routingTime = ctx.calculationProgress.routingCalculatedTime;
    ctx.visitedSegments = ctx.calculationProgress.visitedSegments;
    ctx.loadedTiles = ctx.calculationProgress.loadedTiles;
    return new RouteResultPreparation().prepareResult(ctx, result);
}
Also used : RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) ArrayList(java.util.ArrayList) BinaryMapRouteReaderAdapter(net.osmand.binary.BinaryMapRouteReaderAdapter) RouteSegment(net.osmand.router.BinaryRoutePlanner.RouteSegment)

Example 12 with RouteRegion

use of net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion in project Osmand by osmandapp.

the class RoutingContext method checkOldRoutingFiles.

public void checkOldRoutingFiles(BinaryMapIndexReader key) {
    if (calculationMode == RouteCalculationMode.BASE && key.getDateCreated() < 1390172400000l) {
        // new SimpleDateFormat("dd-MM-yyyy").parse("20-01-2014").getTime()
        System.err.println("Old routing file : " + key.getDateCreated() + " " + new Date(key.getDateCreated()));
        String map = "";
        for (RouteRegion r : key.getRoutingIndexes()) {
            map = r.getName();
        }
        throw new RuntimeException("Update map '" + map + "' !");
    }
}
Also used : RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) Date(java.util.Date)

Example 13 with RouteRegion

use of net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion in project Osmand by osmandapp.

the class CurrentPositionHelper method justifyResult.

private void justifyResult(List<GeocodingResult> res, final ResultMatcher<GeocodingResult> result) {
    List<GeocodingResult> complete = new ArrayList<>();
    double minBuildingDistance = 0;
    if (res != null) {
        for (GeocodingResult r : res) {
            BinaryMapIndexReader foundRepo = null;
            List<BinaryMapIndexReader> rts = usedReaders;
            for (BinaryMapIndexReader reader : rts) {
                for (RouteRegion rb : reader.getRoutingIndexes()) {
                    if (r.regionFP == rb.getFilePointer() && r.regionLen == rb.getLength()) {
                        foundRepo = reader;
                        break;
                    }
                }
            }
            if (result.isCancelled()) {
                break;
            } else if (foundRepo != null) {
                List<GeocodingResult> justified = null;
                try {
                    justified = new GeocodingUtilities().justifyReverseGeocodingSearch(r, foundRepo, minBuildingDistance, result);
                } catch (IOException e) {
                    log.error("Exception happened during reverse geocoding", e);
                    e.printStackTrace();
                }
                if (justified != null && !justified.isEmpty()) {
                    double md = justified.get(0).getDistance();
                    if (minBuildingDistance == 0) {
                        minBuildingDistance = md;
                    } else {
                        minBuildingDistance = Math.min(md, minBuildingDistance);
                    }
                    complete.addAll(justified);
                }
            } else {
                complete.add(r);
            }
        }
    }
    if (result.isCancelled()) {
        app.runInUIThread(new Runnable() {

            public void run() {
                result.publish(null);
            }
        });
        return;
    }
    Collections.sort(complete, GeocodingUtilities.DISTANCE_COMPARATOR);
    // for(GeocodingResult rt : complete) {
    // System.out.println(rt.toString());
    // }
    final GeocodingResult rts = complete.size() > 0 ? complete.get(0) : new GeocodingResult();
    app.runInUIThread(new Runnable() {

        public void run() {
            result.publish(rts);
        }
    });
}
Also used : GeocodingResult(net.osmand.binary.GeocodingUtilities.GeocodingResult) RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) ArrayList(java.util.ArrayList) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) GeocodingUtilities(net.osmand.binary.GeocodingUtilities)

Example 14 with RouteRegion

use of net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion 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 15 with RouteRegion

use of net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion 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)

Aggregations

RouteRegion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion)20 ArrayList (java.util.ArrayList)9 MapIndex (net.osmand.binary.BinaryMapIndexReader.MapIndex)7 PoiRegion (net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion)7 RouteSubregion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion)7 TransportIndex (net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex)7 IOException (java.io.IOException)6 AddressRegion (net.osmand.binary.BinaryMapAddressReaderAdapter.AddressRegion)6 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)5 MapRoot (net.osmand.binary.BinaryMapIndexReader.MapRoot)5 TLongArrayList (gnu.trove.list.array.TLongArrayList)4 RoutePlannerFrontEnd (net.osmand.router.RoutePlannerFrontEnd)4 RoutingConfiguration (net.osmand.router.RoutingConfiguration)4 RoutingContext (net.osmand.router.RoutingContext)4 RoutingSubregionTile (net.osmand.router.RoutingContext.RoutingSubregionTile)4 FileOutputStream (java.io.FileOutputStream)3 RandomAccessFile (java.io.RandomAccessFile)3 List (java.util.List)3 CitiesBlock (net.osmand.binary.BinaryMapAddressReaderAdapter.CitiesBlock)3 GeocodingResult (net.osmand.binary.GeocodingUtilities.GeocodingResult)3