Search in sources :

Example 1 with MapRoot

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

the class IndexUploader method copyMapIndex.

private static void copyMapIndex(File roadOnlyFile, MapIndex part, BinaryMapIndexReader index, CodedOutputStream ous, RandomAccessFile routf) throws IOException, RTreeException {
    final List<MapRoot> rts = part.getRoots();
    BinaryMapIndexWriter writer = new BinaryMapIndexWriter(routf, ous);
    writer.startWriteMapIndex(part.getName());
    boolean first = true;
    for (MapRoot r : rts) {
        final TLongObjectHashMap<BinaryMapDataObject> objects = new TLongObjectHashMap<BinaryMapDataObject>();
        File nonpackRtree = new File(roadOnlyFile.getParentFile(), "nonpack" + r.getMinZoom() + "." + roadOnlyFile.getName() + ".rtree");
        File packRtree = new File(roadOnlyFile.getParentFile(), "pack" + r.getMinZoom() + "." + roadOnlyFile.getName() + ".rtree");
        RTree rtree = null;
        try {
            rtree = new RTree(nonpackRtree.getAbsolutePath());
            final SearchRequest<BinaryMapDataObject> req = buildSearchRequest(r, objects, rtree);
            index.searchMapIndex(req, part);
            rtree = AbstractIndexPartCreator.packRtreeFile(rtree, nonpackRtree.getAbsolutePath(), packRtree.getAbsolutePath());
            TLongObjectHashMap<BinaryFileReference> treeHeader = new TLongObjectHashMap<BinaryFileReference>();
            long rootIndex = rtree.getFileHdr().getRootIndex();
            rtree.Node root = rtree.getReadNode(rootIndex);
            Rect rootBounds = calcBounds(root);
            if (rootBounds != null) {
                if (first) {
                    writer.writeMapEncodingRules(part.decodingRules);
                    first = false;
                }
                writer.startWriteMapLevelIndex(r.getMinZoom(), r.getMaxZoom(), rootBounds.getMinX(), rootBounds.getMaxX(), rootBounds.getMinY(), rootBounds.getMaxY());
                IndexVectorMapCreator.writeBinaryMapTree(root, rootBounds, rtree, writer, treeHeader);
                writeBinaryMapBlock(root, rootBounds, rtree, writer, treeHeader, objects, r.getMapZoom(), false);
                writer.endWriteMapLevelIndex();
            }
        } finally {
            if (rtree != null) {
                RandomAccessFile file = rtree.getFileHdr().getFile();
                file.close();
            }
            nonpackRtree.delete();
            packRtree.delete();
            RTree.clearCache();
        }
    }
    writer.endWriteMapIndex();
}
Also used : Rect(rtree.Rect) MapRoot(net.osmand.binary.BinaryMapIndexReader.MapRoot) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) BinaryFileReference(net.osmand.data.preparation.BinaryFileReference) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) RandomAccessFile(java.io.RandomAccessFile) Node(rtree.Node) RTree(rtree.RTree) BinaryMapIndexWriter(net.osmand.data.preparation.BinaryMapIndexWriter) RandomAccessFile(java.io.RandomAccessFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 2 with MapRoot

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

the class ObfFileInMemory method readObfFiles.

public void readObfFiles(List<File> files) throws IOException {
    for (int i = 0; i < files.size(); i++) {
        File inputFile = files.get(i);
        File nonGzip = inputFile;
        boolean gzip = false;
        if (inputFile.getName().endsWith(".gz")) {
            nonGzip = new File(inputFile.getParentFile(), inputFile.getName().substring(0, inputFile.getName().length() - 3));
            GZIPInputStream gzin = new GZIPInputStream(new FileInputStream(inputFile));
            FileOutputStream fous = new FileOutputStream(nonGzip);
            Algorithms.streamCopy(gzin, fous);
            fous.close();
            gzin.close();
            gzip = true;
        }
        RandomAccessFile raf = new RandomAccessFile(nonGzip, "r");
        BinaryMapIndexReader indexReader = new BinaryMapIndexReader(raf, nonGzip);
        for (BinaryIndexPart p : indexReader.getIndexes()) {
            if (p instanceof MapIndex) {
                MapIndex mi = (MapIndex) p;
                for (MapRoot mr : mi.getRoots()) {
                    MapZooms.MapZoomPair pair = new MapZooms.MapZoomPair(mr.getMinZoom(), mr.getMaxZoom());
                    TLongObjectHashMap<BinaryMapDataObject> objects = readBinaryMapData(indexReader, mi, mr.getMinZoom());
                    putMapObjects(pair, objects.valueCollection(), true);
                }
            } else if (p instanceof RouteRegion) {
                RouteRegion rr = (RouteRegion) p;
                readRoutingData(indexReader, rr, ZOOM_LEVEL_ROUTING, true);
            } else if (p instanceof PoiRegion) {
                PoiRegion pr = (PoiRegion) p;
                TLongObjectHashMap<Map<String, Amenity>> rr = readPoiData(indexReader, pr, ZOOM_LEVEL_POI, true);
                putPoiData(rr, true);
            } else if (p instanceof TransportIndex) {
            // read all data later
            }
        }
        readTransportData(indexReader, true);
        updateTimestamp(indexReader.getDateCreated());
        indexReader.close();
        raf.close();
        if (gzip) {
            nonGzip.delete();
        }
    }
}
Also used : MapZoomPair(net.osmand.binary.MapZooms.MapZoomPair) BinaryIndexPart(net.osmand.binary.BinaryIndexPart) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) MapRoot(net.osmand.binary.BinaryMapIndexReader.MapRoot) FileInputStream(java.io.FileInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) MapZoomPair(net.osmand.binary.MapZooms.MapZoomPair) RandomAccessFile(java.io.RandomAccessFile) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) FileOutputStream(java.io.FileOutputStream) RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) MapZooms(net.osmand.binary.MapZooms) MapIndex(net.osmand.binary.BinaryMapIndexReader.MapIndex) TransportIndex(net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) TreeMap(java.util.TreeMap) PoiRegion(net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion)

Example 3 with MapRoot

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

the class BinaryInspector method printFileInformation.

public void printFileInformation(RandomAccessFile r, File file) throws IOException {
    String filename = file.getName();
    try {
        BinaryMapIndexReader index = new BinaryMapIndexReader(r, file);
        int i = 1;
        println("Binary index " + filename + " version = " + index.getVersion() + " edition = " + new Date(index.getDateCreated()));
        for (BinaryIndexPart p : index.getIndexes()) {
            String partname = "";
            if (p instanceof MapIndex) {
                partname = "Map";
            } else if (p instanceof TransportIndex) {
                partname = "Transport";
            } else if (p instanceof RouteRegion) {
                partname = "Routing";
            } else if (p instanceof PoiRegion) {
                partname = "Poi";
            } else if (p instanceof AddressRegion) {
                partname = "Address";
            }
            String name = p.getName() == null ? "" : p.getName();
            println(MessageFormat.format("{0} {1} data {3} - {2,number,#} bytes", new Object[] { i, partname, p.getLength(), name }));
            if (p instanceof TransportIndex) {
                TransportIndex ti = ((TransportIndex) p);
                int sh = (31 - BinaryMapIndexReader.TRANSPORT_STOP_ZOOM);
                println("\tBounds " + formatBounds(ti.getLeft() << sh, ti.getRight() << sh, ti.getTop() << sh, ti.getBottom() << sh));
                if ((vInfo != null && vInfo.isVtransport())) {
                    printTransportDetailInfo(vInfo, index, (TransportIndex) p);
                }
            } else if (p instanceof RouteRegion) {
                RouteRegion ri = ((RouteRegion) p);
                println("\tBounds " + formatLatBounds(ri.getLeftLongitude(), ri.getRightLongitude(), ri.getTopLatitude(), ri.getBottomLatitude()));
                if ((vInfo != null && vInfo.isVrouting())) {
                    printRouteDetailInfo(index, (RouteRegion) p);
                }
            } else if (p instanceof MapIndex) {
                MapIndex m = ((MapIndex) p);
                int j = 1;
                for (MapRoot mi : m.getRoots()) {
                    println(MessageFormat.format("\t{4}.{5} Map level minZoom = {0}, maxZoom = {1}, size = {2,number,#} bytes \n\t\tBounds {3}", new Object[] { mi.getMinZoom(), mi.getMaxZoom(), mi.getLength(), formatBounds(mi.getLeft(), mi.getRight(), mi.getTop(), mi.getBottom()), i, j++ }));
                }
                if ((vInfo != null && vInfo.isVmap())) {
                    printMapDetailInfo(index, m);
                }
            } else if (p instanceof PoiRegion && (vInfo != null && vInfo.isVpoi())) {
                printPOIDetailInfo(vInfo, index, (PoiRegion) p);
            } else if (p instanceof TransportIndex && (vInfo != null && vInfo.isVtransport())) {
            } else if (p instanceof AddressRegion) {
                List<CitiesBlock> cities = ((AddressRegion) p).cities;
                for (CitiesBlock c : cities) {
                    println("\t" + i + "." + c.type + " Address part size=" + c.length + " bytes");
                }
                if (vInfo != null && vInfo.isVaddress()) {
                    printAddressDetailedInfo(vInfo, index, (AddressRegion) p);
                }
            }
            i++;
        }
    } catch (IOException e) {
        System.err.println("File doesn't have valid structure : " + filename + " " + e.getMessage());
        throw e;
    }
}
Also used : MapRoot(net.osmand.binary.BinaryMapIndexReader.MapRoot) IOException(java.io.IOException) Date(java.util.Date) RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) MapObject(net.osmand.data.MapObject) TIntArrayList(gnu.trove.list.array.TIntArrayList) List(java.util.List) ArrayList(java.util.ArrayList) TLongArrayList(gnu.trove.list.array.TLongArrayList) MapIndex(net.osmand.binary.BinaryMapIndexReader.MapIndex) CitiesBlock(net.osmand.binary.BinaryMapAddressReaderAdapter.CitiesBlock) TransportIndex(net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex) AddressRegion(net.osmand.binary.BinaryMapAddressReaderAdapter.AddressRegion) PoiRegion(net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion)

Example 4 with MapRoot

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

the class CachedOsmandIndexes method addToCache.

public void addToCache(BinaryMapIndexReader reader, File f) {
    hasChanged = true;
    if (storedIndexBuilder == null) {
        storedIndexBuilder = OsmandIndex.OsmAndStoredIndex.newBuilder();
        storedIndexBuilder.setVersion(VERSION);
        storedIndexBuilder.setDateCreated(System.currentTimeMillis());
        if (storedIndex != null) {
            for (FileIndex ex : storedIndex.getFileIndexList()) {
                storedIndexBuilder.addFileIndex(ex);
            }
        }
    }
    FileIndex.Builder fileIndex = OsmandIndex.FileIndex.newBuilder();
    long d = reader.getDateCreated();
    fileIndex.setDateModified(d == 0 ? f.lastModified() : d);
    fileIndex.setSize(f.length());
    fileIndex.setVersion(reader.getVersion());
    fileIndex.setFileName(f.getName());
    for (MapIndex index : reader.getMapIndexes()) {
        MapPart.Builder map = OsmandIndex.MapPart.newBuilder();
        map.setSize(index.getLength());
        map.setOffset(index.getFilePointer());
        if (index.getName() != null) {
            map.setName(index.getName());
        }
        for (MapRoot mr : index.getRoots()) {
            MapLevel.Builder lev = OsmandIndex.MapLevel.newBuilder();
            lev.setSize(mr.length);
            lev.setOffset(mr.filePointer);
            lev.setLeft(mr.left);
            lev.setRight(mr.right);
            lev.setTop(mr.top);
            lev.setBottom(mr.bottom);
            lev.setMinzoom(mr.minZoom);
            lev.setMaxzoom(mr.maxZoom);
            map.addLevels(lev);
        }
        fileIndex.addMapIndex(map);
    }
    for (AddressRegion index : reader.getAddressIndexes()) {
        AddressPart.Builder addr = OsmandIndex.AddressPart.newBuilder();
        addr.setSize(index.getLength());
        addr.setOffset(index.getFilePointer());
        if (index.getName() != null) {
            addr.setName(index.getName());
        }
        if (index.getEnName() != null) {
            addr.setNameEn(index.getEnName());
        }
        addr.setIndexNameOffset(index.getIndexNameOffset());
        for (CitiesBlock mr : index.getCities()) {
            CityBlock.Builder cblock = OsmandIndex.CityBlock.newBuilder();
            cblock.setSize(mr.length);
            cblock.setOffset(mr.filePointer);
            cblock.setType(mr.type);
            addr.addCities(cblock);
        }
        for (String s : index.getAttributeTagsTable()) {
            addr.addAdditionalTags(s);
        }
        fileIndex.addAddressIndex(addr);
    }
    for (PoiRegion index : reader.getPoiIndexes()) {
        PoiPart.Builder poi = OsmandIndex.PoiPart.newBuilder();
        poi.setSize(index.getLength());
        poi.setOffset(index.getFilePointer());
        if (index.getName() != null) {
            poi.setName(index.getName());
        }
        poi.setLeft(index.left31);
        poi.setRight(index.right31);
        poi.setTop(index.top31);
        poi.setBottom(index.bottom31);
        fileIndex.addPoiIndex(poi.build());
    }
    for (TransportIndex index : reader.getTransportIndexes()) {
        TransportPart.Builder transport = OsmandIndex.TransportPart.newBuilder();
        transport.setSize(index.getLength());
        transport.setOffset(index.getFilePointer());
        if (index.getName() != null) {
            transport.setName(index.getName());
        }
        transport.setLeft(index.getLeft());
        transport.setRight(index.getRight());
        transport.setTop(index.getTop());
        transport.setBottom(index.getBottom());
        transport.setStopsTableLength(index.stopsFileLength);
        transport.setStopsTableOffset(index.stopsFileOffset);
        transport.setStringTableLength(index.stringTable.length);
        transport.setStringTableOffset(index.stringTable.fileOffset);
        fileIndex.addTransportIndex(transport);
    }
    for (RouteRegion index : reader.getRoutingIndexes()) {
        RoutingPart.Builder routing = OsmandIndex.RoutingPart.newBuilder();
        routing.setSize(index.getLength());
        routing.setOffset(index.getFilePointer());
        if (index.getName() != null) {
            routing.setName(index.getName());
        }
        for (RouteSubregion sub : index.getSubregions()) {
            addRouteSubregion(routing, sub, false);
        }
        for (RouteSubregion sub : index.getBaseSubregions()) {
            addRouteSubregion(routing, sub, true);
        }
        fileIndex.addRoutingIndex(routing);
    }
    storedIndexBuilder.addFileIndex(fileIndex);
}
Also used : FileIndex(net.osmand.binary.OsmandIndex.FileIndex) RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) MapPart(net.osmand.binary.OsmandIndex.MapPart) CitiesBlock(net.osmand.binary.BinaryMapAddressReaderAdapter.CitiesBlock) MapLevel(net.osmand.binary.OsmandIndex.MapLevel) AddressRegion(net.osmand.binary.BinaryMapAddressReaderAdapter.AddressRegion) PoiRegion(net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion) RouteSubregion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion) CityBlock(net.osmand.binary.OsmandIndex.CityBlock) RoutingPart(net.osmand.binary.OsmandIndex.RoutingPart) MapRoot(net.osmand.binary.BinaryMapIndexReader.MapRoot) TransportPart(net.osmand.binary.OsmandIndex.TransportPart) PoiPart(net.osmand.binary.OsmandIndex.PoiPart) AddressPart(net.osmand.binary.OsmandIndex.AddressPart) MapIndex(net.osmand.binary.BinaryMapIndexReader.MapIndex) TransportIndex(net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex)

Example 5 with MapRoot

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

the class CachedOsmandIndexes method initFileIndex.

private BinaryMapIndexReader initFileIndex(FileIndex found, RandomAccessFile mf, File f) throws IOException {
    BinaryMapIndexReader reader = new BinaryMapIndexReader(mf, f, false);
    reader.version = found.getVersion();
    reader.dateCreated = found.getDateModified();
    for (MapPart index : found.getMapIndexList()) {
        MapIndex mi = new MapIndex();
        mi.length = (int) index.getSize();
        mi.filePointer = (int) index.getOffset();
        mi.name = index.getName();
        for (MapLevel mr : index.getLevelsList()) {
            MapRoot root = new MapRoot();
            root.length = (int) mr.getSize();
            root.filePointer = (int) mr.getOffset();
            root.left = mr.getLeft();
            root.right = mr.getRight();
            root.top = mr.getTop();
            root.bottom = mr.getBottom();
            root.minZoom = mr.getMinzoom();
            root.maxZoom = mr.getMaxzoom();
            mi.roots.add(root);
        }
        reader.mapIndexes.add(mi);
        reader.indexes.add(mi);
        reader.basemap = reader.basemap || mi.isBaseMap();
    }
    for (AddressPart index : found.getAddressIndexList()) {
        AddressRegion mi = new AddressRegion();
        mi.length = (int) index.getSize();
        mi.filePointer = (int) index.getOffset();
        mi.name = index.getName();
        mi.enName = index.getNameEn();
        mi.indexNameOffset = index.getIndexNameOffset();
        for (CityBlock mr : index.getCitiesList()) {
            CitiesBlock cblock = new CitiesBlock();
            cblock.length = (int) mr.getSize();
            cblock.filePointer = (int) mr.getOffset();
            cblock.type = mr.getType();
            mi.cities.add(cblock);
        }
        for (String s : index.getAdditionalTagsList()) {
            mi.attributeTagsTable.add(s);
        }
        reader.addressIndexes.add(mi);
        reader.indexes.add(mi);
    }
    for (PoiPart index : found.getPoiIndexList()) {
        PoiRegion mi = new PoiRegion();
        mi.length = (int) index.getSize();
        mi.filePointer = (int) index.getOffset();
        mi.name = index.getName();
        mi.left31 = index.getLeft();
        mi.right31 = index.getRight();
        mi.top31 = index.getTop();
        mi.bottom31 = index.getBottom();
        reader.poiIndexes.add(mi);
        reader.indexes.add(mi);
    }
    for (TransportPart index : found.getTransportIndexList()) {
        TransportIndex mi = new TransportIndex();
        mi.length = (int) index.getSize();
        mi.filePointer = (int) index.getOffset();
        mi.name = index.getName();
        mi.left = index.getLeft();
        mi.right = index.getRight();
        mi.top = index.getTop();
        mi.bottom = index.getBottom();
        mi.stopsFileLength = index.getStopsTableLength();
        mi.stopsFileOffset = index.getStopsTableOffset();
        mi.stringTable = new IndexStringTable();
        mi.stringTable.fileOffset = index.getStringTableOffset();
        mi.stringTable.length = index.getStringTableLength();
        reader.transportIndexes.add(mi);
        reader.indexes.add(mi);
    }
    for (RoutingPart index : found.getRoutingIndexList()) {
        RouteRegion mi = new RouteRegion();
        mi.length = (int) index.getSize();
        mi.filePointer = (int) index.getOffset();
        mi.name = index.getName();
        for (RoutingSubregion mr : index.getSubregionsList()) {
            RouteSubregion sub = new RouteSubregion(mi);
            sub.length = (int) mr.getSize();
            sub.filePointer = (int) mr.getOffset();
            sub.left = mr.getLeft();
            sub.right = mr.getRight();
            sub.top = mr.getTop();
            sub.bottom = mr.getBottom();
            sub.shiftToData = mr.getShifToData();
            if (mr.getBasemap()) {
                mi.basesubregions.add(sub);
            } else {
                mi.subregions.add(sub);
            }
        }
        reader.routingIndexes.add(mi);
        reader.indexes.add(mi);
    }
    return reader;
}
Also used : RouteSubregion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion) CityBlock(net.osmand.binary.OsmandIndex.CityBlock) RoutingPart(net.osmand.binary.OsmandIndex.RoutingPart) RoutingSubregion(net.osmand.binary.OsmandIndex.RoutingSubregion) MapRoot(net.osmand.binary.BinaryMapIndexReader.MapRoot) TransportPart(net.osmand.binary.OsmandIndex.TransportPart) IndexStringTable(net.osmand.binary.BinaryMapTransportReaderAdapter.IndexStringTable) PoiPart(net.osmand.binary.OsmandIndex.PoiPart) AddressPart(net.osmand.binary.OsmandIndex.AddressPart) RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) MapPart(net.osmand.binary.OsmandIndex.MapPart) MapIndex(net.osmand.binary.BinaryMapIndexReader.MapIndex) CitiesBlock(net.osmand.binary.BinaryMapAddressReaderAdapter.CitiesBlock) MapLevel(net.osmand.binary.OsmandIndex.MapLevel) AddressRegion(net.osmand.binary.BinaryMapAddressReaderAdapter.AddressRegion) TransportIndex(net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex) PoiRegion(net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion)

Aggregations

MapRoot (net.osmand.binary.BinaryMapIndexReader.MapRoot)7 MapIndex (net.osmand.binary.BinaryMapIndexReader.MapIndex)5 PoiRegion (net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion)5 RouteRegion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion)5 TransportIndex (net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex)5 RandomAccessFile (java.io.RandomAccessFile)4 AddressRegion (net.osmand.binary.BinaryMapAddressReaderAdapter.AddressRegion)4 File (java.io.File)3 CitiesBlock (net.osmand.binary.BinaryMapAddressReaderAdapter.CitiesBlock)3 TIntArrayList (gnu.trove.list.array.TIntArrayList)2 TLongArrayList (gnu.trove.list.array.TLongArrayList)2 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)2 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)2 RouteSubregion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion)2 AddressPart (net.osmand.binary.OsmandIndex.AddressPart)2 CityBlock (net.osmand.binary.OsmandIndex.CityBlock)2