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