use of net.osmand.router.GeneralRouter 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);
}
use of net.osmand.router.GeneralRouter in project Osmand by osmandapp.
the class SettingsNavigationActivity method prepareRoutingPrefs.
private void prepareRoutingPrefs(PreferenceScreen screen) {
PreferenceCategory cat = (PreferenceCategory) screen.findPreference("routing_preferences");
cat.removeAll();
CheckBoxPreference fastRoute = createCheckBoxPreference(settings.FAST_ROUTE_MODE, R.string.fast_route_mode, R.string.fast_route_mode_descr);
if (settings.ROUTER_SERVICE.get() != RouteService.OSMAND) {
cat.addPreference(fastRoute);
} else {
ApplicationMode am = settings.getApplicationMode();
GeneralRouter router = getRouter(getMyApplication().getDefaultRoutingConfig(), am);
clearParameters();
if (router != null) {
Map<String, RoutingParameter> parameters = router.getParameters();
if (parameters.containsKey("short_way")) {
cat.addPreference(fastRoute);
}
List<RoutingParameter> others = new ArrayList<GeneralRouter.RoutingParameter>();
for (Map.Entry<String, RoutingParameter> e : parameters.entrySet()) {
String param = e.getKey();
RoutingParameter routingParameter = e.getValue();
if (param.startsWith("avoid_")) {
avoidParameters.add(routingParameter);
} else if (param.startsWith("prefer_")) {
preferParameters.add(routingParameter);
} else if ("relief_smoothness_factor".equals(routingParameter.getGroup())) {
reliefFactorParameters.add(routingParameter);
} else if (!param.equals("short_way") && !"driving_style".equals(routingParameter.getGroup())) {
others.add(routingParameter);
}
}
if (avoidParameters.size() > 0) {
avoidRouting = new Preference(this);
avoidRouting.setTitle(R.string.avoid_in_routing_title);
avoidRouting.setSummary(R.string.avoid_in_routing_descr);
avoidRouting.setOnPreferenceClickListener(this);
cat.addPreference(avoidRouting);
}
if (preferParameters.size() > 0) {
preferRouting = new Preference(this);
preferRouting.setTitle(R.string.prefer_in_routing_title);
preferRouting.setSummary(R.string.prefer_in_routing_descr);
preferRouting.setOnPreferenceClickListener(this);
cat.addPreference(preferRouting);
}
if (reliefFactorParameters.size() > 0) {
reliefFactorRouting = new Preference(this);
reliefFactorRouting.setTitle(SettingsBaseActivity.getRoutingStringPropertyName(this, reliefFactorParameters.get(0).getGroup(), Algorithms.capitalizeFirstLetterAndLowercase(reliefFactorParameters.get(0).getGroup().replace('_', ' '))));
reliefFactorRouting.setSummary(R.string.relief_smoothness_factor_descr);
reliefFactorRouting.setOnPreferenceClickListener(this);
cat.addPreference(reliefFactorRouting);
}
for (RoutingParameter p : others) {
Preference basePref;
if (p.getType() == RoutingParameterType.BOOLEAN) {
basePref = createCheckBoxPreference(settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean()));
} else {
Object[] vls = p.getPossibleValues();
String[] svlss = new String[vls.length];
int i = 0;
for (Object o : vls) {
svlss[i++] = o.toString();
}
basePref = createListPreference(settings.getCustomRoutingProperty(p.getId(), p.getType() == RoutingParameterType.NUMERIC ? "0.0" : "-"), p.getPossibleValueDescriptions(), svlss, SettingsBaseActivity.getRoutingStringPropertyName(this, p.getId(), p.getName()), SettingsBaseActivity.getRoutingStringPropertyDescription(this, p.getId(), p.getDescription()));
}
basePref.setTitle(SettingsBaseActivity.getRoutingStringPropertyName(this, p.getId(), p.getName()));
basePref.setSummary(SettingsBaseActivity.getRoutingStringPropertyDescription(this, p.getId(), p.getDescription()));
cat.addPreference(basePref);
}
}
ApplicationMode mode = getMyApplication().getSettings().getApplicationMode();
if (mode.isDerivedRoutingFrom(ApplicationMode.CAR)) {
PreferenceCategory category = (PreferenceCategory) screen.findPreference("guidance_preferences");
category.addPreference(speedLimitExceed);
} else {
PreferenceCategory category = (PreferenceCategory) screen.findPreference("guidance_preferences");
category.removePreference(speedLimitExceed);
}
}
}
use of net.osmand.router.GeneralRouter in project Osmand by osmandapp.
the class RoutePreferencesMenu method getRoutingParametersInner.
private List<LocalRoutingParameter> getRoutingParametersInner(ApplicationMode am) {
List<LocalRoutingParameter> list = new ArrayList<LocalRoutingParameter>();
RouteProvider.GPXRouteParamsBuilder rparams = mapActivity.getRoutingHelper().getCurrentGPXRoute();
boolean osmandRouter = settings.ROUTER_SERVICE.getModeValue(am) == RouteProvider.RouteService.OSMAND;
if (!osmandRouter) {
list.add(new OtherLocalRoutingParameter(R.string.calculate_osmand_route_without_internet, getString(R.string.calculate_osmand_route_without_internet), settings.GPX_ROUTE_CALC_OSMAND_PARTS.get()));
list.add(new OtherLocalRoutingParameter(R.string.fast_route_mode, getString(R.string.fast_route_mode), settings.FAST_ROUTE_MODE.get()));
return list;
}
if (rparams != null) {
GPXUtilities.GPXFile fl = rparams.getFile();
if (fl.hasRtePt()) {
list.add(new OtherLocalRoutingParameter(R.string.use_points_as_intermediates, getString(R.string.use_points_as_intermediates), rparams.isUseIntermediatePointsRTE()));
}
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_reverse_route, getString(R.string.gpx_option_reverse_route), rparams.isReverse()));
if (!rparams.isUseIntermediatePointsRTE()) {
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_from_start_point, getString(R.string.gpx_option_from_start_point), rparams.isPassWholeRoute()));
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_calculate_first_last_segment, getString(R.string.gpx_option_calculate_first_last_segment), rparams.isCalculateOsmAndRouteParts()));
}
}
GeneralRouter rm = SettingsNavigationActivity.getRouter(app.getDefaultRoutingConfig(), am);
if (rm == null || (rparams != null && !rparams.isCalculateOsmAndRoute()) && !rparams.getFile().hasRtePt()) {
return list;
}
for (RoutingParameter r : rm.getParameters().values()) {
if (r.getType() == GeneralRouter.RoutingParameterType.BOOLEAN) {
if ("relief_smoothness_factor".equals(r.getGroup())) {
continue;
}
if (!Algorithms.isEmpty(r.getGroup())) {
LocalRoutingParameterGroup rpg = getLocalRoutingParameterGroup(list, r.getGroup());
if (rpg == null) {
rpg = new LocalRoutingParameterGroup(am, r.getGroup());
list.add(rpg);
}
rpg.addRoutingParameter(r);
} else {
LocalRoutingParameter rp = new LocalRoutingParameter(am);
rp.routingParameter = r;
list.add(rp);
}
}
}
return list;
}
use of net.osmand.router.GeneralRouter in project OsmAnd-tools by osmandapp.
the class MapTransportLayer method buildRoute.
public void buildRoute(boolean schedule) {
long time = System.currentTimeMillis();
if (start != null && end != null) {
try {
BinaryMapIndexReader[] files = DataExtractionSettings.getSettings().getObfReaders();
if (files.length == 0) {
JOptionPane.showMessageDialog(OsmExtractionUI.MAIN_APP.getFrame(), "Please specify obf file in settings", "Obf file not found", JOptionPane.ERROR_MESSAGE);
return;
}
System.out.println("Transport route from " + start + " to " + end);
Builder builder = DataExtractionSettings.getSettings().getRoutingConfig();
String m = DataExtractionSettings.getSettings().getRouteMode();
String[] props = m.split("\\,");
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");
}
}
GeneralRouter prouter = builder.getRouter("public_transport");
TransportRoutingConfiguration cfg = new TransportRoutingConfiguration(prouter, paramsR);
cfg.useSchedule = schedule;
TransportRoutePlanner planner = new TransportRoutePlanner();
TransportRoutingContext ctx = new TransportRoutingContext(cfg, DataExtractionSettings.getSettings().useNativeRouting() ? NativeSwingRendering.getDefaultFromSettings() : null, files);
if (ctx.library != null) {
NativeTransportRoutingResult[] nativeRes = ctx.library.runNativePTRouting(MapUtils.get31TileNumberX(start.getLongitude()), MapUtils.get31TileNumberY(start.getLatitude()), MapUtils.get31TileNumberX(end.getLongitude()), MapUtils.get31TileNumberY(end.getLatitude()), cfg, ctx.calculationProgress);
if (nativeRes.length > 0) {
this.results = TransportRoutePlanner.convertToTransportRoutingResult(nativeRes, cfg);
} else {
System.out.println("No luck, empty result from Native");
}
} else {
startProgressThread(ctx);
this.results = planner.buildRoute(ctx, start, end);
}
this.currentRoute = 0;
throwExceptionIfRouteNotFound(ctx, results);
} catch (Exception e) {
ExceptionHandler.handle(e);
} finally {
infoButton.setVisible(false);
prevRoute.setVisible(false);
nextRoute.setVisible(false);
if (map.getPoints() != null) {
map.getPoints().clear();
}
}
System.out.println("Finding self routes " + results.size() + " " + (System.currentTimeMillis() - time) + " ms");
}
return;
}
use of net.osmand.router.GeneralRouter in project OsmAnd-tools by osmandapp.
the class ManyToOneRoadCalculation method calculateManyToMany.
private void calculateManyToMany(RoutingContext ctx, TLongObjectHashMap<ManyToManySegment> allSegments, List<ManyToManySegment> topIntersects, List<ManyToManySegment> bottomIntersects, int stop, final int sbottom) {
final GeneralRouter router = ctx.config.router;
float DISTANCE_THRESHOLD = 50000;
// TODO depth search from one top intersect
List<TLongArrayList> sets = new ArrayList<TLongArrayList>();
for (int i = 0; i < topIntersects.size(); i++) {
ManyToManySegment oneTop = topIntersects.get(i);
clearAllSegments(allSegments);
List<ManyToManySegment> finalSegmentResult = calculateOneToMany(allSegments, bottomIntersects, sbottom, router, oneTop);
for (ManyToManySegment fnsResult : finalSegmentResult) {
TLongArrayList set = convertToRoadIds(fnsResult, DISTANCE_THRESHOLD / router.getMaxDefaultSpeed());
combineWithLocal(sets, set);
}
System.out.println(oneTop.road.getHighway() + " " + oneTop.road.id + " " + oneTop.segmentIndex + " common ways=" + sets.size());
}
System.out.println(sets.size());
for (TLongArrayList s : sets) {
System.out.println(s);
}
}
Aggregations