use of net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion in project Osmand by osmandapp.
the class RoutePlannerFrontEnd method runNativeRouting.
private List<RouteSegmentResult> runNativeRouting(final RoutingContext ctx, RouteSegment recalculationEnd) throws IOException {
refreshProgressDistance(ctx);
RouteRegion[] regions = ctx.reverseMap.keySet().toArray(new BinaryMapRouteReaderAdapter.RouteRegion[ctx.reverseMap.size()]);
ctx.checkOldRoutingFiles(ctx.startX, ctx.startY);
ctx.checkOldRoutingFiles(ctx.targetX, ctx.targetY);
long time = System.currentTimeMillis();
RouteSegmentResult[] res = ctx.nativeLib.runNativeRouting(ctx.startX, ctx.startY, ctx.targetX, ctx.targetY, ctx.config, regions, ctx.calculationProgress, ctx.precalculatedRouteDirection, ctx.calculationMode == RouteCalculationMode.BASE);
log.info("Native routing took " + (System.currentTimeMillis() - time) / 1000f + " seconds");
ArrayList<RouteSegmentResult> result = new ArrayList<RouteSegmentResult>(Arrays.asList(res));
if (recalculationEnd != null) {
log.info("Native routing use precalculated route");
RouteSegment current = recalculationEnd;
while (current.getParentRoute() != null) {
RouteSegment pr = current.getParentRoute();
result.add(new RouteSegmentResult(pr.getRoad(), current.getParentSegmentEnd(), pr.getSegmentStart()));
current = pr;
}
}
ctx.routingTime = ctx.calculationProgress.routingCalculatedTime;
ctx.visitedSegments = ctx.calculationProgress.visitedSegments;
ctx.loadedTiles = ctx.calculationProgress.loadedTiles;
return new RouteResultPreparation().prepareResult(ctx, result);
}
use of net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion in project Osmand by osmandapp.
the class RoutingContext method checkOldRoutingFiles.
public void checkOldRoutingFiles(BinaryMapIndexReader key) {
if (calculationMode == RouteCalculationMode.BASE && key.getDateCreated() < 1390172400000l) {
// new SimpleDateFormat("dd-MM-yyyy").parse("20-01-2014").getTime()
System.err.println("Old routing file : " + key.getDateCreated() + " " + new Date(key.getDateCreated()));
String map = "";
for (RouteRegion r : key.getRoutingIndexes()) {
map = r.getName();
}
throw new RuntimeException("Update map '" + map + "' !");
}
}
use of net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion in project Osmand by osmandapp.
the class CurrentPositionHelper method justifyResult.
private void justifyResult(List<GeocodingResult> res, final ResultMatcher<GeocodingResult> result) {
List<GeocodingResult> complete = new ArrayList<>();
double minBuildingDistance = 0;
if (res != null) {
for (GeocodingResult r : res) {
BinaryMapIndexReader foundRepo = null;
List<BinaryMapIndexReader> rts = usedReaders;
for (BinaryMapIndexReader reader : rts) {
for (RouteRegion rb : reader.getRoutingIndexes()) {
if (r.regionFP == rb.getFilePointer() && r.regionLen == rb.getLength()) {
foundRepo = reader;
break;
}
}
}
if (result.isCancelled()) {
break;
} else if (foundRepo != null) {
List<GeocodingResult> justified = null;
try {
justified = new GeocodingUtilities().justifyReverseGeocodingSearch(r, foundRepo, minBuildingDistance, result);
} catch (IOException e) {
log.error("Exception happened during reverse geocoding", e);
e.printStackTrace();
}
if (justified != null && !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);
}
}
}
if (result.isCancelled()) {
app.runInUIThread(new Runnable() {
public void run() {
result.publish(null);
}
});
return;
}
Collections.sort(complete, GeocodingUtilities.DISTANCE_COMPARATOR);
// for(GeocodingResult rt : complete) {
// System.out.println(rt.toString());
// }
final GeocodingResult rts = complete.size() > 0 ? complete.get(0) : new GeocodingResult();
app.runInUIThread(new Runnable() {
public void run() {
result.publish(rts);
}
});
}
use of net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion 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.RouteRegion 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));
}
}
}
}
Aggregations