Search in sources :

Example 41 with BinaryMapIndexReader

use of net.osmand.binary.BinaryMapIndexReader 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 42 with BinaryMapIndexReader

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

Example 43 with BinaryMapIndexReader

use of net.osmand.binary.BinaryMapIndexReader in project Osmand by osmandapp.

the class TestRouting method runAllTests.

public static boolean runAllTests(Parameters params, NativeLibrary lib) throws FileNotFoundException, IOException, Exception {
    BinaryMapIndexReader[] rs = collectFiles(params.obfDir.getAbsolutePath());
    boolean allSuccess = true;
    for (File f : params.tests) {
        System.out.println("Before test " + f.getAbsolutePath());
        System.out.flush();
        allSuccess &= test(lib, new FileInputStream(f), rs, params.configBuilder);
    }
    return allSuccess;
}
Also used : BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 44 with BinaryMapIndexReader

use of net.osmand.binary.BinaryMapIndexReader in project Osmand by osmandapp.

the class SearchPhrase method getDiffsByRegion.

private Map<String, List<BinaryMapIndexReader>> getDiffsByRegion() {
    Map<String, List<BinaryMapIndexReader>> result = new HashMap<>();
    Iterator<BinaryMapIndexReader> it = indexes.iterator();
    while (it.hasNext()) {
        BinaryMapIndexReader r = it.next();
        if (r == null || r.getFile() == null) {
            continue;
        }
        String filename = r.getFile().getName();
        if (filename.matches("([a-zA-Z-]+_)+([0-9]+_){2}[0-9]+\\.obf")) {
            String currRegionName = r.getRegionName();
            if (result.containsKey(currRegionName)) {
                result.get(currRegionName).add(r);
            } else {
                result.put(currRegionName, new ArrayList<>(Arrays.asList(r)));
            }
            it.remove();
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) ArrayList(java.util.ArrayList) List(java.util.List)

Example 45 with BinaryMapIndexReader

use of net.osmand.binary.BinaryMapIndexReader in project Osmand by osmandapp.

the class ResourceManager method setRepositories.

private void setRepositories() {
    ArrayList<File> files = new ArrayList<>();
    File appPath = app.getAppPath(null);
    SampleUtils.collectFiles(appPath, IndexConstants.BINARY_MAP_INDEX_EXT, files);
    SampleUtils.collectFiles(app.getAppPath(IndexConstants.WIKI_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files);
    for (File f : files) {
        try {
            RandomAccessFile mf = new RandomAccessFile(f.getPath(), "r");
            BinaryMapIndexReader reader = new BinaryMapIndexReader(mf, f);
            if (reader.containsPoiData()) {
                amenityRepositories.put(f.getName(), new AmenityIndexRepositoryBinary(reader));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) ArrayList(java.util.ArrayList) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Aggregations

BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)48 File (java.io.File)26 RandomAccessFile (java.io.RandomAccessFile)25 ArrayList (java.util.ArrayList)24 IOException (java.io.IOException)16 List (java.util.List)7 RoutePlannerFrontEnd (net.osmand.router.RoutePlannerFrontEnd)7 RoutingConfiguration (net.osmand.router.RoutingConfiguration)7 LinkedHashMap (java.util.LinkedHashMap)6 LatLon (net.osmand.data.LatLon)6 HashMap (java.util.HashMap)5 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)5 MapIndex (net.osmand.binary.BinaryMapIndexReader.MapIndex)5 RouteRegion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion)5 City (net.osmand.data.City)5 RoutingContext (net.osmand.router.RoutingContext)5 Point (java.awt.Point)4 FileOutputStream (java.io.FileOutputStream)4 GeocodingResult (net.osmand.binary.GeocodingUtilities.GeocodingResult)4 TLongHashSet (gnu.trove.set.hash.TLongHashSet)3