reworked command line start
This commit is contained in:
parent
3b650a51c2
commit
5ed5259912
2 changed files with 87 additions and 54 deletions
|
@ -158,16 +158,21 @@ public class RoutingEngine extends Thread {
|
||||||
|
|
||||||
switch (engineMode) {
|
switch (engineMode) {
|
||||||
case BROUTER_ENGINEMODE_ROUTING:
|
case BROUTER_ENGINEMODE_ROUTING:
|
||||||
|
if (waypoints.size() < 2) {
|
||||||
|
throw new IllegalArgumentException("we need two lat/lon points at least!");
|
||||||
|
}
|
||||||
doRouting(maxRunningTime);
|
doRouting(maxRunningTime);
|
||||||
break;
|
break;
|
||||||
case BROUTER_ENGINEMODE_SEED: /* do nothing, handled the old way */
|
case BROUTER_ENGINEMODE_SEED: /* do nothing, handled the old way */
|
||||||
break;
|
throw new IllegalArgumentException("not a valid engine mode");
|
||||||
case BROUTER_ENGINEMODE_GETELEV:
|
case BROUTER_ENGINEMODE_GETELEV:
|
||||||
|
if (waypoints.size() < 1) {
|
||||||
|
throw new IllegalArgumentException("we need one lat/lon point at least!");
|
||||||
|
}
|
||||||
doGetElev();
|
doGetElev();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
doRouting(maxRunningTime);
|
throw new IllegalArgumentException("not a valid engine mode");
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,6 +206,9 @@ public class RoutingEngine extends Thread {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
oldTrack = null;
|
oldTrack = null;
|
||||||
|
track.exportWaypoints = routingContext.exportWaypoints;
|
||||||
|
// doesn't work at the moment
|
||||||
|
// use routingContext.outputFormat
|
||||||
track.writeGpx(filename);
|
track.writeGpx(filename);
|
||||||
foundTrack = track;
|
foundTrack = track;
|
||||||
alternativeIndex = i;
|
alternativeIndex = i;
|
||||||
|
@ -300,8 +308,16 @@ public class RoutingEngine extends Thread {
|
||||||
OsmNodeNamed n = new OsmNodeNamed(listOne.get(0).crosspoint);
|
OsmNodeNamed n = new OsmNodeNamed(listOne.get(0).crosspoint);
|
||||||
n.selev = startNode != null ? startNode.getSElev() : Short.MIN_VALUE;
|
n.selev = startNode != null ? startNode.getSElev() : Short.MIN_VALUE;
|
||||||
|
|
||||||
|
// doesn't work at the moment
|
||||||
|
// use routingContext.outputFormat
|
||||||
outputMessage = OsmTrack.formatAsGpxWaypoint(n);
|
outputMessage = OsmTrack.formatAsGpxWaypoint(n);
|
||||||
|
if (outfileBase != null) {
|
||||||
|
String filename = outfileBase + ".gpx";
|
||||||
|
File out = new File(filename);
|
||||||
|
FileWriter fw = new FileWriter(filename);
|
||||||
|
fw.write(outputMessage);
|
||||||
|
fw.close();
|
||||||
|
}
|
||||||
long endTime = System.currentTimeMillis();
|
long endTime = System.currentTimeMillis();
|
||||||
logInfo("execution time = " + (endTime - startTime) / 1000. + " seconds");
|
logInfo("execution time = " + (endTime - startTime) / 1000. + " seconds");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -2,72 +2,55 @@ package btools.server;
|
||||||
|
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.io.File;
|
import java.util.Map;
|
||||||
|
|
||||||
import btools.router.OsmNodeNamed;
|
import btools.router.OsmNodeNamed;
|
||||||
import btools.router.OsmTrack;
|
import btools.router.OsmTrack;
|
||||||
import btools.router.RoutingContext;
|
import btools.router.RoutingContext;
|
||||||
import btools.router.RoutingEngine;
|
import btools.router.RoutingEngine;
|
||||||
|
import btools.router.RoutingParamCollector;
|
||||||
import btools.router.SearchBoundary;
|
import btools.router.SearchBoundary;
|
||||||
|
|
||||||
public class BRouter {
|
public class BRouter {
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
if (args.length == 2) { // cgi-input-mode
|
if (args.length == 3) { // cgi-input-mode
|
||||||
try {
|
try {
|
||||||
String queryString = args[1];
|
System.setProperty("segmentBaseDir", args[0]);
|
||||||
int sepIdx = queryString.indexOf('=');
|
System.setProperty("profileBaseDir", args[1]);
|
||||||
if (sepIdx >= 0) queryString = queryString.substring(sepIdx + 1);
|
String queryString = args[2];
|
||||||
|
|
||||||
queryString = URLDecoder.decode(queryString, "ISO-8859-1");
|
queryString = URLDecoder.decode(queryString, "ISO-8859-1");
|
||||||
int ntokens = 1;
|
|
||||||
for (int ic = 0; ic < queryString.length(); ic++) {
|
int lonIdx = queryString.indexOf("lonlats=");
|
||||||
if (queryString.charAt(ic) == '_') ntokens++;
|
int sepIdx = queryString.indexOf("&", lonIdx);
|
||||||
}
|
String lonlats = queryString.substring(lonIdx+8, sepIdx);
|
||||||
String[] a2 = new String[ntokens + 1];
|
|
||||||
int idx = 1;
|
RoutingContext rc = new RoutingContext();
|
||||||
int pos = 0;
|
RoutingParamCollector routingParamCollector = new RoutingParamCollector();
|
||||||
for (; ; ) {
|
List<OsmNodeNamed> wplist = routingParamCollector.getWayPointList(lonlats);
|
||||||
int p = queryString.indexOf('_', pos);
|
|
||||||
if (p < 0) {
|
Map<String, String> params = routingParamCollector.getUrlParams(queryString);
|
||||||
a2[idx++] = queryString.substring(pos);
|
routingParamCollector.setParams(rc, wplist, params);
|
||||||
break;
|
|
||||||
}
|
|
||||||
a2[idx++] = queryString.substring(pos, p);
|
|
||||||
pos = p + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// cgi-header
|
// cgi-header
|
||||||
System.out.println("Content-type: text/plain");
|
System.out.println("Content-type: text/plain");
|
||||||
System.out.println();
|
System.out.println();
|
||||||
OsmNodeNamed from = readPosition(a2, 1, "from");
|
|
||||||
OsmNodeNamed to = readPosition(a2, 3, "to");
|
|
||||||
|
|
||||||
|
|
||||||
int airDistance = from.calcDistance(to);
|
|
||||||
|
|
||||||
String airDistanceLimit = System.getProperty("airDistanceLimit");
|
|
||||||
if (airDistanceLimit != null) {
|
|
||||||
int maxKm = Integer.parseInt(airDistanceLimit);
|
|
||||||
if (airDistance > maxKm * 1000) {
|
|
||||||
System.out.println("airDistance " + (airDistance / 1000) + "km exceeds limit for online router (" + maxKm + "km)");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
long maxRunningTime = 60000; // the cgi gets a 1 Minute timeout
|
long maxRunningTime = 60000; // the cgi gets a 1 Minute timeout
|
||||||
String sMaxRunningTime = System.getProperty("maxRunningTime");
|
String sMaxRunningTime = System.getProperty("maxRunningTime");
|
||||||
if (sMaxRunningTime != null) {
|
if (sMaxRunningTime != null) {
|
||||||
maxRunningTime = Integer.parseInt(sMaxRunningTime) * 1000;
|
maxRunningTime = Integer.parseInt(sMaxRunningTime) * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<OsmNodeNamed> wplist = new ArrayList<>();
|
|
||||||
wplist.add(from);
|
|
||||||
wplist.add(to);
|
|
||||||
|
|
||||||
RoutingEngine re = new RoutingEngine(null, null, new File(args[0]), wplist, readRoutingContext(a2));
|
RoutingEngine re = new RoutingEngine(null, null, new File(args[0]), wplist, rc);
|
||||||
|
|
||||||
re.doRun(maxRunningTime);
|
re.doRun(maxRunningTime);
|
||||||
if (re.getErrorMessage() != null) {
|
if (re.getErrorMessage() != null) {
|
||||||
System.out.println(re.getErrorMessage());
|
System.out.println(re.getErrorMessage());
|
||||||
|
@ -78,15 +61,17 @@ public class BRouter {
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
System.out.println("BRouter " + OsmTrack.version + " / " + OsmTrack.versionDate);
|
System.out.println("BRouter " + OsmTrack.version + " / " + OsmTrack.versionDate);
|
||||||
if (args.length < 6) {
|
if (args.length < 5) {
|
||||||
System.out.println("Find routes in an OSM map");
|
System.out.println("Find routes in an OSM map");
|
||||||
System.out.println("usage: java -jar brouter.jar <segmentdir> <lon-from> <lat-from> <lon-to> <lat-to> <profile>");
|
System.out.println("usage: java -jar brouter.jar <segmentdir> <profiledir> <engineMode> <profile> <lonlats-list> [parameter-list] [profile-parameter-list] ");
|
||||||
return;
|
System.out.println(" or: java -cp %CLASSPATH% btools.server.BRouter <segmentdir>> <profiledir> <engineMode> <profile> <lonlats-list> [parameter-list] [profile-parameter-list]");
|
||||||
|
System.out.println(" or: java -jar brouter.jar <segmentdir> <profiledir> <parameter-list> ");
|
||||||
|
System.exit(0);
|
||||||
}
|
}
|
||||||
List<OsmNodeNamed> wplist = new ArrayList<>();
|
|
||||||
wplist.add(readPosition(args, 1, "from"));
|
|
||||||
RoutingEngine re = null;
|
RoutingEngine re = null;
|
||||||
if ("seed".equals(args[3])) {
|
if ("seed".equals(args[3])) {
|
||||||
|
List<OsmNodeNamed> wplist = new ArrayList<>();
|
||||||
|
wplist.add(readPosition(args, 1, "from"));
|
||||||
int searchRadius = Integer.parseInt(args[4]); // if = 0 search a 5x5 square
|
int searchRadius = Integer.parseInt(args[4]); // if = 0 search a 5x5 square
|
||||||
|
|
||||||
String filename = SearchBoundary.getFileName(wplist.get(0));
|
String filename = SearchBoundary.getFileName(wplist.get(0));
|
||||||
|
@ -108,14 +93,46 @@ public class BRouter {
|
||||||
}
|
}
|
||||||
dos.close();
|
dos.close();
|
||||||
} else {
|
} else {
|
||||||
wplist.add(readPosition(args, 3, "to"));
|
int engineMode = 0;
|
||||||
RoutingContext rc = readRoutingContext(args);
|
try {
|
||||||
re = new RoutingEngine("mytrack", "mylog", new File(args[0]), wplist, rc);
|
engineMode = Integer.parseInt(args[2]);
|
||||||
re.doRun(0);
|
} catch (NumberFormatException e) {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
RoutingParamCollector routingParamCollector = new RoutingParamCollector();
|
||||||
if (re.getErrorMessage() != null) {
|
List<OsmNodeNamed> wplist = routingParamCollector.getWayPointList(args[4]);
|
||||||
System.out.println(re.getErrorMessage());
|
|
||||||
|
System.setProperty("segmentBaseDir", args[0]);
|
||||||
|
System.setProperty("profileBaseDir", args[1]);
|
||||||
|
String moreParams = null;
|
||||||
|
String profileParams = null;
|
||||||
|
if (args.length >= 6) {
|
||||||
|
moreParams = args[5];
|
||||||
|
}
|
||||||
|
if (args.length == 7) {
|
||||||
|
profileParams = args[6];
|
||||||
|
}
|
||||||
|
|
||||||
|
RoutingContext rc = new RoutingContext();
|
||||||
|
rc.localFunction = args[3];
|
||||||
|
if (moreParams != null) {
|
||||||
|
Map<String, String> params = routingParamCollector.getUrlParams(moreParams);
|
||||||
|
routingParamCollector.setParams(rc, wplist, params);
|
||||||
|
}
|
||||||
|
if (profileParams != null) {
|
||||||
|
Map<String, String> params = routingParamCollector.getUrlParams(profileParams);
|
||||||
|
routingParamCollector.setProfileParams(rc, params);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (engineMode==RoutingEngine.BROUTER_ENGINEMODE_GETELEV) {
|
||||||
|
re = new RoutingEngine("testinfo", null, new File(args[0]), wplist, rc, engineMode);
|
||||||
|
} else {
|
||||||
|
re = new RoutingEngine("testtrack", null, new File(args[0]), wplist, rc, engineMode);
|
||||||
|
}
|
||||||
|
re.doRun(0);
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue