Search in sources :

Example 56 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)

Example 57 with BinaryMapIndexReader

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

the class CurrentPositionHelper method setRepositories.

public void setRepositories() {
    ArrayList<File> files = new ArrayList<File>();
    File appPath = app.getAppPath(null);
    SampleUtils.collectFiles(appPath, IndexConstants.BINARY_MAP_INDEX_EXT, files);
    readers.clear();
    for (File f : files) {
        try {
            RandomAccessFile mf = new RandomAccessFile(f.getPath(), "r");
            BinaryMapIndexReader reader = new BinaryMapIndexReader(mf, f);
            readers.add(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)

Example 58 with BinaryMapIndexReader

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

the class CurrentPositionHelper method initCtx.

private void initCtx(SampleApplication app, List<BinaryMapIndexReader> checkReaders) {
    BinaryMapIndexReader[] rs = checkReaders.toArray(new BinaryMapIndexReader[checkReaders.size()]);
    if (rs.length > 0) {
        RoutingConfiguration defCfg = RoutingConfiguration.getDefault().build("geocoding", 10, new HashMap<String, String>());
        defCtx = new RoutePlannerFrontEnd(false).buildRoutingContext(defCfg, null, rs);
    } else {
        defCtx = null;
    }
    usedReaders = checkReaders;
}
Also used : RoutingConfiguration(net.osmand.router.RoutingConfiguration) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd)

Example 59 with BinaryMapIndexReader

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

the class MapRenderRepositories method containsLatLonMapData.

public boolean containsLatLonMapData(double lat, double lon, int zoom) {
    int x = MapUtils.get31TileNumberX(lon);
    int y = MapUtils.get31TileNumberY(lat);
    for (BinaryMapIndexReader reader : files.values()) {
        if (reader.containsMapData(x, y, zoom)) {
            return true;
        }
    }
    return false;
}
Also used : BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader)

Example 60 with BinaryMapIndexReader

use of net.osmand.binary.BinaryMapIndexReader in project OsmAnd-tools by osmandapp.

the class DataExtractionSettings method getObfReaders.

public BinaryMapIndexReader[] getObfReaders() throws IOException {
    List<BinaryMapIndexReader> files = new ArrayList<>();
    File mapsFolder = new File(getBinaryFilesDir());
    CachedOsmandIndexes cache = null;
    File cacheFile = new File(mapsFolder, INDEXES_CACHE);
    if (mapsFolder.exists() && obfFiles.isEmpty() && INDEXES_CACHE.length() > 0) {
        cache = new CachedOsmandIndexes();
        if (cacheFile.exists()) {
            cache.readFromFile(cacheFile, 2);
        }
    }
    for (File obf : Algorithms.getSortedFilesVersions(mapsFolder)) {
        if (obf.getName().endsWith(".obf")) {
            BinaryMapIndexReaderReference ref = obfFiles.get(obf.getAbsolutePath());
            if (ref == null || ref.reader == null) {
                ref = new BinaryMapIndexReaderReference();
                ref.file = obf;
                if (cache == null) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    RandomAccessFile raf = new RandomAccessFile(obf, "r");
                    ref.reader = new BinaryMapIndexReader(raf, obf);
                } else {
                    ref.reader = cache.getReader(obf, true);
                }
                obfFiles.put(obf.getAbsolutePath(), ref);
            }
            files.add(ref.reader);
        }
    }
    if (cache != null && !files.isEmpty()) {
        cache.writeToFile(cacheFile);
    }
    return files.toArray(new BinaryMapIndexReader[files.size()]);
}
Also used : RandomAccessFile(java.io.RandomAccessFile) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) ArrayList(java.util.ArrayList) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) CachedOsmandIndexes(net.osmand.binary.CachedOsmandIndexes)

Aggregations

BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)74 File (java.io.File)41 RandomAccessFile (java.io.RandomAccessFile)39 ArrayList (java.util.ArrayList)35 IOException (java.io.IOException)23 LinkedHashMap (java.util.LinkedHashMap)11 MapIndex (net.osmand.binary.BinaryMapIndexReader.MapIndex)11 List (java.util.List)10 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)10 RouteRegion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion)10 RoutePlannerFrontEnd (net.osmand.router.RoutePlannerFrontEnd)10 LatLon (net.osmand.data.LatLon)9 RoutingConfiguration (net.osmand.router.RoutingConfiguration)9 FileOutputStream (java.io.FileOutputStream)8 BinaryIndexPart (net.osmand.binary.BinaryIndexPart)8 AddressRegion (net.osmand.binary.BinaryMapAddressReaderAdapter.AddressRegion)8 PoiRegion (net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion)8 HashMap (java.util.HashMap)7 City (net.osmand.data.City)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6