Merge pull request #634 from afischerdev/engine-mode
Update new parameter collector for BRouter app
This commit is contained in:
commit
c6473055f4
6 changed files with 128 additions and 514 deletions
|
@ -14,8 +14,9 @@ public class RoutingParamCollector {
|
|||
|
||||
/**
|
||||
* get a list of points and optional extra info for the points
|
||||
* @param lonLats - linked list separated by ';' or '|'
|
||||
* @return - a list
|
||||
*
|
||||
* @param lonLats linked list separated by ';' or '|'
|
||||
* @return a list
|
||||
*/
|
||||
public List<OsmNodeNamed> getWayPointList(String lonLats) {
|
||||
if (lonLats == null) throw new IllegalArgumentException("lonlats parameter not set");
|
||||
|
@ -49,9 +50,10 @@ public class RoutingParamCollector {
|
|||
|
||||
/**
|
||||
* get a list of points (old style, positions only)
|
||||
* @param lons - array with longitudes
|
||||
* @param lats - array with latitudes
|
||||
* @return - a list
|
||||
*
|
||||
* @param lons array with longitudes
|
||||
* @param lats array with latitudes
|
||||
* @return a list
|
||||
*/
|
||||
public List<OsmNodeNamed> readPositions(double[] lons, double[] lats) {
|
||||
List<OsmNodeNamed> wplist = new ArrayList<>();
|
||||
|
@ -93,8 +95,9 @@ public class RoutingParamCollector {
|
|||
|
||||
/**
|
||||
* read a url like parameter list linked with '&'
|
||||
* @param url - parameter list
|
||||
* @return - a hashmap of the parameter
|
||||
*
|
||||
* @param url parameter list
|
||||
* @return a hashmap of the parameter
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
public Map<String, String> getUrlParams(String url) throws UnsupportedEncodingException {
|
||||
|
@ -117,9 +120,10 @@ public class RoutingParamCollector {
|
|||
|
||||
/**
|
||||
* fill a parameter map into the routing context
|
||||
* @param rctx - the context
|
||||
* @param wplist - the list of way points needed for 'straight' parameter
|
||||
* @param params - the list of parameters
|
||||
*
|
||||
* @param rctx the context
|
||||
* @param wplist the list of way points needed for 'straight' parameter
|
||||
* @param params the list of parameters
|
||||
*/
|
||||
public void setParams(RoutingContext rctx, List<OsmNodeNamed> wplist, Map<String, String> params) {
|
||||
if (params != null) {
|
||||
|
@ -129,11 +133,15 @@ public class RoutingParamCollector {
|
|||
if (params.containsKey("profile")) {
|
||||
rctx.localFunction = params.get("profile");
|
||||
}
|
||||
if (params.containsKey("nogoLats")) {
|
||||
if (params.containsKey("nogoLats") && params.get("nogoLats").length() > 0) {
|
||||
List<OsmNodeNamed> nogoList = readNogos(params.get("nogoLons"), params.get("nogoLats"), params.get("nogoRadi"));
|
||||
if (nogoList != null) {
|
||||
RoutingContext.prepareNogoPoints(nogoList);
|
||||
if (rctx.nogopoints == null) {
|
||||
rctx.nogopoints = nogoList;
|
||||
} else {
|
||||
rctx.nogopoints.addAll(nogoList);
|
||||
}
|
||||
}
|
||||
params.remove("nogoLats");
|
||||
params.remove("nogoLons");
|
||||
|
@ -143,7 +151,11 @@ public class RoutingParamCollector {
|
|||
List<OsmNodeNamed> nogoList = readNogoList(params.get("nogos"));
|
||||
if (nogoList != null) {
|
||||
RoutingContext.prepareNogoPoints(nogoList);
|
||||
if (rctx.nogopoints == null) {
|
||||
rctx.nogopoints = nogoList;
|
||||
} else {
|
||||
rctx.nogopoints.addAll(nogoList);
|
||||
}
|
||||
}
|
||||
params.remove("nogos");
|
||||
}
|
||||
|
@ -196,6 +208,12 @@ public class RoutingParamCollector {
|
|||
rctx.turnInstructionMode = Integer.parseInt(value);
|
||||
} else if (key.equals("timode")) {
|
||||
rctx.turnInstructionMode = Integer.parseInt(value);
|
||||
} else if (key.equals("turnInstructionFormat")) {
|
||||
if ("osmand".equalsIgnoreCase(value)) {
|
||||
rctx.turnInstructionMode = 3;
|
||||
} else if ("locus".equalsIgnoreCase(value)) {
|
||||
rctx.turnInstructionMode = 2;
|
||||
}
|
||||
} else if (key.equals("exportWaypoints")) {
|
||||
rctx.exportWaypoints = (Integer.parseInt(value) == 1);
|
||||
} else if (key.equals("format")) {
|
||||
|
@ -213,8 +231,9 @@ public class RoutingParamCollector {
|
|||
|
||||
/**
|
||||
* fill profile parameter list
|
||||
* @param rctx - the routing context
|
||||
* @param params - the list of parameters
|
||||
*
|
||||
* @param rctx the routing context
|
||||
* @param params the list of parameters
|
||||
*/
|
||||
public void setProfileParams(RoutingContext rctx, Map<String, String> params) {
|
||||
if (params != null) {
|
||||
|
|
|
@ -19,6 +19,7 @@ import java.io.InputStreamReader;
|
|||
import java.io.OutputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
|
@ -39,10 +40,6 @@ public class BRouterService extends Service {
|
|||
|
||||
BRouterWorker worker = new BRouterWorker();
|
||||
|
||||
for (String key : params.keySet()) {
|
||||
// Log.d("BS", "income " + key + " = " + params.get(key));
|
||||
}
|
||||
|
||||
int engineMode = 0;
|
||||
if (params.containsKey("engineMode")) {
|
||||
engineMode = params.getInt("engineMode", 0);
|
||||
|
@ -277,8 +274,13 @@ public class BRouterService extends Service {
|
|||
private void logBundle(Bundle params) {
|
||||
if (AppLogger.isLogging()) {
|
||||
for (String k : params.keySet()) {
|
||||
Object val = "remoteProfile".equals(k) ? "<..cut..>" : params.getString(k);
|
||||
String desc = "key=" + k + (val == null ? "" : " class=" + val.getClass() + " val=" + val.toString());
|
||||
Object val = "remoteProfile".equals(k) ? "<..cut..>" : params.get(k);
|
||||
String desc = "key=" + k + (val == null ? "" : " class=" + val.getClass() + " val=");
|
||||
if (val instanceof double[]) {
|
||||
desc += Arrays.toString(params.getDoubleArray(k));
|
||||
} else {
|
||||
desc += val.toString();
|
||||
}
|
||||
AppLogger.log(desc);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,16 +6,17 @@ import android.os.Bundle;
|
|||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.Map;
|
||||
|
||||
import btools.router.OsmNodeNamed;
|
||||
import btools.router.OsmNogoPolygon;
|
||||
import btools.router.OsmTrack;
|
||||
import btools.router.RoutingContext;
|
||||
import btools.router.RoutingEngine;
|
||||
import btools.router.RoutingParamCollector;
|
||||
|
||||
public class BRouterWorker {
|
||||
private static final int OUTPUT_FORMAT_GPX = 0;
|
||||
|
@ -39,6 +40,72 @@ public class BRouterWorker {
|
|||
engineMode = params.getInt("engineMode", 0);
|
||||
}
|
||||
|
||||
RoutingContext rc = new RoutingContext();
|
||||
rc.rawTrackPath = rawTrackPath;
|
||||
rc.localFunction = profilePath;
|
||||
|
||||
RoutingParamCollector routingParamCollector = new RoutingParamCollector();
|
||||
|
||||
// parameter pre control
|
||||
if (params.containsKey("lonlats")) {
|
||||
waypoints = routingParamCollector.getWayPointList(params.getString("lonlats"));
|
||||
params.remove("lonlats");
|
||||
}
|
||||
if (params.containsKey("lats")) {
|
||||
double[] lats = params.getDoubleArray("lats");
|
||||
double[] lons = params.getDoubleArray("lons");
|
||||
waypoints = routingParamCollector.readPositions(lons, lats);
|
||||
params.remove("lons");
|
||||
params.remove("lats");
|
||||
}
|
||||
|
||||
if (waypoints == null) {
|
||||
throw new IllegalArgumentException("no points!");
|
||||
}
|
||||
if (engineMode == 0) {
|
||||
if (waypoints.size() < 2) {
|
||||
throw new IllegalArgumentException("we need two lat/lon points at least!");
|
||||
}
|
||||
} else {
|
||||
if (waypoints.size() < 1) {
|
||||
throw new IllegalArgumentException("we need two lat/lon points at least!");
|
||||
}
|
||||
}
|
||||
|
||||
if (nogoList != null && nogoList.size() > 0) {
|
||||
// forward already read nogos from filesystem
|
||||
if (rc.nogopoints == null) {
|
||||
rc.nogopoints = nogoList;
|
||||
} else {
|
||||
rc.nogopoints.addAll(nogoList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Map<String, String> theParams = new HashMap<>();
|
||||
for (String key : params.keySet()) {
|
||||
Object value = params.get(key);
|
||||
if (value instanceof double[]) {
|
||||
String s = Arrays.toString(params.getDoubleArray(key));
|
||||
s = s.replace("[", "").replace("]", "");
|
||||
theParams.put(key, s);
|
||||
} else {
|
||||
theParams.put(key, value.toString());
|
||||
}
|
||||
}
|
||||
routingParamCollector.setParams(rc, waypoints, theParams);
|
||||
|
||||
if (params.containsKey("extraParams")) {
|
||||
Map<String, String> profileparams = null;
|
||||
try {
|
||||
profileparams = routingParamCollector.getUrlParams(params.getString("extraParams"));
|
||||
routingParamCollector.setProfileParams(rc, profileparams);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String pathToFileResult = params.getString("pathToFileResult");
|
||||
|
||||
if (pathToFileResult != null) {
|
||||
|
@ -52,100 +119,9 @@ public class BRouterWorker {
|
|||
long maxRunningTime = 60000;
|
||||
String sMaxRunningTime = params.getString("maxRunningTime");
|
||||
if (sMaxRunningTime != null) {
|
||||
maxRunningTime = Integer.parseInt(sMaxRunningTime) * 1000;
|
||||
maxRunningTime = Integer.parseInt(sMaxRunningTime) * 1000L;
|
||||
}
|
||||
|
||||
RoutingContext rc = new RoutingContext();
|
||||
rc.rawTrackPath = rawTrackPath;
|
||||
rc.localFunction = profilePath;
|
||||
|
||||
String tiFormat = params.getString("turnInstructionFormat");
|
||||
if (tiFormat != null) {
|
||||
if ("osmand".equalsIgnoreCase(tiFormat)) {
|
||||
rc.turnInstructionMode = 3;
|
||||
} else if ("locus".equalsIgnoreCase(tiFormat)) {
|
||||
rc.turnInstructionMode = 2;
|
||||
}
|
||||
}
|
||||
if (params.containsKey("timode")) {
|
||||
rc.turnInstructionMode = params.getInt("timode");
|
||||
}
|
||||
|
||||
if (params.containsKey("direction")) {
|
||||
rc.startDirection = params.getInt("direction");
|
||||
}
|
||||
if (params.containsKey("heading")) {
|
||||
rc.startDirection = params.getInt("heading");
|
||||
rc.forceUseStartDirection = true;
|
||||
}
|
||||
if (params.containsKey("alternativeidx")) {
|
||||
rc.alternativeIdx = params.getInt("alternativeidx");
|
||||
}
|
||||
|
||||
readNogos(params); // add interface provided nogos
|
||||
if (nogoList != null) {
|
||||
RoutingContext.prepareNogoPoints(nogoList);
|
||||
if (rc.nogopoints == null) {
|
||||
rc.nogopoints = nogoList;
|
||||
} else {
|
||||
rc.nogopoints.addAll(nogoList);
|
||||
}
|
||||
}
|
||||
if (rc.nogopoints == null) {
|
||||
rc.nogopoints = nogoPolygonsList;
|
||||
} else if (nogoPolygonsList != null) {
|
||||
rc.nogopoints.addAll(nogoPolygonsList);
|
||||
}
|
||||
List<OsmNodeNamed> poisList = readPoisList(params);
|
||||
rc.poipoints = poisList;
|
||||
|
||||
if (params.containsKey("lats")) {
|
||||
waypoints = readPositions(params);
|
||||
}
|
||||
if (params.containsKey("lonlats")) {
|
||||
waypoints = readLonlats(params, engineMode);
|
||||
}
|
||||
|
||||
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.parseInt(sa[i]);
|
||||
if (waypoints.size() > v) waypoints.get(v).direct = true;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
|
||||
String extraParams = null;
|
||||
if (params.containsKey("extraParams")) { // add user params
|
||||
extraParams = params.getString("extraParams");
|
||||
}
|
||||
if (extraParams != null && this.profileParams != null) {
|
||||
// don't overwrite incoming values
|
||||
extraParams = this.profileParams + "&" + extraParams;
|
||||
} else if (this.profileParams != null) {
|
||||
extraParams = this.profileParams;
|
||||
}
|
||||
|
||||
if (params.containsKey("extraParams")) { // add user params
|
||||
if (rc.keyValues == null) rc.keyValues = new HashMap<>();
|
||||
StringTokenizer tk = new StringTokenizer(extraParams, "?&");
|
||||
while (tk.hasMoreTokens()) {
|
||||
String t = tk.nextToken();
|
||||
StringTokenizer tk2 = new StringTokenizer(t, "=");
|
||||
if (tk2.hasMoreTokens()) {
|
||||
String key = tk2.nextToken();
|
||||
if (tk2.hasMoreTokens()) {
|
||||
String value = tk2.nextToken();
|
||||
rc.keyValues.put(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
writeTimeoutData(rc);
|
||||
|
@ -170,18 +146,15 @@ public class BRouterWorker {
|
|||
return cr.getErrorMessage();
|
||||
}
|
||||
|
||||
String format = params.getString("trackFormat");
|
||||
int writeFromat = OUTPUT_FORMAT_GPX;
|
||||
if (format != null) {
|
||||
if ("kml".equals(format)) writeFromat = OUTPUT_FORMAT_KML;
|
||||
if ("json".equals(format)) writeFromat = OUTPUT_FORMAT_JSON;
|
||||
if (rc.outputFormat != null) {
|
||||
if ("kml".equals(rc.outputFormat)) writeFromat = OUTPUT_FORMAT_KML;
|
||||
if ("json".equals(rc.outputFormat)) writeFromat = OUTPUT_FORMAT_JSON;
|
||||
}
|
||||
|
||||
OsmTrack track = cr.getFoundTrack();
|
||||
if (track != null) {
|
||||
if (params.containsKey("exportWaypoints")) {
|
||||
track.exportWaypoints = (params.getInt("exportWaypoints", 0) == 1);
|
||||
}
|
||||
track.exportWaypoints = rc.exportWaypoints;
|
||||
if (pathToFileResult == null) {
|
||||
switch (writeFromat) {
|
||||
case OUTPUT_FORMAT_GPX:
|
||||
|
@ -223,204 +196,6 @@ public class BRouterWorker {
|
|||
return null;
|
||||
}
|
||||
|
||||
private List<OsmNodeNamed> readPositions(Bundle params) {
|
||||
List<OsmNodeNamed> wplist = new ArrayList<>();
|
||||
|
||||
double[] lats = params.getDoubleArray("lats");
|
||||
double[] lons = params.getDoubleArray("lons");
|
||||
|
||||
if (lats == null || lats.length < 2 || lons == null || lons.length < 2) {
|
||||
throw new IllegalArgumentException("we need two lat/lon points at least!");
|
||||
}
|
||||
|
||||
for (int i = 0; i < lats.length && i < lons.length; i++) {
|
||||
OsmNodeNamed n = new OsmNodeNamed();
|
||||
n.name = "via" + i;
|
||||
n.ilon = (int) ((lons[i] + 180.) * 1000000. + 0.5);
|
||||
n.ilat = (int) ((lats[i] + 90.) * 1000000. + 0.5);
|
||||
wplist.add(n);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
private List<OsmNodeNamed> readLonlats(Bundle params, int mode) {
|
||||
List<OsmNodeNamed> wplist = new ArrayList<>();
|
||||
|
||||
String lonLats = params.getString("lonlats");
|
||||
if (lonLats == null) throw new IllegalArgumentException("lonlats parameter not set");
|
||||
|
||||
String[] coords;
|
||||
if (mode == 0) {
|
||||
coords = lonLats.split("\\|");
|
||||
if (coords.length < 2)
|
||||
throw new IllegalArgumentException("we need two lat/lon points at least!");
|
||||
} else {
|
||||
coords = new String[1];
|
||||
coords[0] = lonLats;
|
||||
}
|
||||
for (int i = 0; i < coords.length; i++) {
|
||||
String[] lonLat = coords[i].split(",");
|
||||
if (lonLat.length < 2)
|
||||
throw new IllegalArgumentException("we need a lat and lon point at least!");
|
||||
wplist.add(readPosition(lonLat[0], lonLat[1], "via" + i));
|
||||
if (lonLat.length > 2) {
|
||||
if (lonLat[2].equals("d")) {
|
||||
wplist.get(wplist.size() - 1).direct = true;
|
||||
} else {
|
||||
wplist.get(wplist.size() - 1).name = lonLat[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private static OsmNodeNamed readPosition(String vlon, String vlat, String name) {
|
||||
if (vlon == null) throw new IllegalArgumentException("lon " + name + " not found in input");
|
||||
if (vlat == null) throw new IllegalArgumentException("lat " + name + " not found in input");
|
||||
|
||||
return readPosition(Double.parseDouble(vlon), Double.parseDouble(vlat), name);
|
||||
}
|
||||
|
||||
private static OsmNodeNamed readPosition(double lon, double lat, String name) {
|
||||
OsmNodeNamed n = new OsmNodeNamed();
|
||||
n.name = name;
|
||||
n.ilon = (int) ((lon + 180.) * 1000000. + 0.5);
|
||||
n.ilat = (int) ((lat + 90.) * 1000000. + 0.5);
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
private void readNogos(Bundle params) {
|
||||
if (params.containsKey("nogoLats")) {
|
||||
double[] lats = params.getDoubleArray("nogoLats");
|
||||
double[] lons = params.getDoubleArray("nogoLons");
|
||||
double[] radi = params.getDoubleArray("nogoRadi");
|
||||
|
||||
if (lats == null || lons == null || radi == null) return;
|
||||
|
||||
for (int i = 0; i < lats.length && i < lons.length && i < radi.length; i++) {
|
||||
OsmNodeNamed n = new OsmNodeNamed();
|
||||
n.name = "nogo" + (int) radi[i];
|
||||
n.ilon = (int) ((lons[i] + 180.) * 1000000. + 0.5);
|
||||
n.ilat = (int) ((lats[i] + 90.) * 1000000. + 0.5);
|
||||
n.isNogo = true;
|
||||
n.nogoWeight = Double.NaN;
|
||||
AppLogger.log("added interface provided nogo: " + n);
|
||||
nogoList.add(n);
|
||||
}
|
||||
}
|
||||
if (params.containsKey("nogos")) {
|
||||
nogoList = readNogoList(params);
|
||||
}
|
||||
if (params.containsKey("polylines") ||
|
||||
params.containsKey("polygons")) {
|
||||
nogoPolygonsList = readNogoPolygons(params);
|
||||
}
|
||||
}
|
||||
|
||||
private List<OsmNodeNamed> readNogoList(Bundle params) {
|
||||
// lon,lat,radius|...
|
||||
String nogos = params.getString("nogos");
|
||||
if (nogos == null) return null;
|
||||
|
||||
String[] lonLatRadList = nogos.split("\\|");
|
||||
|
||||
List<OsmNodeNamed> nogoList = new ArrayList<>();
|
||||
for (int i = 0; i < lonLatRadList.length; i++) {
|
||||
String[] lonLatRad = lonLatRadList[i].split(",");
|
||||
String nogoWeight = "NaN";
|
||||
if (lonLatRad.length > 3) {
|
||||
nogoWeight = lonLatRad[3];
|
||||
}
|
||||
nogoList.add(readNogo(lonLatRad[0], lonLatRad[1], lonLatRad[2], nogoWeight));
|
||||
}
|
||||
|
||||
return nogoList;
|
||||
}
|
||||
|
||||
private static OsmNodeNamed readNogo(String lon, String lat, String radius, String nogoWeight) {
|
||||
double weight = "undefined".equals(nogoWeight) ? Double.NaN : Double.parseDouble(nogoWeight);
|
||||
return readNogo(Double.parseDouble(lon), Double.parseDouble(lat), Integer.parseInt(radius), weight);
|
||||
}
|
||||
|
||||
private static OsmNodeNamed readNogo(double lon, double lat, int radius, double nogoWeight) {
|
||||
OsmNodeNamed n = new OsmNodeNamed();
|
||||
n.name = "nogo" + radius;
|
||||
n.ilon = (int) ((lon + 180.) * 1000000. + 0.5);
|
||||
n.ilat = (int) ((lat + 90.) * 1000000. + 0.5);
|
||||
n.isNogo = true;
|
||||
n.nogoWeight = nogoWeight;
|
||||
return n;
|
||||
}
|
||||
|
||||
private List<OsmNodeNamed> readNogoPolygons(Bundle params) {
|
||||
List<OsmNodeNamed> result = new ArrayList<>();
|
||||
parseNogoPolygons(params.getString("polylines"), result, false);
|
||||
parseNogoPolygons(params.getString("polygons"), result, true);
|
||||
return result.size() > 0 ? result : null;
|
||||
}
|
||||
|
||||
private static void parseNogoPolygons(String polygons, List<OsmNodeNamed> result, boolean closed) {
|
||||
if (polygons != null) {
|
||||
String[] polygonList = polygons.split("\\|");
|
||||
for (int i = 0; i < polygonList.length; i++) {
|
||||
String[] lonLatList = polygonList[i].split(",");
|
||||
if (lonLatList.length > 1) {
|
||||
OsmNogoPolygon polygon = new OsmNogoPolygon(closed);
|
||||
polygon.name = "nogo" + i;
|
||||
int j;
|
||||
for (j = 0; j < 2 * (lonLatList.length / 2) - 1; ) {
|
||||
String slon = lonLatList[j++];
|
||||
String slat = lonLatList[j++];
|
||||
int lon = (int) ((Double.parseDouble(slon) + 180.) * 1000000. + 0.5);
|
||||
int lat = (int) ((Double.parseDouble(slat) + 90.) * 1000000. + 0.5);
|
||||
polygon.addVertex(lon, lat);
|
||||
}
|
||||
|
||||
String nogoWeight = "NaN";
|
||||
if (j < lonLatList.length) {
|
||||
nogoWeight = lonLatList[j];
|
||||
}
|
||||
polygon.nogoWeight = Double.parseDouble(nogoWeight);
|
||||
|
||||
if (polygon.points.size() > 0) {
|
||||
polygon.calcBoundingCircle();
|
||||
result.add(polygon);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<OsmNodeNamed> readPoisList(Bundle params) {
|
||||
// lon,lat,name|...
|
||||
String pois = params.getString("pois");
|
||||
if (pois == null) return null;
|
||||
|
||||
String[] lonLatNameList = pois.split("\\|");
|
||||
|
||||
List<OsmNodeNamed> poisList = new ArrayList<>();
|
||||
for (int i = 0; i < lonLatNameList.length; i++) {
|
||||
String[] lonLatName = lonLatNameList[i].split(",");
|
||||
|
||||
OsmNodeNamed n = new OsmNodeNamed();
|
||||
n.ilon = (int) ((Double.parseDouble(lonLatName[0]) + 180.) * 1000000. + 0.5);
|
||||
n.ilat = (int) ((Double.parseDouble(lonLatName[1]) + 90.) * 1000000. + 0.5);
|
||||
n.name = lonLatName[2];
|
||||
poisList.add(n);
|
||||
}
|
||||
|
||||
return poisList;
|
||||
}
|
||||
|
||||
private void writeTimeoutData(RoutingContext rc) throws Exception {
|
||||
String timeoutFile = baseDir + "/brouter/modes/timeoutdata.txt";
|
||||
|
@ -431,7 +206,7 @@ public class BRouterWorker {
|
|||
bw.write(rc.rawTrackPath);
|
||||
bw.write("\n");
|
||||
writeWPList(bw, waypoints);
|
||||
writeWPList(bw, nogoList);
|
||||
writeWPList(bw, rc.nogopoints);
|
||||
bw.close();
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ import btools.router.OsmTrack;
|
|||
import btools.router.ProfileCache;
|
||||
import btools.router.RoutingContext;
|
||||
import btools.router.RoutingEngine;
|
||||
import btools.router.RoutingParamCollector;
|
||||
import btools.server.request.ProfileUploadHandler;
|
||||
import btools.server.request.RequestHandler;
|
||||
import btools.server.request.ServerHandler;
|
||||
|
@ -146,7 +147,9 @@ public class RouteServer extends Thread implements Comparable<RouteServer> {
|
|||
}
|
||||
|
||||
String url = getline.split(" ")[1];
|
||||
Map<String, String> params = getUrlParams(url);
|
||||
|
||||
RoutingParamCollector routingParamCollector = new RoutingParamCollector();
|
||||
Map<String, String> params = routingParamCollector.getUrlParams(url);
|
||||
|
||||
long maxRunningTime = getMaxRunningTime();
|
||||
|
||||
|
@ -186,33 +189,17 @@ public class RouteServer extends Thread implements Comparable<RouteServer> {
|
|||
return;
|
||||
}
|
||||
RoutingContext rc = handler.readRoutingContext();
|
||||
List<OsmNodeNamed> wplist = handler.readWayPointList();
|
||||
List<OsmNodeNamed> wplist = routingParamCollector.getWayPointList(params.get("lonlats"));
|
||||
|
||||
if (wplist.size() < 10) {
|
||||
SuspectManager.nearRecentWps.add(wplist);
|
||||
}
|
||||
int engineMode = 0;
|
||||
for (Map.Entry<String, String> e : params.entrySet()) {
|
||||
if ("engineMode".equals(e.getKey())) {
|
||||
engineMode = Integer.parseInt(e.getValue());
|
||||
} else if ("timode".equals(e.getKey())) {
|
||||
rc.turnInstructionMode = Integer.parseInt(e.getValue());
|
||||
} else if ("heading".equals(e.getKey())) {
|
||||
rc.startDirection = Integer.parseInt(e.getValue());
|
||||
rc.forceUseStartDirection = true;
|
||||
} else if (e.getKey().startsWith("profile:")) {
|
||||
if (rc.keyValues == null) {
|
||||
rc.keyValues = new HashMap<>();
|
||||
}
|
||||
rc.keyValues.put(e.getKey().substring(8), e.getValue());
|
||||
} else if (e.getKey().equals("straight")) {
|
||||
String[] sa = e.getValue().split(",");
|
||||
for (int i = 0; i < sa.length; i++) {
|
||||
int v = Integer.parseInt(sa[i]);
|
||||
if (wplist.size() > v) wplist.get(v).direct = true;
|
||||
}
|
||||
}
|
||||
if (params.containsKey("engineMode")) {
|
||||
engineMode = Integer.parseInt(params.get("engineMode"));
|
||||
}
|
||||
routingParamCollector.setParams(rc, wplist, params);
|
||||
|
||||
cr = new RoutingEngine(null, null, serviceContext.segmentDir, wplist, rc, engineMode);
|
||||
cr.quite = true;
|
||||
cr.doRun(maxRunningTime);
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package btools.server.request;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import btools.router.OsmNodeNamed;
|
||||
import btools.router.OsmTrack;
|
||||
import btools.router.RoutingContext;
|
||||
import btools.server.ServiceContext;
|
||||
|
@ -19,8 +17,6 @@ public abstract class RequestHandler {
|
|||
|
||||
public abstract RoutingContext readRoutingContext();
|
||||
|
||||
public abstract List<OsmNodeNamed> readWayPointList();
|
||||
|
||||
public abstract String formatTrack(OsmTrack track);
|
||||
|
||||
public abstract String getMimeType();
|
||||
|
|
|
@ -3,12 +3,8 @@ package btools.server.request;
|
|||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import btools.router.OsmNodeNamed;
|
||||
import btools.router.OsmNogoPolygon;
|
||||
import btools.router.OsmTrack;
|
||||
import btools.router.RoutingContext;
|
||||
import btools.server.ServiceContext;
|
||||
|
@ -62,59 +58,9 @@ public class ServerHandler extends RequestHandler {
|
|||
}
|
||||
rc.localFunction = profile;
|
||||
|
||||
rc.setAlternativeIdx(Integer.parseInt(params.get("alternativeidx")));
|
||||
|
||||
List<OsmNodeNamed> poisList = readPoisList();
|
||||
rc.poipoints = poisList;
|
||||
|
||||
List<OsmNodeNamed> nogoList = readNogoList();
|
||||
List<OsmNodeNamed> nogoPolygonsList = readNogoPolygons();
|
||||
|
||||
if (nogoList != null) {
|
||||
RoutingContext.prepareNogoPoints(nogoList);
|
||||
rc.nogopoints = nogoList;
|
||||
}
|
||||
|
||||
if (rc.nogopoints == null) {
|
||||
rc.nogopoints = nogoPolygonsList;
|
||||
} else if (nogoPolygonsList != null) {
|
||||
rc.nogopoints.addAll(nogoPolygonsList);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OsmNodeNamed> readWayPointList() {
|
||||
// lon,lat|...
|
||||
String lonLats = params.get("lonlats");
|
||||
if (lonLats == null) throw new IllegalArgumentException("lonlats parameter not set");
|
||||
|
||||
String[] coords = lonLats.split("\\|");
|
||||
if (coords.length < 2)
|
||||
throw new IllegalArgumentException("we need two lat/lon points at least!");
|
||||
|
||||
List<OsmNodeNamed> wplist = new ArrayList<>();
|
||||
for (int i = 0; i < coords.length; i++) {
|
||||
String[] lonLat = coords[i].split(",");
|
||||
if (lonLat.length < 2)
|
||||
throw new IllegalArgumentException("we need two lat/lon points at least!");
|
||||
wplist.add(readPosition(lonLat[0], lonLat[1], "via" + i));
|
||||
if (lonLat.length > 2) {
|
||||
if (lonLat[2].equals("d")) {
|
||||
wplist.get(wplist.size()-1).direct = true;
|
||||
} else {
|
||||
wplist.get(wplist.size()-1).name = lonLat[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatTrack(OsmTrack track) {
|
||||
String result;
|
||||
|
@ -191,115 +137,4 @@ public class ServerHandler extends RequestHandler {
|
|||
return params.get("trackname") == null ? null : params.get("trackname").replaceAll("[^a-zA-Z0-9 \\._\\-]+", "");
|
||||
}
|
||||
|
||||
private static OsmNodeNamed readPosition(String vlon, String vlat, String name) {
|
||||
if (vlon == null) throw new IllegalArgumentException("lon " + name + " not found in input");
|
||||
if (vlat == null) throw new IllegalArgumentException("lat " + name + " not found in input");
|
||||
|
||||
return readPosition(Double.parseDouble(vlon), Double.parseDouble(vlat), name);
|
||||
}
|
||||
|
||||
private static OsmNodeNamed readPosition(double lon, double lat, String name) {
|
||||
OsmNodeNamed n = new OsmNodeNamed();
|
||||
n.name = name;
|
||||
n.ilon = (int) ((lon + 180.) * 1000000. + 0.5);
|
||||
n.ilat = (int) ((lat + 90.) * 1000000. + 0.5);
|
||||
return n;
|
||||
}
|
||||
|
||||
private List<OsmNodeNamed> readPoisList() {
|
||||
// lon,lat,name|...
|
||||
String pois = params.get("pois");
|
||||
if (pois == null) return null;
|
||||
|
||||
String[] lonLatNameList = pois.split("\\|");
|
||||
|
||||
List<OsmNodeNamed> poisList = new ArrayList<>();
|
||||
for (int i = 0; i < lonLatNameList.length; i++) {
|
||||
String[] lonLatName = lonLatNameList[i].split(",");
|
||||
|
||||
if (lonLatName.length != 3)
|
||||
continue;
|
||||
|
||||
OsmNodeNamed n = new OsmNodeNamed();
|
||||
n.ilon = (int) ((Double.parseDouble(lonLatName[0]) + 180.) * 1000000. + 0.5);
|
||||
n.ilat = (int) ((Double.parseDouble(lonLatName[1]) + 90.) * 1000000. + 0.5);
|
||||
n.name = lonLatName[2];
|
||||
poisList.add(n);
|
||||
}
|
||||
|
||||
return poisList;
|
||||
}
|
||||
|
||||
private List<OsmNodeNamed> readNogoList() {
|
||||
// lon,lat,radius|...
|
||||
String nogos = params.get("nogos");
|
||||
if (nogos == null) return null;
|
||||
|
||||
String[] lonLatRadList = nogos.split("\\|");
|
||||
|
||||
List<OsmNodeNamed> nogoList = new ArrayList<>();
|
||||
for (int i = 0; i < lonLatRadList.length; i++) {
|
||||
String[] lonLatRad = lonLatRadList[i].split(",");
|
||||
String nogoWeight = "NaN";
|
||||
if (lonLatRad.length > 3) {
|
||||
nogoWeight = lonLatRad[3];
|
||||
}
|
||||
nogoList.add(readNogo(lonLatRad[0], lonLatRad[1], lonLatRad[2], nogoWeight));
|
||||
}
|
||||
|
||||
return nogoList;
|
||||
}
|
||||
|
||||
private static OsmNodeNamed readNogo(String lon, String lat, String radius, String nogoWeight) {
|
||||
double weight = "undefined".equals(nogoWeight) ? Double.NaN : Double.parseDouble(nogoWeight);
|
||||
return readNogo(Double.parseDouble(lon), Double.parseDouble(lat), Integer.parseInt(radius), weight);
|
||||
}
|
||||
|
||||
private static OsmNodeNamed readNogo(double lon, double lat, int radius, double nogoWeight) {
|
||||
OsmNodeNamed n = new OsmNodeNamed();
|
||||
n.name = "nogo" + radius;
|
||||
n.ilon = (int) ((lon + 180.) * 1000000. + 0.5);
|
||||
n.ilat = (int) ((lat + 90.) * 1000000. + 0.5);
|
||||
n.isNogo = true;
|
||||
n.nogoWeight = nogoWeight;
|
||||
return n;
|
||||
}
|
||||
|
||||
private List<OsmNodeNamed> readNogoPolygons() {
|
||||
List<OsmNodeNamed> result = new ArrayList<>();
|
||||
parseNogoPolygons(params.get("polylines"), result, false);
|
||||
parseNogoPolygons(params.get("polygons"), result, true);
|
||||
return result.size() > 0 ? result : null;
|
||||
}
|
||||
|
||||
private static void parseNogoPolygons(String polygons, List<OsmNodeNamed> result, boolean closed) {
|
||||
if (polygons != null) {
|
||||
String[] polygonList = polygons.split("\\|");
|
||||
for (int i = 0; i < polygonList.length; i++) {
|
||||
String[] lonLatList = polygonList[i].split(",");
|
||||
if (lonLatList.length > 1) {
|
||||
OsmNogoPolygon polygon = new OsmNogoPolygon(closed);
|
||||
int j;
|
||||
for (j = 0; j < 2 * (lonLatList.length / 2) - 1; ) {
|
||||
String slon = lonLatList[j++];
|
||||
String slat = lonLatList[j++];
|
||||
int lon = (int) ((Double.parseDouble(slon) + 180.) * 1000000. + 0.5);
|
||||
int lat = (int) ((Double.parseDouble(slat) + 90.) * 1000000. + 0.5);
|
||||
polygon.addVertex(lon, lat);
|
||||
}
|
||||
|
||||
String nogoWeight = "NaN";
|
||||
if (j < lonLatList.length) {
|
||||
nogoWeight = lonLatList[j];
|
||||
}
|
||||
polygon.nogoWeight = Double.parseDouble(nogoWeight);
|
||||
|
||||
if (polygon.points.size() > 0) {
|
||||
polygon.calcBoundingCircle();
|
||||
result.add(polygon);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue