Search in sources :

Example 11 with PoiRegion

use of net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion in project Osmand by osmandapp.

the class BinaryMapIndexReader method main.

public static void main(String[] args) throws IOException {
    File fl = new File(System.getProperty("maps") + "/Synthetic_test_rendering.obf");
    fl = new File(System.getProperty("maps") + "/Map.obf");
    RandomAccessFile raf = new RandomAccessFile(fl, "r");
    BinaryMapIndexReader reader = new BinaryMapIndexReader(raf, fl);
    // $NON-NLS-1$
    println("VERSION " + reader.getVersion());
    long time = System.currentTimeMillis();
    if (testMapSearch) {
        testMapSearch(reader);
    }
    if (testAddressSearchName) {
        testAddressSearchByName(reader);
    }
    if (testAddressSearch) {
        testAddressSearch(reader);
    }
    if (testAddressJustifySearch) {
        testAddressJustifySearch(reader);
    }
    if (testTransportSearch) {
        testTransportSearch(reader);
    }
    if (testPoiSearch || testPoiSearchOnPath) {
        PoiRegion poiRegion = reader.getPoiIndexes().get(0);
        if (testPoiSearch) {
            testPoiSearch(reader, poiRegion);
            testPoiSearchByName(reader);
        }
        if (testPoiSearchOnPath) {
            testSearchOnthePath(reader);
        }
    }
    // $NON-NLS-1$
    println("MEMORY " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));
    // $NON-NLS-1$
    println("Time " + (System.currentTimeMillis() - time));
}
Also used : RandomAccessFile(java.io.RandomAccessFile) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) PoiRegion(net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion)

Example 12 with PoiRegion

use of net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion in project Osmand by osmandapp.

the class BinaryMapIndexReader method init.

private void init() throws IOException {
    boolean initCorrectly = false;
    while (true) {
        int t = codedIS.readTag();
        int tag = WireFormat.getTagFieldNumber(t);
        switch(tag) {
            case 0:
                if (!initCorrectly) {
                    // $NON-NLS-1$
                    throw new IOException("Corrupt file, it should have ended as it starts with version: " + file.getName());
                }
                return;
            case OsmandOdb.OsmAndStructure.VERSION_FIELD_NUMBER:
                version = codedIS.readUInt32();
                break;
            case OsmandOdb.OsmAndStructure.DATECREATED_FIELD_NUMBER:
                dateCreated = codedIS.readInt64();
                break;
            case OsmandOdb.OsmAndStructure.MAPINDEX_FIELD_NUMBER:
                MapIndex mapIndex = new MapIndex();
                mapIndex.length = readInt();
                mapIndex.filePointer = codedIS.getTotalBytesRead();
                int oldLimit = codedIS.pushLimit(mapIndex.length);
                readMapIndex(mapIndex, false);
                basemap = basemap || mapIndex.isBaseMap();
                codedIS.popLimit(oldLimit);
                codedIS.seek(mapIndex.filePointer + mapIndex.length);
                mapIndexes.add(mapIndex);
                indexes.add(mapIndex);
                break;
            case OsmandOdb.OsmAndStructure.ADDRESSINDEX_FIELD_NUMBER:
                AddressRegion region = new AddressRegion();
                region.length = readInt();
                region.filePointer = codedIS.getTotalBytesRead();
                if (addressAdapter != null) {
                    oldLimit = codedIS.pushLimit(region.length);
                    addressAdapter.readAddressIndex(region);
                    if (region.name != null) {
                        addressIndexes.add(region);
                        indexes.add(region);
                    }
                    codedIS.popLimit(oldLimit);
                }
                codedIS.seek(region.filePointer + region.length);
                break;
            case OsmandOdb.OsmAndStructure.TRANSPORTINDEX_FIELD_NUMBER:
                TransportIndex ind = new TransportIndex();
                ind.length = readInt();
                ind.filePointer = codedIS.getTotalBytesRead();
                if (transportAdapter != null) {
                    oldLimit = codedIS.pushLimit(ind.length);
                    transportAdapter.readTransportIndex(ind);
                    codedIS.popLimit(oldLimit);
                    transportIndexes.add(ind);
                    indexes.add(ind);
                }
                codedIS.seek(ind.filePointer + ind.length);
                break;
            case OsmandOdb.OsmAndStructure.ROUTINGINDEX_FIELD_NUMBER:
                RouteRegion routeReg = new RouteRegion();
                routeReg.length = readInt();
                routeReg.filePointer = codedIS.getTotalBytesRead();
                if (routeAdapter != null) {
                    oldLimit = codedIS.pushLimit(routeReg.length);
                    routeAdapter.readRouteIndex(routeReg);
                    codedIS.popLimit(oldLimit);
                    routingIndexes.add(routeReg);
                    indexes.add(routeReg);
                }
                codedIS.seek(routeReg.filePointer + routeReg.length);
                break;
            case OsmandOdb.OsmAndStructure.POIINDEX_FIELD_NUMBER:
                PoiRegion poiInd = new PoiRegion();
                poiInd.length = readInt();
                poiInd.filePointer = codedIS.getTotalBytesRead();
                if (poiAdapter != null) {
                    oldLimit = codedIS.pushLimit(poiInd.length);
                    poiAdapter.readPoiIndex(poiInd, false);
                    codedIS.popLimit(oldLimit);
                    poiIndexes.add(poiInd);
                    indexes.add(poiInd);
                }
                codedIS.seek(poiInd.filePointer + poiInd.length);
                break;
            case OsmandOdb.OsmAndStructure.VERSIONCONFIRM_FIELD_NUMBER:
                int cversion = codedIS.readUInt32();
                calculateCenterPointForRegions();
                initCorrectly = cversion == version;
                break;
            default:
                skipUnknownField(t);
                break;
        }
    }
}
Also used : RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) IOException(java.io.IOException) AddressRegion(net.osmand.binary.BinaryMapAddressReaderAdapter.AddressRegion) TransportIndex(net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex) PoiRegion(net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion)

Aggregations

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