use of net.osmand.router.RouteSegmentResult in project OsmAnd-tools by osmandapp.
the class DijkstraAlgorithm method main.
public static void main(String[] args) throws IOException, InterruptedException, XmlPullParserException {
File fl = new File("/Users/victorshcherb/osmand/maps/Netherlands_europe_2.obf");
// $NON-NLS-1$ //$NON-NLS-2$
RandomAccessFile raf = new RandomAccessFile(fl, "r");
RoutePlannerFrontEnd fe = new RoutePlannerFrontEnd(false);
Builder builder = RoutingConfiguration.parseFromInputStream(new FileInputStream("/Users/victorshcherb/osmand/repos/resources/routing/routing.xml"));
RoutingConfiguration config = builder.build("car", RoutingConfiguration.DEFAULT_MEMORY_LIMIT * 3);
RoutingContext ctx = fe.buildRoutingContext(config, null, new BinaryMapIndexReader[] { new BinaryMapIndexReader(raf, fl) }, RouteCalculationMode.NORMAL);
RouteResultPreparation.PRINT_TO_CONSOLE_ROUTE_INFORMATION_TO_TEST = true;
List<RouteSegmentResult> route = fe.searchRoute(ctx, new LatLon(52.28283, 4.8622713), new LatLon(52.326496, 4.8753176), null);
}
use of net.osmand.router.RouteSegmentResult in project Osmand by osmandapp.
the class RouteCalculationResult method convertVectorResult.
/**
* PREPARATION
*/
private static List<RouteSegmentResult> convertVectorResult(List<RouteDirectionInfo> directions, List<Location> locations, List<RouteSegmentResult> list, List<AlarmInfo> alarms, OsmandApplication ctx) {
float prevDirectionTime = 0;
float prevDirectionDistance = 0;
double lastHeight = HEIGHT_UNDEFINED;
List<RouteSegmentResult> segmentsToPopulate = new ArrayList<RouteSegmentResult>();
AlarmInfo tunnelAlarm = null;
for (int routeInd = 0; routeInd < list.size(); routeInd++) {
RouteSegmentResult s = list.get(routeInd);
float[] vls = s.getObject().calculateHeightArray();
boolean plus = s.getStartPointIndex() < s.getEndPointIndex();
int i = s.getStartPointIndex();
int prevLocationSize = locations.size();
if (s.getObject().tunnel()) {
if (tunnelAlarm == null) {
LatLon latLon = s.getPoint(i);
tunnelAlarm = new AlarmInfo(AlarmInfoType.TUNNEL, prevLocationSize);
tunnelAlarm.setLatLon(latLon.getLatitude(), latLon.getLongitude());
tunnelAlarm.setFloatValue(s.getDistance());
alarms.add(tunnelAlarm);
} else {
tunnelAlarm.setFloatValue(tunnelAlarm.getFloatValue() + s.getDistance());
}
} else {
if (tunnelAlarm != null) {
tunnelAlarm.setLastLocationIndex(locations.size());
}
tunnelAlarm = null;
}
while (true) {
// $NON-NLS-1$
Location n = new Location("");
LatLon point = s.getPoint(i);
n.setLatitude(point.getLatitude());
n.setLongitude(point.getLongitude());
if (i == s.getEndPointIndex() && routeInd != list.size() - 1) {
break;
}
if (vls != null && i * 2 + 1 < vls.length) {
float h = vls[2 * i + 1];
n.setAltitude(h);
if (lastHeight == HEIGHT_UNDEFINED && locations.size() > 0) {
for (Location l : locations) {
if (!l.hasAltitude()) {
l.setAltitude(h);
}
}
}
lastHeight = h;
}
locations.add(n);
attachAlarmInfo(alarms, s, i, locations.size());
segmentsToPopulate.add(s);
if (i == s.getEndPointIndex()) {
break;
}
if (plus) {
i++;
} else {
i--;
}
}
TurnType turn = s.getTurnType();
if (turn != null) {
RouteDirectionInfo info = new RouteDirectionInfo(s.getSegmentSpeed(), turn);
if (routeInd < list.size()) {
int lind = routeInd;
if (turn.isRoundAbout()) {
int roundAboutEnd = prevLocationSize;
// take next name for roundabout (not roundabout name)
while (lind < list.size() - 1 && list.get(lind).getObject().roundabout()) {
roundAboutEnd += Math.abs(list.get(lind).getEndPointIndex() - list.get(lind).getStartPointIndex());
lind++;
}
// Consider roundabout end.
info.routeEndPointOffset = roundAboutEnd;
}
RouteSegmentResult next = list.get(lind);
info.setRef(next.getObject().getRef(ctx.getSettings().MAP_PREFERRED_LOCALE.get(), ctx.getSettings().MAP_TRANSLITERATE_NAMES.get(), next.isForwardDirection()));
info.setStreetName(next.getObject().getName(ctx.getSettings().MAP_PREFERRED_LOCALE.get(), ctx.getSettings().MAP_TRANSLITERATE_NAMES.get()));
info.setDestinationName(next.getObject().getDestinationName(ctx.getSettings().MAP_PREFERRED_LOCALE.get(), ctx.getSettings().MAP_TRANSLITERATE_NAMES.get(), next.isForwardDirection()));
}
String description = toString(turn, ctx, false) + " " + RoutingHelper.formatStreetName(info.getStreetName(), info.getRef(), info.getDestinationName(), ctx.getString(R.string.towards));
description = description.trim();
String[] pointNames = s.getObject().getPointNames(s.getStartPointIndex());
if (pointNames != null) {
for (int t = 0; t < pointNames.length; t++) {
description = description.trim();
description += " " + pointNames[t];
}
}
info.setDescriptionRoute(description);
info.routePointOffset = prevLocationSize;
if (directions.size() > 0 && prevDirectionTime > 0 && prevDirectionDistance > 0) {
RouteDirectionInfo prev = directions.get(directions.size() - 1);
prev.setAverageSpeed(prevDirectionDistance / prevDirectionTime);
prevDirectionDistance = 0;
prevDirectionTime = 0;
}
directions.add(info);
}
prevDirectionDistance += s.getDistance();
prevDirectionTime += s.getSegmentTime();
}
if (directions.size() > 0 && prevDirectionTime > 0 && prevDirectionDistance > 0) {
RouteDirectionInfo prev = directions.get(directions.size() - 1);
prev.setAverageSpeed(prevDirectionDistance / prevDirectionTime);
}
return segmentsToPopulate;
}
use of net.osmand.router.RouteSegmentResult in project Osmand by osmandapp.
the class RouteCalculationResult method getUpcomingTunnel.
public List<RouteSegmentResult> getUpcomingTunnel(float distToStart) {
int cs = currentRoute > 0 ? currentRoute - 1 : 0;
if (cs < segments.size()) {
RouteSegmentResult prev = null;
boolean tunnel = false;
while (cs < segments.size() && distToStart > 0) {
RouteSegmentResult segment = segments.get(cs);
if (segment != prev) {
if (segment.getObject().tunnel()) {
tunnel = true;
break;
} else {
distToStart -= segment.getDistance();
prev = segment;
}
}
cs++;
}
if (tunnel) {
List<RouteSegmentResult> list = new ArrayList<RouteSegmentResult>();
while (cs < segments.size()) {
RouteSegmentResult segment = segments.get(cs);
if (segment != prev) {
if (segment.getObject().tunnel()) {
list.add(segment);
} else {
break;
}
prev = segment;
}
cs++;
}
return list;
}
}
return null;
}
use of net.osmand.router.RouteSegmentResult in project Osmand by osmandapp.
the class VoiceRouter method updateStatus.
/**
* Updates status of voice guidance
* @param currentLocation
*/
protected void updateStatus(Location currentLocation, boolean repeat) {
// Directly after turn: goAhead (dist), unless:
// < PREPARE_LONG_DISTANCE (e.g. 3500m): playPrepareTurn (-not played any more-)
// < PREPARE_DISTANCE (e.g. 1500m): playPrepareTurn ("Turn after ...")
// < TURN_IN_DISTANCE (e.g. 390m or 30sec): playMakeTurnIn ("Turn in ...")
// < TURN_DISTANCE (e.g. 50m or 7sec): playMakeTurn ("Turn ...")
float speed = DEFAULT_SPEED;
if (currentLocation != null && currentLocation.hasSpeed()) {
speed = Math.max(currentLocation.getSpeed(), speed);
}
NextDirectionInfo nextInfo = router.getNextRouteDirectionInfo(new NextDirectionInfo(), true);
RouteSegmentResult currentSegment = router.getCurrentSegmentResult();
if (nextInfo == null || nextInfo.directionInfo == null) {
return;
}
int dist = nextInfo.distanceTo;
RouteDirectionInfo next = nextInfo.directionInfo;
// If routing is changed update status to unknown
if (next != nextRouteDirection) {
nextRouteDirection = next;
currentStatus = STATUS_UNKNOWN;
suppressDest = false;
playedAndArriveAtTarget = false;
announceBackOnRoute = false;
if (playGoAheadDist != -1) {
playGoAheadDist = 0;
}
}
if (!repeat) {
if (dist <= 0) {
return;
} else if (needsInforming()) {
playGoAhead(dist, getSpeakableStreetName(currentSegment, next, false));
return;
} else if (currentStatus == STATUS_TOLD) {
// however it should be checked manually ?
return;
}
}
if (currentStatus == STATUS_UNKNOWN) {
// Play "Continue for ..." if (1) after route calculation no other prompt is due, or (2) after a turn if next turn is more than PREPARE_LONG_DISTANCE away
if ((playGoAheadDist == -1) || (dist > PREPARE_LONG_DISTANCE)) {
playGoAheadDist = dist - 3 * TURN_DISTANCE;
}
}
// I think "true" is correct here, not "!repeat"
NextDirectionInfo nextNextInfo = router.getNextRouteDirectionInfoAfter(nextInfo, new NextDirectionInfo(), true);
// STATUS_TURN = "Turn (now)"
if ((repeat || statusNotPassed(STATUS_TURN)) && isDistanceLess(speed, dist, TURN_DISTANCE, TURN_DEFAULT_SPEED)) {
if (nextNextInfo.distanceTo < TURN_IN_DISTANCE_END && nextNextInfo != null) {
playMakeTurn(currentSegment, next, nextNextInfo);
} else {
playMakeTurn(currentSegment, next, null);
}
if (!next.getTurnType().goAhead() && isTargetPoint(nextNextInfo)) {
// !goAhead() avoids isolated "and arrive.." prompt, as goAhead() is not pronounced
if (nextNextInfo.distanceTo < TURN_IN_DISTANCE_END) {
// Distance fon non-straights already announced in "Turn (now)"'s nextnext code above
if ((nextNextInfo != null) && (nextNextInfo.directionInfo != null) && nextNextInfo.directionInfo.getTurnType().goAhead()) {
playThen();
playGoAhead(nextNextInfo.distanceTo, empty);
}
playAndArriveAtDestination(nextNextInfo);
} else if (nextNextInfo.distanceTo < 1.2f * TURN_IN_DISTANCE_END) {
// 1.2 is safety margin should the subsequent "Turn in" prompt not fit in amy more
playThen();
playGoAhead(nextNextInfo.distanceTo, empty);
playAndArriveAtDestination(nextNextInfo);
}
}
nextStatusAfter(STATUS_TURN);
// STATUS_TURN_IN = "Turn in ..."
} else if ((repeat || statusNotPassed(STATUS_TURN_IN)) && isDistanceLess(speed, dist, TURN_IN_DISTANCE, 0f)) {
if (repeat || dist >= TURN_IN_DISTANCE_END) {
if ((isDistanceLess(speed, nextNextInfo.distanceTo, TURN_DISTANCE, 0f) || nextNextInfo.distanceTo < TURN_IN_DISTANCE_END) && nextNextInfo != null) {
playMakeTurnIn(currentSegment, next, dist - (int) btScoDelayDistance, nextNextInfo.directionInfo);
} else {
playMakeTurnIn(currentSegment, next, dist - (int) btScoDelayDistance, null);
}
playGoAndArriveAtDestination(repeat, nextInfo, currentSegment);
}
nextStatusAfter(STATUS_TURN_IN);
// STATUS_PREPARE = "Turn after ..."
} else if ((repeat || statusNotPassed(STATUS_PREPARE)) && (dist <= PREPARE_DISTANCE)) {
if (repeat || dist >= PREPARE_DISTANCE_END) {
if (!repeat && (next.getTurnType().keepLeft() || next.getTurnType().keepRight())) {
// Do not play prepare for keep left/right
} else {
playPrepareTurn(currentSegment, next, dist);
playGoAndArriveAtDestination(repeat, nextInfo, currentSegment);
}
}
nextStatusAfter(STATUS_PREPARE);
// STATUS_LONG_PREPARE = also "Turn after ...", we skip this now, users said this is obsolete
} else if ((repeat || statusNotPassed(STATUS_LONG_PREPARE)) && (dist <= PREPARE_LONG_DISTANCE)) {
if (repeat || dist >= PREPARE_LONG_DISTANCE_END) {
playPrepareTurn(currentSegment, next, dist);
playGoAndArriveAtDestination(repeat, nextInfo, currentSegment);
}
nextStatusAfter(STATUS_LONG_PREPARE);
// STATUS_UNKNOWN = "Continue for ..." if (1) after route calculation no other prompt is due, or (2) after a turn if next turn is more than PREPARE_LONG_DISTANCE away
} else if (statusNotPassed(STATUS_UNKNOWN)) {
// Strange how we get here but
nextStatusAfter(STATUS_UNKNOWN);
} else if (repeat || (statusNotPassed(STATUS_PREPARE) && dist < playGoAheadDist)) {
playGoAheadDist = 0;
playGoAhead(dist, getSpeakableStreetName(currentSegment, next, false));
}
}
Aggregations