Merge pull request #538 from afischerdev/lib-update-export

Lib update export
This commit is contained in:
afischerdev 2023-04-26 13:26:08 +02:00 committed by GitHub
commit 242a1d7b93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 112 additions and 49 deletions

View file

@ -138,8 +138,8 @@ abstract class OsmPath implements OsmLinkHolder {
message.ele = Short.MIN_VALUE; message.ele = Short.MIN_VALUE;
message.linkdist = sourceNode.calcDistance(targetNode); message.linkdist = sourceNode.calcDistance(targetNode);
message.wayKeyValues = "direct_segment=" + seg; message.wayKeyValues = "direct_segment=" + seg;
}
seg++; seg++;
}
return; return;
} }

View file

@ -350,8 +350,10 @@ public final class OsmTrack {
float t0 = ourSize > 0 ? nodes.get(ourSize - 1).getTime() : 0; float t0 = ourSize > 0 ? nodes.get(ourSize - 1).getTime() : 0;
float e0 = ourSize > 0 ? nodes.get(ourSize - 1).getEnergy() : 0; float e0 = ourSize > 0 ? nodes.get(ourSize - 1).getEnergy() : 0;
for (i = 0; i < t.nodes.size(); i++) { for (i = 0; i < t.nodes.size(); i++) {
if (i > 0 || ourSize == 0) {
OsmPathElement e = t.nodes.get(i); OsmPathElement e = t.nodes.get(i);
if (i == 0 && ourSize > 0 && nodes.get(ourSize - 1).getSElev() == Short.MIN_VALUE)
nodes.get(ourSize - 1).setSElev(e.getSElev());
if (i > 0 || ourSize == 0) {
e.setTime(e.getTime() + t0); e.setTime(e.getTime() + t0);
e.setEnergy(e.getEnergy() + e0); e.setEnergy(e.getEnergy() + e0);
nodes.add(e); nodes.add(e);
@ -613,7 +615,10 @@ public final class OsmTrack {
} }
} }
sb.append(" <trk>\n"); sb.append(" <trk>\n");
if (turnInstructionMode == 9) { // brouter style if (turnInstructionMode == 9
|| turnInstructionMode == 2
|| turnInstructionMode == 8
|| turnInstructionMode == 4) { // Locus, comment, cruise, brouter style
sb.append(" <src>").append(name).append("</src>\n"); sb.append(" <src>").append(name).append("</src>\n");
sb.append(" <type>").append(voiceHints.getTransportMode()).append("</type>\n"); sb.append(" <type>").append(voiceHints.getTransportMode()).append("</type>\n");
} else { } else {
@ -644,14 +649,19 @@ public final class OsmTrack {
if (showTime) { if (showTime) {
sele += "<time>" + getFormattedTime3(n.getTime()) + "</time>"; sele += "<time>" + getFormattedTime3(n.getTime()) + "</time>";
} }
if (turnInstructionMode == 8) {
if (mwpt != null &&
!mwpt.name.startsWith("via") && !mwpt.name.startsWith("from") && !mwpt.name.startsWith("to")) {
sele += "<name>" + mwpt.name + "</name>";
}
}
boolean bNeedHeader = false; boolean bNeedHeader = false;
if (turnInstructionMode == 9) { // trkpt/sym style if (turnInstructionMode == 9) { // trkpt/sym style
if (hint != null) { if (hint != null) {
if (mwpt != null && if (mwpt != null &&
!mwpt.name.startsWith("via") && !mwpt.name.startsWith("from") && !mwpt.name.startsWith("end")) { !mwpt.name.startsWith("via") && !mwpt.name.startsWith("from") && !mwpt.name.startsWith("to")) {
sele += "<name>" + mwpt.name + "</name>"; sele += "<name>" + mwpt.name + "</name>";
} }
sele += "<desc>" + hint.getCruiserMessageString() + "</desc>"; sele += "<desc>" + hint.getCruiserMessageString() + "</desc>";
@ -741,17 +751,23 @@ public final class OsmTrack {
if (turnInstructionMode == 2) { // locus style new if (turnInstructionMode == 2) { // locus style new
if (hint != null) { if (hint != null) {
if (mwpt != null) { if (mwpt != null) {
if (!mwpt.name.startsWith("via") && !mwpt.name.startsWith("from") && !mwpt.name.startsWith("to")) {
sele += "<name>" + mwpt.name + "</name>";
}
if (mwpt.direct && bNextDirect) { if (mwpt.direct && bNextDirect) {
sele += "<src>" + hint.getLocusSymbolString() + "</src><sym>pass_place</sym><type>Shaping</type>"; sele += "<src>" + hint.getLocusSymbolString() + "</src><sym>pass_place</sym><type>Shaping</type>";
// bNextDirect = false; // bNextDirect = false;
} else if (mwpt.direct) { } else if (mwpt.direct) {
if (idx == 0)
sele += "<sym>pass_place</sym><type>Via</type>";
else
sele += "<sym>pass_place</sym><type>Shaping</type>"; sele += "<sym>pass_place</sym><type>Shaping</type>";
bNextDirect = true; bNextDirect = true;
} else if (bNextDirect) { } else if (bNextDirect) {
sele += "<src>beeline</src><sym>" + hint.getLocusSymbolString() + "</sym><type>Shaping</type>"; sele += "<src>beeline</src><sym>" + hint.getLocusSymbolString() + "</sym><type>Shaping</type>";
bNextDirect = false; bNextDirect = false;
} else { } else {
sele += "<sym>" + hint.getLocusSymbolString() + "</sym>"; sele += "<sym>" + hint.getLocusSymbolString() + "</sym><type>Via</type>";
} }
} else { } else {
sele += "<sym>" + hint.getLocusSymbolString() + "</sym>"; sele += "<sym>" + hint.getLocusSymbolString() + "</sym>";
@ -787,28 +803,27 @@ public final class OsmTrack {
} else { } else {
if (mwpt != null) { if (mwpt != null) {
if (sele.contains("sym") && if (!mwpt.name.startsWith("via") && !mwpt.name.startsWith("from") && !mwpt.name.startsWith("to")) {
!sele.contains("name") && sele += "<name>" + mwpt.name + "</name>";
!mwpt.name.startsWith("via") && }
!mwpt.name.startsWith("from") && if (mwpt.direct && bNextDirect) {
!mwpt.name.startsWith("to")) {
int pos = sele.indexOf("<sym");
if (pos != -1)
sele = sele.substring(0, pos) + "<name>" + mwpt.name + "</name>" + sele.substring(pos) + "<type>Via</type>";
} else if (sele.contains("sym") && mwpt.name.startsWith("via")) {
sele += "<type>Via</type>";
} else if (mwpt.direct && bNextDirect) {
sele += "<src>beeline</src><sym>pass_place</sym><type>Shaping</type>"; sele += "<src>beeline</src><sym>pass_place</sym><type>Shaping</type>";
} else if (mwpt.direct) { } else if (mwpt.direct) {
if (idx == 0)
sele += "<sym>pass_place</sym><type>Via</type>";
else
sele += "<sym>pass_place</sym><type>Shaping</type>"; sele += "<sym>pass_place</sym><type>Shaping</type>";
bNextDirect = true; bNextDirect = true;
} else if (bNextDirect) {
sele += "<src>beeline</src><sym>pass_place</sym><type>Shaping</type>";
bNextDirect = false;
} else if (mwpt.name.startsWith("via") || } else if (mwpt.name.startsWith("via") ||
mwpt.name.startsWith("from") || mwpt.name.startsWith("from") ||
mwpt.name.startsWith("to")) { mwpt.name.startsWith("to")) {
if (bNextDirect) { if (bNextDirect) {
sele += "<src>beeline</src><sym>pass_place</sym><type>Shaping</type>"; sele += "<src>beeline</src><sym>pass_place</sym><type>Shaping</type>";
} else { } else {
sele += "<sym>pass_place</sym><type>Shaping</type>"; sele += "<sym>pass_place</sym><type>Via</type>";
} }
bNextDirect = false; bNextDirect = false;
} else { } else {

View file

@ -249,7 +249,7 @@ public class RoutingEngine extends Thread {
int ourSize = track.nodes.size(); int ourSize = track.nodes.size();
for (int idx = 0; idx < ourSize; idx++) { for (int idx = 0; idx < ourSize; idx++) {
OsmPathElement n = track.nodes.get(idx); OsmPathElement n = track.nodes.get(idx);
if (n.getSElev() == Short.MIN_VALUE && lastElev != Short.MIN_VALUE && idx < ourSize-1) { if (n.getSElev() == Short.MIN_VALUE && lastElev != Short.MIN_VALUE && idx < ourSize - 1) {
// start one point before entry point to get better elevation results // start one point before entry point to get better elevation results
if (idx > 1) if (idx > 1)
startElev = track.nodes.get(idx - 2).getSElev(); startElev = track.nodes.get(idx - 2).getSElev();
@ -338,8 +338,9 @@ public class RoutingEngine extends Thread {
} }
} else if (n.getSElev() == Short.MIN_VALUE && idx == track.nodes.size() - 1) { } else if (n.getSElev() == Short.MIN_VALUE && idx == track.nodes.size() - 1) {
// fill at end // fill at end
startIdx = idx;
for (int i = startIdx; i < track.nodes.size(); i++) { for (int i = startIdx; i < track.nodes.size(); i++) {
track.nodes.get(i).setSElev(startElev); track.nodes.get(i).setSElev(lastElev);
} }
} else if (n.getSElev() == Short.MIN_VALUE) { } else if (n.getSElev() == Short.MIN_VALUE) {
if (lastPt != null) if (lastPt != null)
@ -474,6 +475,7 @@ public class RoutingEngine extends Thread {
} }
} }
OsmPath.seg = 1; // set segment counter
for (int i = 0; i < matchedWaypoints.size() - 1; i++) { for (int i = 0; i < matchedWaypoints.size() - 1; i++) {
if (lastTracks[i] != null) { if (lastTracks[i] != null) {
if (refTracks[i] == null) refTracks[i] = new OsmTrack(); if (refTracks[i] == null) refTracks[i] = new OsmTrack();
@ -549,12 +551,6 @@ public class RoutingEngine extends Thread {
ArrayList<OsmPathElement> removeBackList = new ArrayList<>(); ArrayList<OsmPathElement> removeBackList = new ArrayList<>();
ArrayList<OsmPathElement> removeForeList = new ArrayList<>(); ArrayList<OsmPathElement> removeForeList = new ArrayList<>();
ArrayList<Integer> removeVoiceHintList = new ArrayList<>(); ArrayList<Integer> removeVoiceHintList = new ArrayList<>();
int lon0,
lat0,
lon1,
lat1,
lon2,
lat2;
OsmPathElement last = null; OsmPathElement last = null;
OsmPathElement lastJunction = null; OsmPathElement lastJunction = null;
CompactLongMap<OsmTrack.OsmPathElementHolder> lastJunctions = new CompactLongMap<>(); CompactLongMap<OsmTrack.OsmPathElementHolder> lastJunctions = new CompactLongMap<>();
@ -571,6 +567,18 @@ public class RoutingEngine extends Thread {
int junctions = 0; int junctions = 0;
tmpback = tt.nodes.get(indexback); tmpback = tt.nodes.get(indexback);
tmpfore = t.nodes.get(indexfore); tmpfore = t.nodes.get(indexfore);
if (tmpback.message != null && tmpback.message.isRoundabout()) {
removeBackList.clear();
removeForeList.clear();
removeVoiceHintList.clear();
return false;
}
if (tmpfore.message != null && tmpfore.message.isRoundabout()) {
removeBackList.clear();
removeForeList.clear();
removeVoiceHintList.clear();
return false;
}
int dist = tmpback.calcDistance(tmpfore); int dist = tmpback.calcDistance(tmpfore);
if (1 == 1) { if (1 == 1) {
OsmTrack.OsmPathElementHolder detours = tt.getFromDetourMap(tmpback.getIdFromPos()); OsmTrack.OsmPathElementHolder detours = tt.getFromDetourMap(tmpback.getIdFromPos());
@ -780,9 +788,9 @@ public class RoutingEngine extends Thread {
float addTime = (value / (speed_min / 3.6f)); float addTime = (value / (speed_min / 3.6f));
double addEnergy = 0; double addEnergy = 0;
if (key < ourSize - 1) { if (key > 0) {
double GRAVITY = 9.81; // in meters per second^(-2) double GRAVITY = 9.81; // in meters per second^(-2)
double incline = (t.nodes.get(key).getElev() - t.nodes.get(key + 1).getElev()) / value; double incline = (t.nodes.get(key - 1).getSElev() == Short.MIN_VALUE || t.nodes.get(key).getSElev() == Short.MIN_VALUE ? 0 : (t.nodes.get(key - 1).getElev() - t.nodes.get(key).getElev()) / value);
double f_roll = routingContext.totalMass * GRAVITY * (routingContext.defaultC_r + incline); double f_roll = routingContext.totalMass * GRAVITY * (routingContext.defaultC_r + incline);
double spd = speed_min / 3.6; double spd = speed_min / 3.6;
addEnergy = value * (routingContext.S_C_x * spd * spd + f_roll); addEnergy = value * (routingContext.S_C_x * spd * spd + f_roll);
@ -793,6 +801,7 @@ public class RoutingEngine extends Thread {
n.setEnergy(n.getEnergy() + (float) addEnergy); n.setEnergy(n.getEnergy() + (float) addEnergy);
} }
} }
t.energy = (int) t.nodes.get(t.nodes.size() - 1).getEnergy();
logInfo("track-length total = " + t.distance); logInfo("track-length total = " + t.distance);
logInfo("filtered ascend = " + t.ascend); logInfo("filtered ascend = " + t.ascend);

View file

@ -101,6 +101,19 @@ public class BRouterWorker {
if (waypoints == null) return "no pts "; if (waypoints == null) return "no pts ";
if (params.containsKey("straight")) {
try {
String straight = params.getString("straight");
String[] sa = straight.split(",");
for (int i = 0; i < sa.length; i++) {
int v = Integer.valueOf(sa[i]);
if (waypoints.size() > v) waypoints.get(v).direct = true;
}
} catch (NumberFormatException e) {
}
}
if (params.containsKey("extraParams")) { // add user params if (params.containsKey("extraParams")) { // add user params
String extraParams = params.getString("extraParams"); String extraParams = params.getString("extraParams");
if (rc.keyValues == null) rc.keyValues = new HashMap<String, String>(); if (rc.keyValues == null) rc.keyValues = new HashMap<String, String>();
@ -112,23 +125,11 @@ public class BRouterWorker {
String key = tk2.nextToken(); String key = tk2.nextToken();
if (tk2.hasMoreTokens()) { if (tk2.hasMoreTokens()) {
String value = tk2.nextToken(); String value = tk2.nextToken();
if (key.equals("straight")) {
try {
String[] sa = value.split(",");
for (int i = 0; i < sa.length; i++) {
int v = Integer.valueOf(sa[i]);
if (waypoints.size() > v) waypoints.get(v).direct = true;
}
} catch (Exception e) {
System.err.println("error " + e.getStackTrace()[0].getLineNumber() + " " + e.getStackTrace()[0] + "\n" + e);
}
} else {
rc.keyValues.put(key, value); rc.keyValues.put(key, value);
} }
} }
} }
} }
}
try { try {
@ -217,8 +218,8 @@ public class BRouterWorker {
n.ilat = (int) ((lats[i] + 90.) * 1000000. + 0.5); n.ilat = (int) ((lats[i] + 90.) * 1000000. + 0.5);
wplist.add(n); wplist.add(n);
} }
wplist.get(0).name = "from"; if (wplist.get(0).name.startsWith("via")) wplist.get(0).name = "from";
wplist.get(wplist.size() - 1).name = "to"; if (wplist.get(wplist.size() - 1).name.startsWith("via")) wplist.get(wplist.size() - 1).name = "to";
return wplist; return wplist;
} }
@ -247,8 +248,8 @@ public class BRouterWorker {
} }
} }
wplist.get(0).name = "from"; if (wplist.get(0).name.startsWith("via")) wplist.get(0).name = "from";
wplist.get(wplist.size() - 1).name = "to"; if (wplist.get(wplist.size() - 1).name.startsWith("via")) wplist.get(wplist.size() - 1).name = "to";
return wplist; return wplist;
} }

View file

@ -109,8 +109,8 @@ public class ServerHandler extends RequestHandler {
} }
} }
wplist.get(0).name = "from"; if (wplist.get(0).name.startsWith("via")) wplist.get(0).name = "from";
wplist.get(wplist.size() - 1).name = "to"; if (wplist.get(wplist.size() - 1).name.startsWith("via")) wplist.get(wplist.size() - 1).name = "to";
return wplist; return wplist;
} }

View file

@ -8,3 +8,39 @@ BRouter exposes an [Android
Service](https://developer.android.com/guide/components/services) which can be Service](https://developer.android.com/guide/components/services) which can be
used by other applications to calculate routes. See `IBRouterService.aidl` for used by other applications to calculate routes. See `IBRouterService.aidl` for
the interface definition. the interface definition.
## Some words on the input rules (app and server)
We have some parts of input:
### lonlats
The lonlats parameter is a list of positions where the routing should go along. It is recommended to use this instead of the two parameter lons and lats.
When there are more than two points the 'via' points may be off the perfect route - in lower zoom level it is not always clear if a point meets the best way.
The profile parameter 'correctMisplacedViaPoints' tries to avoid this situation.
On the other hand, it would be fatal if this point is not reached when you want to go there.
There are to choices to manage that:
- add a poi to the 'pois' list
- name the point in lonlats list
Another feature of BRouter is routing via beelines.
Define a straight starting point in the 'lonlats' list with a 'd' (direct). The second point needs no declaration.
This contradicts the naming rules in 'lonlats'. If the point is to be given a name, the router parameter 'straight' can be used instead and filled with the index of the point.
'nogos', 'polylines' and 'polygons' are also lists of positions.
Please note: when they have a parameter 'weight' the result is not an absolute nogo it is weighted to the other ways.
### routing parameter
This parameters are needed to tell BRouter what to do.
### profile parameter
Profile parameters affect the result of a profile.
For the app it is a list of params concatenated by '&'. E.g. extraParams=avoidferry=1&avoidsteps=0
The server calls profile params by a prefix 'profile:'. E.g. ...&profile:avoidferry=1&profile:avoidsteps=0

View file

@ -14,3 +14,5 @@ BRouter HTTP server for various platforms.
The API endpoints exposed by this HTTP server are documented in the The API endpoints exposed by this HTTP server are documented in the
`ServerHandler.java` `ServerHandler.java`
Please see also [IBRouterService.aidl](./android_service.md) for calling parameter.