Search in sources :

Example 6 with RouteSubregion

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

the class ManyToOneRoadCalculation method manyToManyCalculation.

private void manyToManyCalculation(BinaryMapIndexReader reader, double top, double bottom) 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 st = MapUtils.get31TileNumberY(top);
    int sb = MapUtils.get31TileNumberY(bottom);
    List<ManyToManySegment> topIntersects = new ArrayList<ManyToManySegment>();
    List<ManyToManySegment> bottomIntersects = new ArrayList<ManyToManySegment>();
    TLongObjectHashMap<ManyToManySegment> allSegments = initSegments(st, sb, ctx, tiles, topIntersects, bottomIntersects);
    filterDisconnected(ctx, allSegments, topIntersects);
    filterDisconnected(ctx, allSegments, topIntersects);
    System.out.println("TOP " + topIntersects.size());
    System.out.println("BOTTOM " + bottomIntersects.size());
    calculateManyToMany(ctx, allSegments, topIntersects, bottomIntersects, st, sb);
}
Also used : RouteSubregion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion) ArrayList(java.util.ArrayList) TLongArrayList(gnu.trove.list.array.TLongArrayList) RoutingContext(net.osmand.router.RoutingContext) RoutingConfiguration(net.osmand.router.RoutingConfiguration) RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd) RouteCalculationMode(net.osmand.router.RoutePlannerFrontEnd.RouteCalculationMode) RoutingSubregionTile(net.osmand.router.RoutingContext.RoutingSubregionTile)

Example 7 with RouteSubregion

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

the class CheckRoadConnectivity method findAllBaseRoadIntersections.

private void findAllBaseRoadIntersections(BinaryMapIndexReader reader, TLongObjectHashMap<List<RouteDataObject>> all, TLongObjectHashMap<List<RouteDataObject>> onlyRoads, TLongHashSet registeredRoadIds) 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);
    }
    for (RoutingSubregionTile tile : tiles) {
        ArrayList<RouteDataObject> dataObjects = new ArrayList<RouteDataObject>();
        ctx.loadSubregionTile(tile, false, dataObjects, null);
        for (RouteDataObject o : dataObjects) {
            registeredRoadIds.add(o.getId());
            int len = o.getPointsLength() - 1;
            double dist = MapUtils.squareRootDist31(o.getPoint31XTile(0), o.getPoint31YTile(0), o.getPoint31XTile(len), o.getPoint31YTile(len));
            boolean shortFerry = "ferry".equals(o.getRoute()) && dist < 1000;
            if (shortFerry) {
                continue;
            }
            boolean link = o.getHighway() != null && (o.getHighway().endsWith("link"));
            long b = calcPointId(o, 0);
            long e = calcPointId(o, len);
            if (!link) {
                addPoint(onlyRoads, o, b);
                addPoint(onlyRoads, o, e);
            }
            for (int i = 0; i < o.getPointsLength(); i++) {
                addPoint(all, o, calcPointId(o, i));
            }
        }
    }
}
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) RouteDataObject(net.osmand.binary.RouteDataObject) RoutingSubregionTile(net.osmand.router.RoutingContext.RoutingSubregionTile)

Example 8 with RouteSubregion

use of net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion in project Osmand by osmandapp.

the class RoutingContext method loadAllSubregionTiles.

public List<RoutingSubregionTile> loadAllSubregionTiles(BinaryMapIndexReader reader, RouteSubregion reg) throws IOException {
    List<RoutingSubregionTile> list = new ArrayList<RoutingContext.RoutingSubregionTile>();
    SearchRequest<RouteDataObject> request = BinaryMapIndexReader.buildSearchRouteRequest(0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, null);
    List<RouteSubregion> subregs = reader.searchRouteIndexTree(request, Collections.singletonList(reg));
    for (RouteSubregion s : subregs) {
        list.add(new RoutingSubregionTile(s));
    }
    return list;
}
Also used : RouteSubregion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion) ArrayList(java.util.ArrayList) RouteDataObject(net.osmand.binary.RouteDataObject)

Example 9 with RouteSubregion

use of net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion in project Osmand by osmandapp.

the class MapRenderRepositories method readRouteDataAsMapObjects.

private void readRouteDataAsMapObjects(SearchRequest<BinaryMapDataObject> sr, BinaryMapIndexReader c, final ArrayList<BinaryMapDataObject> tempResult, final TLongSet ids) {
    final boolean basemap = c.isBasemap();
    try {
        for (RouteRegion reg : c.getRoutingIndexes()) {
            List<RouteSubregion> parent = sr.getZoom() < 15 ? reg.getBaseSubregions() : reg.getSubregions();
            List<RouteSubregion> searchRouteIndexTree = c.searchRouteIndexTree(sr, parent);
            final MapIndex nmi = new MapIndex();
            c.loadRouteIndexData(searchRouteIndexTree, new ResultMatcher<RouteDataObject>() {

                @Override
                public boolean publish(RouteDataObject r) {
                    if (basemap) {
                        renderedState |= 1;
                    } else {
                        renderedState |= 2;
                    }
                    if (checkForDuplicateObjectIds && !basemap) {
                        if (ids.contains(r.getId()) && r.getId() > 0) {
                            // do not add object twice
                            return false;
                        }
                        ids.add(r.getId());
                    }
                    int[] coordinantes = new int[r.getPointsLength() * 2];
                    int[] roTypes = r.getTypes();
                    for (int k = 0; k < roTypes.length; k++) {
                        int type = roTypes[k];
                        registerMissingType(nmi, r, type);
                    }
                    for (int k = 0; k < coordinantes.length / 2; k++) {
                        coordinantes[2 * k] = r.getPoint31XTile(k);
                        coordinantes[2 * k + 1] = r.getPoint31YTile(k);
                    }
                    BinaryMapDataObject mo = new BinaryMapDataObject(r.getId(), coordinantes, new int[0][], RenderingRulesStorage.LINE_RULES, true, roTypes, null);
                    TIntObjectHashMap<String> names = r.getNames();
                    if (names != null) {
                        TIntObjectIterator<String> it = names.iterator();
                        while (it.hasNext()) {
                            it.advance();
                            registerMissingType(nmi, r, it.key());
                            mo.putObjectName(it.key(), it.value());
                        }
                    }
                    mo.setMapIndex(nmi);
                    tempResult.add(mo);
                    return false;
                }

                private void registerMissingType(final MapIndex nmi, RouteDataObject r, int type) {
                    if (!nmi.isRegisteredRule(type)) {
                        RouteTypeRule rr = r.region.quickGetEncodingRule(type);
                        String tag = rr.getTag();
                        int additional = ("highway".equals(tag) || "route".equals(tag) || "railway".equals(tag) || "aeroway".equals(tag) || "aerialway".equals(tag)) ? 0 : 1;
                        nmi.initMapEncodingRule(additional, type, rr.getTag(), rr.getValue());
                    }
                }

                @Override
                public boolean isCancelled() {
                    return !interrupted;
                }
            });
        }
    } catch (IOException e) {
        // $NON-NLS-1$
        log.debug("Search failed " + c.getRegionNames(), e);
    }
}
Also used : RouteSubregion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion) TIntObjectIterator(gnu.trove.iterator.TIntObjectIterator) RouteTypeRule(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule) IOException(java.io.IOException) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) RouteDataObject(net.osmand.binary.RouteDataObject) MapIndex(net.osmand.binary.BinaryMapIndexReader.MapIndex)

Aggregations

RouteSubregion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion)9 RouteRegion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion)7 ArrayList (java.util.ArrayList)6 RouteDataObject (net.osmand.binary.RouteDataObject)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 MapIndex (net.osmand.binary.BinaryMapIndexReader.MapIndex)3 TLongArrayList (gnu.trove.list.array.TLongArrayList)2 IOException (java.io.IOException)2 AddressRegion (net.osmand.binary.BinaryMapAddressReaderAdapter.AddressRegion)2 CitiesBlock (net.osmand.binary.BinaryMapAddressReaderAdapter.CitiesBlock)2 MapRoot (net.osmand.binary.BinaryMapIndexReader.MapRoot)2 PoiRegion (net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion)2 TransportIndex (net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex)2 AddressPart (net.osmand.binary.OsmandIndex.AddressPart)2 CityBlock (net.osmand.binary.OsmandIndex.CityBlock)2 MapLevel (net.osmand.binary.OsmandIndex.MapLevel)2 MapPart (net.osmand.binary.OsmandIndex.MapPart)2