use of net.osmand.router.RoutePlannerFrontEnd in project OsmAnd-tools by osmandapp.
the class MapRouterLayer method selfRoute.
public List<Way> selfRoute(LatLon start, LatLon end, List<LatLon> intermediates, List<RouteSegmentResult> previousRoute, RouteCalculationMode rm) {
List<Way> res = new ArrayList<Way>();
long time = System.currentTimeMillis();
List<File> files = new ArrayList<File>();
for (File f : Algorithms.getSortedFilesVersions(new File(DataExtractionSettings.getSettings().getBinaryFilesDir()))) {
if (f.getName().endsWith(".obf")) {
files.add(f);
}
}
final boolean animateRoutingCalculation = DataExtractionSettings.getSettings().isAnimateRouting();
if (animateRoutingCalculation) {
nextTurn.setVisible(true);
playPauseButton.setVisible(true);
stopButton.setVisible(true);
pause = true;
playPauseButton.setText("Play");
}
stop = false;
if (files.isEmpty()) {
JOptionPane.showMessageDialog(OsmExtractionUI.MAIN_APP.getFrame(), "Please specify obf file in settings", "Obf file not found", JOptionPane.ERROR_MESSAGE);
return null;
}
System.out.println("Self made route from " + start + " to " + end);
if (start != null && end != null) {
try {
BinaryMapIndexReader[] rs = new BinaryMapIndexReader[files.size()];
int it = 0;
for (File f : files) {
// $NON-NLS-1$ //$NON-NLS-2$
RandomAccessFile raf = new RandomAccessFile(f, "r");
rs[it++] = new BinaryMapIndexReader(raf, f);
}
String m = DataExtractionSettings.getSettings().getRouteMode();
String[] props = m.split("\\,");
RoutePlannerFrontEnd router = new RoutePlannerFrontEnd(USE_OLD_ROUTING);
Map<String, String> paramsR = new LinkedHashMap<String, String>();
for (String p : props) {
if (p.contains("=")) {
paramsR.put(p.split("=")[0], p.split("=")[1]);
} else {
paramsR.put(p, "true");
}
}
RoutingConfiguration config = DataExtractionSettings.getSettings().getRoutingConfig().build(props[0], /*RoutingConfiguration.DEFAULT_MEMORY_LIMIT*/
1000, paramsR);
PrecalculatedRouteDirection precalculatedRouteDirection = null;
// Test gpx precalculation
// LatLon[] lts = parseGPXDocument("/home/victor/projects/osmand/temp/esya.gpx");
// start = lts[0];
// end = lts[lts.length - 1];
// System.out.println("Start " + start + " end " + end);
// precalculatedRouteDirection = PrecalculatedRouteDirection.build(lts, config.router.getMaxDefaultSpeed());
// precalculatedRouteDirection.setFollowNext(true);
// config.planRoadDirection = 1;
// Test initial direction
// config.initialDirection = 90d / 180d * Math.PI; // EAST
// config.initialDirection = 180d / 180d * Math.PI; // SOUTH
// config.initialDirection = -90d / 180d * Math.PI; // WEST
// config.initialDirection = 0 / 180d * Math.PI; // NORTH
// config.NUMBER_OF_DESIRABLE_TILES_IN_MEMORY = 300;
// config.ZOOM_TO_LOAD_TILES = 14;
final RoutingContext ctx = router.buildRoutingContext(config, DataExtractionSettings.getSettings().useNativeRouting() ? NativeSwingRendering.getDefaultFromSettings() : null, rs, rm);
ctx.leftSideNavigation = false;
ctx.previouslyCalculatedRoute = previousRoute;
log.info("Use " + config.routerName + "mode for routing");
final DataTileManager<Entity> points = new DataTileManager<Entity>(11);
map.setPoints(points);
ctx.setVisitor(createSegmentVisitor(animateRoutingCalculation, points));
// Choose native or not native
long nt = System.nanoTime();
startProgressThread(ctx);
try {
List<RouteSegmentResult> searchRoute = router.searchRoute(ctx, start, end, intermediates, precalculatedRouteDirection);
throwExceptionIfRouteNotFound(ctx, searchRoute);
System.out.println("External native time " + (System.nanoTime() - nt) / 1.0e9f);
if (animateRoutingCalculation) {
playPauseButton.setVisible(false);
nextTurn.setText("FINISH");
waitNextPress();
nextTurn.setText(">>");
}
this.previousRoute = searchRoute;
calculateResult(res, searchRoute);
} finally {
ctx.calculationProgress.isCancelled = true;
}
} catch (Exception e) {
ExceptionHandler.handle(e);
} finally {
playPauseButton.setVisible(false);
nextTurn.setVisible(false);
stopButton.setVisible(false);
if (map.getPoints() != null) {
map.getPoints().clear();
}
}
System.out.println("Finding self routes " + res.size() + " " + (System.currentTimeMillis() - time) + " ms");
}
return res;
}
use of net.osmand.router.RoutePlannerFrontEnd 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.RoutePlannerFrontEnd 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.RoutePlannerFrontEnd in project OsmAnd-tools by osmandapp.
the class MapAddressLayer method whereAmI.
private List<Entity> whereAmI(double lat, double lon, final DataTileManager<Entity> points) throws IOException {
List<Entity> results = new ArrayList<Entity>();
int x = MapUtils.get31TileNumberX(lon);
int y = MapUtils.get31TileNumberY(lat);
List<BinaryMapIndexReader> list = new ArrayList<BinaryMapIndexReader>();
for (File f : new File(DataExtractionSettings.getSettings().getBinaryFilesDir()).listFiles()) {
if (f.getName().endsWith(".obf")) {
// $NON-NLS-1$ //$NON-NLS-2$
RandomAccessFile raf = new RandomAccessFile(f, "r");
BinaryMapIndexReader rd = new BinaryMapIndexReader(raf, f);
if (rd.containsAddressData() && rd.containsRouteData(x, y, x, y, 15)) {
list.add(rd);
} else {
rd.close();
raf.close();
}
}
}
RoutingConfiguration cfg = DataExtractionSettings.getSettings().getRoutingConfig().build("geocoding", 100, new HashMap<String, String>());
RoutingContext ctx = new RoutePlannerFrontEnd(false).buildRoutingContext(cfg, null, list.toArray(new BinaryMapIndexReader[list.size()]));
GeocodingUtilities su = new GeocodingUtilities();
double minBuildingDistance = 0;
List<GeocodingResult> complete = new ArrayList<GeocodingUtilities.GeocodingResult>();
List<GeocodingResult> res = su.reverseGeocodingSearch(ctx, lat, lon, false);
minBuildingDistance = justifyResults(list, su, complete, res);
// complete.addAll(res);
Collections.sort(complete, GeocodingUtilities.DISTANCE_COMPARATOR);
long lid = -1;
for (GeocodingResult r : complete) {
if (r.building != null && r.getDistance() > minBuildingDistance * GeocodingUtilities.THRESHOLD_MULTIPLIER_SKIP_BUILDINGS_AFTER) {
continue;
}
Node n = new Node(r.getLocation().getLatitude(), r.getLocation().getLongitude(), lid--);
n.putTag(OSMTagKey.NAME.getValue(), r.toString());
results.add(n);
}
for (BinaryMapIndexReader l : list) {
l.close();
}
return results;
}
use of net.osmand.router.RoutePlannerFrontEnd in project Osmand by osmandapp.
the class RouteProvider method findVectorMapsRoute.
protected RouteCalculationResult findVectorMapsRoute(final RouteCalculationParams params, boolean calcGPXRoute) throws IOException {
BinaryMapIndexReader[] files = params.ctx.getResourceManager().getRoutingMapFiles();
RoutePlannerFrontEnd router = new RoutePlannerFrontEnd(false);
OsmandSettings settings = params.ctx.getSettings();
router.setUseFastRecalculation(settings.USE_FAST_RECALCULATION.get());
RoutingConfiguration.Builder config = params.ctx.getDefaultRoutingConfig();
GeneralRouter generalRouter = SettingsNavigationActivity.getRouter(config, params.mode);
if (generalRouter == null) {
return applicationModeNotSupported(params);
}
RoutingConfiguration cf = initOsmAndRoutingConfig(config, params, settings, generalRouter);
if (cf == null) {
return applicationModeNotSupported(params);
}
PrecalculatedRouteDirection precalculated = null;
if (calcGPXRoute) {
ArrayList<Location> sublist = findStartAndEndLocationsFromRoute(params.gpxRoute.points, params.start, params.end, null, null);
LatLon[] latLon = new LatLon[sublist.size()];
for (int k = 0; k < latLon.length; k++) {
latLon[k] = new LatLon(sublist.get(k).getLatitude(), sublist.get(k).getLongitude());
}
precalculated = PrecalculatedRouteDirection.build(latLon, generalRouter.getMaxDefaultSpeed());
precalculated.setFollowNext(true);
// cf.planRoadDirection = 1;
}
// BUILD context
NativeOsmandLibrary lib = settings.SAFE_MODE.get() ? null : NativeOsmandLibrary.getLoadedLibrary();
// check loaded files
int leftX = MapUtils.get31TileNumberX(params.start.getLongitude());
int rightX = leftX;
int bottomY = MapUtils.get31TileNumberY(params.start.getLatitude());
int topY = bottomY;
if (params.intermediates != null) {
for (LatLon l : params.intermediates) {
leftX = Math.min(MapUtils.get31TileNumberX(l.getLongitude()), leftX);
rightX = Math.max(MapUtils.get31TileNumberX(l.getLongitude()), rightX);
bottomY = Math.max(MapUtils.get31TileNumberY(l.getLatitude()), bottomY);
topY = Math.min(MapUtils.get31TileNumberY(l.getLatitude()), topY);
}
}
LatLon l = params.end;
leftX = Math.min(MapUtils.get31TileNumberX(l.getLongitude()), leftX);
rightX = Math.max(MapUtils.get31TileNumberX(l.getLongitude()), rightX);
bottomY = Math.max(MapUtils.get31TileNumberY(l.getLatitude()), bottomY);
topY = Math.min(MapUtils.get31TileNumberY(l.getLatitude()), topY);
params.ctx.getResourceManager().getRenderer().checkInitialized(15, lib, leftX, rightX, bottomY, topY);
RoutingContext ctx = router.buildRoutingContext(cf, lib, files, RouteCalculationMode.NORMAL);
RoutingContext complexCtx = null;
boolean complex = params.mode.isDerivedRoutingFrom(ApplicationMode.CAR) && !settings.DISABLE_COMPLEX_ROUTING.get() && precalculated == null;
ctx.leftSideNavigation = params.leftSide;
ctx.calculationProgress = params.calculationProgress;
if (params.previousToRecalculate != null && params.onlyStartPointChanged) {
int currentRoute = params.previousToRecalculate.getCurrentRoute();
List<RouteSegmentResult> originalRoute = params.previousToRecalculate.getOriginalRoute();
if (originalRoute != null && currentRoute < originalRoute.size()) {
ctx.previouslyCalculatedRoute = originalRoute.subList(currentRoute, originalRoute.size());
}
}
if (complex && router.getRecalculationEnd(ctx) != null) {
complex = false;
}
if (complex) {
complexCtx = router.buildRoutingContext(cf, lib, files, RouteCalculationMode.COMPLEX);
complexCtx.calculationProgress = params.calculationProgress;
complexCtx.leftSideNavigation = params.leftSide;
complexCtx.previouslyCalculatedRoute = ctx.previouslyCalculatedRoute;
}
LatLon st = new LatLon(params.start.getLatitude(), params.start.getLongitude());
LatLon en = new LatLon(params.end.getLatitude(), params.end.getLongitude());
List<LatLon> inters = new ArrayList<LatLon>();
if (params.intermediates != null) {
inters = new ArrayList<LatLon>(params.intermediates);
}
return calcOfflineRouteImpl(params, router, ctx, complexCtx, st, en, inters, precalculated);
}
Aggregations