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);
}
}
}
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;
}
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);
}
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;
}
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);
}
Aggregations