Search in sources :

Example 1 with RoutingSubregionTile

use of net.osmand.router.RoutingContext.RoutingSubregionTile 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 2 with RoutingSubregionTile

use of net.osmand.router.RoutingContext.RoutingSubregionTile in project OsmAnd-tools by osmandapp.

the class ManyToOneRoadCalculation method initSegments.

private TLongObjectHashMap<ManyToManySegment> initSegments(int stop, int sbottom, RoutingContext ctx, List<RoutingSubregionTile> tiles, List<ManyToManySegment> topIntersects, List<ManyToManySegment> bottomIntersects) {
    TLongObjectHashMap<ManyToManySegment> res = new TLongObjectHashMap<ManyToManySegment>();
    List<RouteDataObject> startObjects = new ArrayList<RouteDataObject>();
    for (RoutingSubregionTile st : tiles) {
        if (st.subregion.top <= sbottom && st.subregion.bottom >= stop) {
            ctx.loadSubregionTile(st, false, startObjects, null);
        }
    }
    System.out.println("Roads in layer " + startObjects.size());
    for (RouteDataObject ro : startObjects) {
        boolean topCheck = false, bottomCheck = false;
        for (int i = 0; i < ro.getPointsLength(); i++) {
            ManyToManySegment sg = new ManyToManySegment();
            sg.road = ro;
            sg.segmentIndex = i;
            int px = ro.getPoint31XTile(i);
            int py = ro.getPoint31YTile(i);
            if (i > 0) {
                int prevX = ro.getPoint31XTile(i - 1);
                int prevY = ro.getPoint31YTile(i - 1);
                if (checkIntersection(prevX, prevY, px, py, 0, Integer.MAX_VALUE, stop, stop) && !topCheck) {
                    topIntersects.add(sg);
                    topCheck = true;
                }
                if (checkIntersection(prevX, prevY, px, py, 0, Integer.MAX_VALUE, sbottom, sbottom) && !bottomCheck) {
                    bottomIntersects.add(sg);
                    bottomCheck = true;
                }
            }
            long key = calcLong(px, py);
            ManyToManySegment sm = res.get(key);
            if (sm != null) {
                while (sm.next != null) {
                    sm = sm.next;
                }
                sm.next = sg;
            } else {
                res.put(key, sg);
            }
        }
    }
    return res;
}
Also used : ArrayList(java.util.ArrayList) TLongArrayList(gnu.trove.list.array.TLongArrayList) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) RouteDataObject(net.osmand.binary.RouteDataObject) RoutingSubregionTile(net.osmand.router.RoutingContext.RoutingSubregionTile)

Example 3 with RoutingSubregionTile

use of net.osmand.router.RoutingContext.RoutingSubregionTile 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 RoutingSubregionTile

use of net.osmand.router.RoutingContext.RoutingSubregionTile in project OsmAnd-tools by osmandapp.

the class ManyToOneRoadCalculation method initSegments.

private TLongObjectHashMap<ManyToManySegment> initSegments(int stop, int sbottom, RoutingContext ctx, List<RoutingSubregionTile> tiles, List<ManyToManySegment> topIntersects, List<ManyToManySegment> bottomIntersects) {
    TLongObjectHashMap<ManyToManySegment> res = new TLongObjectHashMap<ManyToManySegment>();
    List<RouteDataObject> startObjects = new ArrayList<RouteDataObject>();
    for (RoutingSubregionTile st : tiles) {
        if (st.subregion.top <= sbottom && st.subregion.bottom >= stop) {
            ctx.loadSubregionTile(st, false, startObjects, null);
        }
    }
    System.out.println("Roads in layer " + startObjects.size());
    for (RouteDataObject ro : startObjects) {
        boolean topCheck = false, bottomCheck = false;
        for (int i = 0; i < ro.getPointsLength(); i++) {
            ManyToManySegment sg = new ManyToManySegment();
            sg.road = ro;
            sg.segmentIndex = i;
            int px = ro.getPoint31XTile(i);
            int py = ro.getPoint31YTile(i);
            if (i > 0) {
                int prevX = ro.getPoint31XTile(i - 1);
                int prevY = ro.getPoint31YTile(i - 1);
                if (checkIntersection(prevX, prevY, px, py, 0, Integer.MAX_VALUE, stop, stop) && !topCheck) {
                    topIntersects.add(sg);
                    topCheck = true;
                }
                if (checkIntersection(prevX, prevY, px, py, 0, Integer.MAX_VALUE, sbottom, sbottom) && !bottomCheck) {
                    bottomIntersects.add(sg);
                    bottomCheck = true;
                }
            }
            long key = calcLong(px, py);
            ManyToManySegment sm = res.get(key);
            if (sm != null) {
                while (sm.next != null) {
                    sm = sm.next;
                }
                sm.next = sg;
            } else {
                res.put(key, sg);
            }
        }
    }
    return res;
}
Also used : ArrayList(java.util.ArrayList) TLongArrayList(gnu.trove.list.array.TLongArrayList) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) RouteDataObject(net.osmand.binary.RouteDataObject) RoutingSubregionTile(net.osmand.router.RoutingContext.RoutingSubregionTile)

Example 5 with RoutingSubregionTile

use of net.osmand.router.RoutingContext.RoutingSubregionTile 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();
    RoutingMemoryLimits memoryLimit = new RoutingMemoryLimits(1000, RoutingConfiguration.DEFAULT_NATIVE_MEMORY_LIMIT * 10);
    RoutingConfiguration config = RoutingConfiguration.getDefault().build("car", memoryLimit);
    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) RoutingMemoryLimits(net.osmand.router.RoutingConfiguration.RoutingMemoryLimits) 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)

Aggregations

ArrayList (java.util.ArrayList)12 RoutingSubregionTile (net.osmand.router.RoutingContext.RoutingSubregionTile)12 TLongArrayList (gnu.trove.list.array.TLongArrayList)8 RouteRegion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion)8 RouteSubregion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion)8 RoutePlannerFrontEnd (net.osmand.router.RoutePlannerFrontEnd)8 RoutingConfiguration (net.osmand.router.RoutingConfiguration)8 RoutingContext (net.osmand.router.RoutingContext)8 RouteDataObject (net.osmand.binary.RouteDataObject)6 RouteCalculationMode (net.osmand.router.RoutePlannerFrontEnd.RouteCalculationMode)4 Builder (net.osmand.router.RoutingConfiguration.Builder)4 RoutingMemoryLimits (net.osmand.router.RoutingConfiguration.RoutingMemoryLimits)4 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 RouteSegment (net.osmand.router.BinaryRoutePlanner.RouteSegment)2