Search in sources :

Example 1 with BinaryMapReaderResource

use of net.osmand.plus.resources.ResourceManager.BinaryMapReaderResource in project Osmand by osmandapp.

the class CurrentPositionHelper method checkReaders.

private List<BinaryMapReaderResource> checkReaders(double lat, double lon, List<BinaryMapReaderResource> ur) {
    List<BinaryMapReaderResource> res = ur;
    for (BinaryMapReaderResource t : ur) {
        if (t.isClosed()) {
            res = new ArrayList<>();
            break;
        }
    }
    int y31 = MapUtils.get31TileNumberY(lat);
    int x31 = MapUtils.get31TileNumberX(lon);
    for (BinaryMapReaderResource r : app.getResourceManager().getFileReaders()) {
        if (!r.isClosed() && r.getShallowReader().containsRouteData(x31, y31, x31, y31, 15)) {
            if (!res.contains(r)) {
                res = new ArrayList<>(res);
                res.add(r);
            }
        }
    }
    return res;
}
Also used : BinaryMapReaderResource(net.osmand.plus.resources.ResourceManager.BinaryMapReaderResource)

Example 2 with BinaryMapReaderResource

use of net.osmand.plus.resources.ResourceManager.BinaryMapReaderResource 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<BinaryMapReaderResource> rts = usedReaders;
            for (BinaryMapReaderResource rt : rts) {
                if (rt.isClosed()) {
                    continue;
                }
                BinaryMapIndexReader reader = rt.getReader(BinaryMapReaderResourceType.STREET_LOOKUP);
                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 : BinaryMapReaderResource(net.osmand.plus.resources.ResourceManager.BinaryMapReaderResource) 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 3 with BinaryMapReaderResource

use of net.osmand.plus.resources.ResourceManager.BinaryMapReaderResource in project Osmand by osmandapp.

the class CurrentPositionHelper method initCtx.

private void initCtx(OsmandApplication app, List<BinaryMapReaderResource> checkReaders, @NonNull ApplicationMode appMode) {
    am = appMode;
    String p;
    if (am.isDerivedRoutingFrom(ApplicationMode.BICYCLE)) {
        p = GeneralRouterProfile.BICYCLE.name().toLowerCase();
    } else if (am.isDerivedRoutingFrom(ApplicationMode.PEDESTRIAN)) {
        p = GeneralRouterProfile.PEDESTRIAN.name().toLowerCase();
    } else if (am.isDerivedRoutingFrom(ApplicationMode.CAR)) {
        p = GeneralRouterProfile.CAR.name().toLowerCase();
    } else {
        p = "geocoding";
    }
    BinaryMapIndexReader[] rs = new BinaryMapIndexReader[checkReaders.size()];
    if (rs.length > 0) {
        int i = 0;
        for (BinaryMapReaderResource rep : checkReaders) {
            rs[i++] = rep.getReader(BinaryMapReaderResourceType.STREET_LOOKUP);
        }
        RoutingConfiguration cfg = app.getDefaultRoutingConfig().build(p, 10, new HashMap<String, String>());
        ctx = new RoutePlannerFrontEnd(false).buildRoutingContext(cfg, null, rs);
        RoutingConfiguration defCfg = app.getDefaultRoutingConfig().build("geocoding", 10, new HashMap<String, String>());
        defCtx = new RoutePlannerFrontEnd(false).buildRoutingContext(defCfg, null, rs);
    } else {
        ctx = null;
        defCtx = null;
    }
    usedReaders = checkReaders;
}
Also used : BinaryMapReaderResource(net.osmand.plus.resources.ResourceManager.BinaryMapReaderResource) RoutingConfiguration(net.osmand.router.RoutingConfiguration) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd)

Aggregations

BinaryMapReaderResource (net.osmand.plus.resources.ResourceManager.BinaryMapReaderResource)3 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 RouteRegion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion)1 GeocodingUtilities (net.osmand.binary.GeocodingUtilities)1 GeocodingResult (net.osmand.binary.GeocodingUtilities.GeocodingResult)1 RoutePlannerFrontEnd (net.osmand.router.RoutePlannerFrontEnd)1 RoutingConfiguration (net.osmand.router.RoutingConfiguration)1