Search in sources :

Example 1 with RouteRegion

use of net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion 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 RouteRegion

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

the class ManyToOneRoadCalculation method cut.

private void cut(BinaryMapIndexReader reader) throws IOException {
    RoutePlannerFrontEnd frontEnd = new RoutePlannerFrontEnd(false);
    RoutingConfiguration config = RoutingConfiguration.getDefault().build("car", 1000);
    RouteCalculationMode mode = RouteCalculationMode.BASE;
    RoutingContext ctx = frontEnd.buildRoutingContext(config, null, new BinaryMapIndexReader[] { reader }, mode);
    RouteRegion reg = reader.getRoutingIndexes().get(0);
    List<RouteSubregion> baseSubregions = reg.getBaseSubregions();
    List<RoutingSubregionTile> tiles = new ArrayList<RoutingContext.RoutingSubregionTile>();
    for (RouteSubregion s : baseSubregions) {
        List<RoutingSubregionTile> loadTiles = ctx.loadAllSubregionTiles(reader, s);
        tiles.addAll(loadTiles);
    }
    int zoom = 9;
    int ty = (int) MapUtils.getTileNumberY(zoom, reg.getTopLatitude());
    int by = (int) MapUtils.getTileNumberY(zoom, reg.getBottomLatitude()) + 1;
    int lx = (int) MapUtils.getTileNumberX(zoom, reg.getLeftLongitude());
    int rx = (int) MapUtils.getTileNumberX(zoom, reg.getRightLongitude()) + 1;
    for (int ky = ty + 1; ky < by; ky++) {
        for (int kx = lx + 1; kx < rx; kx++) {
            cutByQuadrant((kx - 1) << (31 - zoom), (ky - 1) << (31 - zoom), kx << (31 - zoom), ky << (31 - zoom), ctx, tiles);
        }
    }
}
Also used : RoutingContext(net.osmand.router.RoutingContext) RouteSubregion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion) RoutingConfiguration(net.osmand.router.RoutingConfiguration) RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd) RouteCalculationMode(net.osmand.router.RoutePlannerFrontEnd.RouteCalculationMode) ArrayList(java.util.ArrayList) TLongArrayList(gnu.trove.list.array.TLongArrayList) RoutingSubregionTile(net.osmand.router.RoutingContext.RoutingSubregionTile)

Example 3 with RouteRegion

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

the class CheckRoadConnectivity method clustering.

public void clustering(final ClusteringContext clusterCtx, BinaryMapIndexReader reader) throws IOException {
    RoutePlannerFrontEnd router = new RoutePlannerFrontEnd(false);
    Builder builder = RoutingConfiguration.getDefault();
    RoutingConfiguration config = builder.build("car", RoutingConfiguration.DEFAULT_MEMORY_LIMIT * 3);
    RoutingContext ctx = router.buildRoutingContext(config, null, new BinaryMapIndexReader[] { reader }, RouteCalculationMode.BASE);
    if (reader.getRoutingIndexes().size() != 1) {
        throw new UnsupportedOperationException();
    }
    RouteRegion reg = reader.getRoutingIndexes().get(0);
    List<RouteSubregion> baseSubregions = reg.getBaseSubregions();
    List<RoutingSubregionTile> tiles = new ArrayList<RoutingContext.RoutingSubregionTile>();
    for (RouteSubregion s : baseSubregions) {
        List<RoutingSubregionTile> loadTiles = ctx.loadAllSubregionTiles(reader, s);
        tiles.addAll(loadTiles);
    }
    List<Cluster> allClusters = new ArrayList<CheckRoadConnectivity.Cluster>();
    for (RoutingSubregionTile tile : tiles) {
        List<Cluster> clusters = processDataObjects(ctx, tile);
        allClusters.addAll(clusters);
    }
    combineClusters(allClusters, tiles);
}
Also used : RouteSubregion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion) Builder(net.osmand.router.RoutingConfiguration.Builder) ArrayList(java.util.ArrayList) RoutingContext(net.osmand.router.RoutingContext) RoutingConfiguration(net.osmand.router.RoutingConfiguration) RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd) RoutingSubregionTile(net.osmand.router.RoutingContext.RoutingSubregionTile)

Example 4 with RouteRegion

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

the class MapAddressLayer method justifyResults.

private double justifyResults(List<BinaryMapIndexReader> list, GeocodingUtilities su, List<GeocodingResult> complete, List<GeocodingResult> res) throws IOException {
    double minBuildingDistance = 0;
    for (GeocodingResult r : res) {
        BinaryMapIndexReader reader = null;
        for (BinaryMapIndexReader b : list) {
            for (RouteRegion rb : b.getRoutingIndexes()) {
                if (r.regionFP == rb.getFilePointer() && r.regionLen == rb.getLength()) {
                    reader = b;
                    break;
                }
            }
            if (reader != null) {
                break;
            }
        }
        if (reader != null) {
            List<GeocodingResult> justified = su.justifyReverseGeocodingSearch(r, reader, minBuildingDistance, null);
            if (!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);
        }
    }
    return minBuildingDistance;
}
Also used : GeocodingResult(net.osmand.binary.GeocodingUtilities.GeocodingResult) RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader)

Example 5 with RouteRegion

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

the class ObfDiffGenerator method compareRouteData.

private void compareRouteData(ObfFileInMemory fStart, ObfFileInMemory fEnd, boolean print, Set<EntityId> modifiedObjIds) {
    RouteRegion ri = fEnd.getRouteIndex();
    int deleteId = ri.searchRouteEncodingRule(OSMAND_CHANGE_TAG, OSMAND_CHANGE_VALUE);
    if (deleteId == -1) {
        deleteId = ri.routeEncodingRules.size();
        if (deleteId == 0) {
            deleteId = 1;
        }
        ri.initRouteEncodingRule(deleteId, OSMAND_CHANGE_TAG, OSMAND_CHANGE_VALUE);
    }
    TLongObjectHashMap<RouteDataObject> startData = fStart.getRoutingData();
    TLongObjectHashMap<RouteDataObject> endData = fEnd.getRoutingData();
    if (endData == null) {
        return;
    }
    for (Long idx : startData.keys()) {
        RouteDataObject objE = endData.get(idx);
        RouteDataObject objS = startData.get(idx);
        if (print) {
            if (objE == null) {
                System.out.println("Route " + idx + " is missing in (2): " + objS);
            } else {
                if (!objE.compareRoute(objS)) {
                    System.out.println("Route " + idx + " is not equal: " + objS + " != " + objE);
                }
                endData.remove(idx);
            }
        } else {
            if (objE == null) {
                EntityId wayId = new EntityId(EntityType.WAY, idx >> (BinaryInspector.SHIFT_ID));
                if (modifiedObjIds == null || modifiedObjIds.contains(wayId)) {
                    RouteDataObject rdo = generateDeletedRouteObject(ri, deleteId, objS);
                    endData.put(idx, rdo);
                }
            } else if (objE.compareRoute(objS)) {
                endData.remove(idx);
            }
        }
    }
    if (print) {
        for (RouteDataObject e : endData.valueCollection()) {
            System.out.println("Route " + e.getId() + " is missing in (1): " + e);
        }
    }
}
Also used : EntityId(net.osmand.osm.edit.Entity.EntityId) RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) RouteDataObject(net.osmand.binary.RouteDataObject)

Aggregations

RouteRegion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion)20 ArrayList (java.util.ArrayList)9 MapIndex (net.osmand.binary.BinaryMapIndexReader.MapIndex)7 PoiRegion (net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion)7 RouteSubregion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion)7 TransportIndex (net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex)7 IOException (java.io.IOException)6 AddressRegion (net.osmand.binary.BinaryMapAddressReaderAdapter.AddressRegion)6 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)5 MapRoot (net.osmand.binary.BinaryMapIndexReader.MapRoot)5 TLongArrayList (gnu.trove.list.array.TLongArrayList)4 RoutePlannerFrontEnd (net.osmand.router.RoutePlannerFrontEnd)4 RoutingConfiguration (net.osmand.router.RoutingConfiguration)4 RoutingContext (net.osmand.router.RoutingContext)4 RoutingSubregionTile (net.osmand.router.RoutingContext.RoutingSubregionTile)4 FileOutputStream (java.io.FileOutputStream)3 RandomAccessFile (java.io.RandomAccessFile)3 List (java.util.List)3 CitiesBlock (net.osmand.binary.BinaryMapAddressReaderAdapter.CitiesBlock)3 GeocodingResult (net.osmand.binary.GeocodingUtilities.GeocodingResult)3