Skip to content

Commit

Permalink
Merge pull request #538 from afischerdev/lib-update-export
Browse files Browse the repository at this point in the history
Lib update export
  • Loading branch information
afischerdev committed Apr 26, 2023
2 parents e176679 + b7422c0 commit 242a1d7
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 49 deletions.
2 changes: 1 addition & 1 deletion brouter-core/src/main/java/btools/router/OsmPath.java
Expand Up @@ -138,8 +138,8 @@ protected void addAddionalPenalty(OsmTrack refTrack, boolean detailMode, OsmPath
message.ele = Short.MIN_VALUE;
message.linkdist = sourceNode.calcDistance(targetNode);
message.wayKeyValues = "direct_segment=" + seg;
seg++;
}
seg++;
return;
}

Expand Down
53 changes: 34 additions & 19 deletions brouter-core/src/main/java/btools/router/OsmTrack.java
Expand Up @@ -350,8 +350,10 @@ public void appendTrack(OsmTrack t) {
float t0 = ourSize > 0 ? nodes.get(ourSize - 1).getTime() : 0;
float e0 = ourSize > 0 ? nodes.get(ourSize - 1).getEnergy() : 0;
for (i = 0; i < t.nodes.size(); 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) {
OsmPathElement e = t.nodes.get(i);
e.setTime(e.getTime() + t0);
e.setEnergy(e.getEnergy() + e0);
nodes.add(e);
Expand Down Expand Up @@ -613,7 +615,10 @@ public String formatAsGpx(BufferedWriter sb) throws IOException {
}
}
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(" <type>").append(voiceHints.getTransportMode()).append("</type>\n");
} else {
Expand Down Expand Up @@ -644,14 +649,19 @@ public String formatAsGpx(BufferedWriter sb) throws IOException {
if (showTime) {
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;
if (turnInstructionMode == 9) { // trkpt/sym style

if (hint != 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 += "<desc>" + hint.getCruiserMessageString() + "</desc>";
Expand Down Expand Up @@ -741,17 +751,23 @@ public String formatAsGpx(BufferedWriter sb) throws IOException {
if (turnInstructionMode == 2) { // locus style new
if (hint != 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) {
sele += "<src>" + hint.getLocusSymbolString() + "</src><sym>pass_place</sym><type>Shaping</type>";
// bNextDirect = false;
} else if (mwpt.direct) {
sele += "<sym>pass_place</sym><type>Shaping</type>";
if (idx == 0)
sele += "<sym>pass_place</sym><type>Via</type>";
else
sele += "<sym>pass_place</sym><type>Shaping</type>";
bNextDirect = true;
} else if (bNextDirect) {
sele += "<src>beeline</src><sym>" + hint.getLocusSymbolString() + "</sym><type>Shaping</type>";
bNextDirect = false;
} else {
sele += "<sym>" + hint.getLocusSymbolString() + "</sym>";
sele += "<sym>" + hint.getLocusSymbolString() + "</sym><type>Via</type>";
}
} else {
sele += "<sym>" + hint.getLocusSymbolString() + "</sym>";
Expand Down Expand Up @@ -787,28 +803,27 @@ public String formatAsGpx(BufferedWriter sb) throws IOException {

} else {
if (mwpt != null) {
if (sele.contains("sym") &&
!sele.contains("name") &&
!mwpt.name.startsWith("via") &&
!mwpt.name.startsWith("from") &&
!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) {
if (!mwpt.name.startsWith("via") && !mwpt.name.startsWith("from") && !mwpt.name.startsWith("to")) {
sele += "<name>" + mwpt.name + "</name>";
}
if (mwpt.direct && bNextDirect) {
sele += "<src>beeline</src><sym>pass_place</sym><type>Shaping</type>";
} else if (mwpt.direct) {
sele += "<sym>pass_place</sym><type>Shaping</type>";
if (idx == 0)
sele += "<sym>pass_place</sym><type>Via</type>";
else
sele += "<sym>pass_place</sym><type>Shaping</type>";
bNextDirect = true;
} else if (bNextDirect) {
sele += "<src>beeline</src><sym>pass_place</sym><type>Shaping</type>";
bNextDirect = false;
} else if (mwpt.name.startsWith("via") ||
mwpt.name.startsWith("from") ||
mwpt.name.startsWith("to")) {
if (bNextDirect) {
sele += "<src>beeline</src><sym>pass_place</sym><type>Shaping</type>";
} else {
sele += "<sym>pass_place</sym><type>Shaping</type>";
sele += "<sym>pass_place</sym><type>Via</type>";
}
bNextDirect = false;
} else {
Expand Down
29 changes: 19 additions & 10 deletions brouter-core/src/main/java/btools/router/RoutingEngine.java
Expand Up @@ -249,7 +249,7 @@ private void postElevationCheck(OsmTrack track) {
int ourSize = track.nodes.size();
for (int idx = 0; idx < ourSize; 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
if (idx > 1)
startElev = track.nodes.get(idx - 2).getSElev();
Expand Down Expand Up @@ -338,8 +338,9 @@ private void postElevationCheck(OsmTrack track) {
}
} else if (n.getSElev() == Short.MIN_VALUE && idx == track.nodes.size() - 1) {
// fill at end
startIdx = idx;
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) {
if (lastPt != null)
Expand Down Expand Up @@ -474,6 +475,7 @@ private OsmTrack tryFindTrack(OsmTrack[] refTracks, OsmTrack[] lastTracks) {
}
}

OsmPath.seg = 1; // set segment counter
for (int i = 0; i < matchedWaypoints.size() - 1; i++) {
if (lastTracks[i] != null) {
if (refTracks[i] == null) refTracks[i] = new OsmTrack();
Expand Down Expand Up @@ -549,12 +551,6 @@ private boolean snappPathConnection(OsmTrack tt, OsmTrack t, MatchedWaypoint sta
ArrayList<OsmPathElement> removeBackList = new ArrayList<>();
ArrayList<OsmPathElement> removeForeList = new ArrayList<>();
ArrayList<Integer> removeVoiceHintList = new ArrayList<>();
int lon0,
lat0,
lon1,
lat1,
lon2,
lat2;
OsmPathElement last = null;
OsmPathElement lastJunction = null;
CompactLongMap<OsmTrack.OsmPathElementHolder> lastJunctions = new CompactLongMap<>();
Expand All @@ -571,6 +567,18 @@ private boolean snappPathConnection(OsmTrack tt, OsmTrack t, MatchedWaypoint sta
int junctions = 0;
tmpback = tt.nodes.get(indexback);
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);
if (1 == 1) {
OsmTrack.OsmPathElementHolder detours = tt.getFromDetourMap(tmpback.getIdFromPos());
Expand Down Expand Up @@ -780,9 +788,9 @@ private void recalcTrack(OsmTrack t) {
float addTime = (value / (speed_min / 3.6f));

double addEnergy = 0;
if (key < ourSize - 1) {
if (key > 0) {
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 spd = speed_min / 3.6;
addEnergy = value * (routingContext.S_C_x * spd * spd + f_roll);
Expand All @@ -793,6 +801,7 @@ private void recalcTrack(OsmTrack t) {
n.setEnergy(n.getEnergy() + (float) addEnergy);
}
}
t.energy = (int) t.nodes.get(t.nodes.size() - 1).getEnergy();

logInfo("track-length total = " + t.distance);
logInfo("filtered ascend = " + t.ascend);
Expand Down
Expand Up @@ -101,6 +101,19 @@ public String getTrackFromParams(Bundle params) {

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
String extraParams = params.getString("extraParams");
if (rc.keyValues == null) rc.keyValues = new HashMap<String, String>();
Expand All @@ -112,19 +125,7 @@ public String getTrackFromParams(Bundle params) {
String key = tk2.nextToken();
if (tk2.hasMoreTokens()) {
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);
}
}
}
Expand Down Expand Up @@ -217,8 +218,8 @@ private List<OsmNodeNamed> readPositions(Bundle params) {
n.ilat = (int) ((lats[i] + 90.) * 1000000. + 0.5);
wplist.add(n);
}
wplist.get(0).name = "from";
wplist.get(wplist.size() - 1).name = "to";
if (wplist.get(0).name.startsWith("via")) wplist.get(0).name = "from";
if (wplist.get(wplist.size() - 1).name.startsWith("via")) wplist.get(wplist.size() - 1).name = "to";

return wplist;
}
Expand Down Expand Up @@ -247,8 +248,8 @@ private List<OsmNodeNamed> readLonlats(Bundle params) {
}
}

wplist.get(0).name = "from";
wplist.get(wplist.size() - 1).name = "to";
if (wplist.get(0).name.startsWith("via")) wplist.get(0).name = "from";
if (wplist.get(wplist.size() - 1).name.startsWith("via")) wplist.get(wplist.size() - 1).name = "to";

return wplist;
}
Expand Down
Expand Up @@ -109,8 +109,8 @@ public List<OsmNodeNamed> readWayPointList() {
}
}

wplist.get(0).name = "from";
wplist.get(wplist.size() - 1).name = "to";
if (wplist.get(0).name.startsWith("via")) wplist.get(0).name = "from";
if (wplist.get(wplist.size() - 1).name.startsWith("via")) wplist.get(wplist.size() - 1).name = "to";

return wplist;
}
Expand Down
36 changes: 36 additions & 0 deletions docs/developers/android_service.md
Expand Up @@ -8,3 +8,39 @@ BRouter exposes an [Android
Service](https://developer.android.com/guide/components/services) which can be
used by other applications to calculate routes. See `IBRouterService.aidl` for
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
2 changes: 2 additions & 0 deletions docs/developers/http_server.md
Expand Up @@ -14,3 +14,5 @@ BRouter HTTP server for various platforms.

The API endpoints exposed by this HTTP server are documented in the
`ServerHandler.java`

Please see also [IBRouterService.aidl](./android_service.md) for calling parameter.

0 comments on commit 242a1d7

Please sign in to comment.