Search in sources :

Example 1 with TransportIndex

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

the class IndexUploader method extractRoadOnlyFile.

public static void extractRoadOnlyFile(File mainFile, File roadOnlyFile) throws IOException, RTreeException {
    RandomAccessFile raf = new RandomAccessFile(mainFile, "r");
    BinaryMapIndexReader index = new BinaryMapIndexReader(raf, mainFile);
    final RandomAccessFile routf = new RandomAccessFile(roadOnlyFile, "rw");
    routf.setLength(0);
    CodedOutputStream ous = CodedOutputStream.newInstance(new OutputStream() {

        @Override
        public void write(int b) throws IOException {
            routf.write(b);
        }

        @Override
        public void write(byte[] b) throws IOException {
            routf.write(b);
        }

        @Override
        public void write(byte[] b, int off, int len) throws IOException {
            routf.write(b, off, len);
        }
    });
    byte[] BUFFER_TO_READ = new byte[BUFFER_SIZE];
    ous.writeInt32(OsmandOdb.OsmAndStructure.VERSION_FIELD_NUMBER, index.getVersion());
    ous.writeInt64(OsmandOdb.OsmAndStructure.DATECREATED_FIELD_NUMBER, index.getDateCreated());
    for (int i = 0; i < index.getIndexes().size(); i++) {
        BinaryIndexPart part = index.getIndexes().get(i);
        if (part instanceof MapIndex) {
            // skip map part
            copyMapIndex(roadOnlyFile, (MapIndex) part, index, ous, routf);
            continue;
        } else if (part instanceof AddressRegion) {
            ous.writeTag(OsmandOdb.OsmAndStructure.ADDRESSINDEX_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
        } else if (part instanceof TransportIndex) {
            ous.writeTag(OsmandOdb.OsmAndStructure.TRANSPORTINDEX_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
        } else if (part instanceof PoiRegion) {
            ous.writeTag(OsmandOdb.OsmAndStructure.POIINDEX_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
        } else if (part instanceof RouteRegion) {
            ous.writeTag(OsmandOdb.OsmAndStructure.ROUTINGINDEX_FIELD_NUMBER, WireFormat.WIRETYPE_FIXED32_LENGTH_DELIMITED);
        } else {
            throw new UnsupportedOperationException();
        }
        BinaryMerger.writeInt(ous, part.getLength());
        BinaryMerger.copyBinaryPart(ous, BUFFER_TO_READ, raf, part.getFilePointer(), part.getLength());
    }
    ous.writeInt32(OsmandOdb.OsmAndStructure.VERSIONCONFIRM_FIELD_NUMBER, index.getVersion());
    ous.flush();
    routf.close();
    raf.close();
}
Also used : BinaryIndexPart(net.osmand.binary.BinaryIndexPart) CodedOutputStream(com.google.protobuf.CodedOutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CodedOutputStream(com.google.protobuf.CodedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) MapIndex(net.osmand.binary.BinaryMapIndexReader.MapIndex) AddressRegion(net.osmand.binary.BinaryMapAddressReaderAdapter.AddressRegion) TransportIndex(net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex) PoiRegion(net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion)

Example 2 with TransportIndex

use of net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex 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 TransportIndex

use of net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex 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 TransportIndex

use of net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex in project Osmand by osmandapp.

the class BinaryMapIndexReader method searchTransportIndex.

public List<TransportStop> searchTransportIndex(SearchRequest<TransportStop> req) throws IOException {
    for (TransportIndex index : transportIndexes) {
        if (index.stopsFileLength == 0 || index.right < req.left || index.left > req.right || index.top > req.bottom || index.bottom < req.top) {
            continue;
        }
        codedIS.seek(index.stopsFileOffset);
        int oldLimit = codedIS.pushLimit(index.stopsFileLength);
        int offset = req.searchResults.size();
        transportAdapter.searchTransportTreeBounds(0, 0, 0, 0, req);
        codedIS.popLimit(oldLimit);
        if (req.stringTable != null) {
            transportAdapter.initializeStringTable(index, req.stringTable);
            for (int i = offset; i < req.searchResults.size(); i++) {
                TransportStop st = req.searchResults.get(i);
                transportAdapter.initializeNames(req.stringTable, st);
            }
        }
    }
    if (req.numberOfVisitedObjects > 0) {
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        log.debug("Search is done. Visit " + req.numberOfVisitedObjects + " objects. Read " + req.numberOfAcceptedObjects + " objects.");
        // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
        log.debug("Read " + req.numberOfReadSubtrees + " subtrees. Go through " + req.numberOfAcceptedSubtrees + " subtrees.");
    }
    return req.getSearchResults();
}
Also used : TransportIndex(net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex) TransportStop(net.osmand.data.TransportStop)

Example 5 with TransportIndex

use of net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex in project Osmand by osmandapp.

the class BinaryMapIndexReader method getTransportRoutes.

/**
 * Transport public methods
 */
public TIntObjectHashMap<TransportRoute> getTransportRoutes(int[] filePointers) throws IOException {
    TIntObjectHashMap<TransportRoute> result = new TIntObjectHashMap<TransportRoute>();
    Map<TransportIndex, TIntArrayList> groupPoints = new HashMap<TransportIndex, TIntArrayList>();
    for (int filePointer : filePointers) {
        TransportIndex ind = getTransportIndex(filePointer);
        if (ind != null) {
            if (!groupPoints.containsKey(ind)) {
                groupPoints.put(ind, new TIntArrayList());
            }
            groupPoints.get(ind).add(filePointer);
        }
    }
    Iterator<Entry<TransportIndex, TIntArrayList>> it = groupPoints.entrySet().iterator();
    if (it.hasNext()) {
        Entry<TransportIndex, TIntArrayList> e = it.next();
        TransportIndex ind = e.getKey();
        TIntArrayList pointers = e.getValue();
        pointers.sort();
        TIntObjectHashMap<String> stringTable = new TIntObjectHashMap<String>();
        for (int i = 0; i < pointers.size(); i++) {
            int filePointer = pointers.get(i);
            TransportRoute transportRoute = transportAdapter.getTransportRoute(filePointer, stringTable, false);
            result.put(filePointer, transportRoute);
        }
        transportAdapter.initializeStringTable(ind, stringTable);
        for (TransportRoute r : result.values(new TransportRoute[result.size()])) {
            transportAdapter.initializeNames(false, r, stringTable);
        }
    }
    return result;
}
Also used : TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) HashMap(java.util.HashMap) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) TIntArrayList(gnu.trove.list.array.TIntArrayList) Entry(java.util.Map.Entry) TransportRoute(net.osmand.data.TransportRoute) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) TransportIndex(net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex)

Aggregations

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