reworked command line start

This commit is contained in:
afischerdev 2023-08-24 10:04:08 +02:00
parent 3b650a51c2
commit 5ed5259912
2 changed files with 87 additions and 54 deletions

View file

@ -158,16 +158,21 @@ public class RoutingEngine extends Thread {
switch (engineMode) {
case BROUTER_ENGINEMODE_ROUTING:
if (waypoints.size() < 2) {
throw new IllegalArgumentException("we need two lat/lon points at least!");
}
doRouting(maxRunningTime);
break;
case BROUTER_ENGINEMODE_SEED: /* do nothing, handled the old way */
break;
throw new IllegalArgumentException("not a valid engine mode");
case BROUTER_ENGINEMODE_GETELEV:
if (waypoints.size() < 1) {
throw new IllegalArgumentException("we need one lat/lon point at least!");
}
doGetElev();
break;
default:
doRouting(maxRunningTime);
break;
throw new IllegalArgumentException("not a valid engine mode");
}
}
@ -201,6 +206,9 @@ public class RoutingEngine extends Thread {
continue;
}
oldTrack = null;
track.exportWaypoints = routingContext.exportWaypoints;
// doesn't work at the moment
// use routingContext.outputFormat
track.writeGpx(filename);
foundTrack = track;
alternativeIndex = i;
@ -300,8 +308,16 @@ public class RoutingEngine extends Thread {
OsmNodeNamed n = new OsmNodeNamed(listOne.get(0).crosspoint);
n.selev = startNode != null ? startNode.getSElev() : Short.MIN_VALUE;
// doesn't work at the moment
// use routingContext.outputFormat
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();
logInfo("execution time = " + (endTime - startTime) / 1000. + " seconds");
} catch (Exception e) {

View file

@ -2,72 +2,55 @@ package btools.server;
import java.io.BufferedOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
import java.io.File;
import java.util.Map;
import btools.router.OsmNodeNamed;
import btools.router.OsmTrack;
import btools.router.RoutingContext;
import btools.router.RoutingEngine;
import btools.router.RoutingParamCollector;
import btools.router.SearchBoundary;
public class BRouter {
public static void main(String[] args) throws Exception {
if (args.length == 2) { // cgi-input-mode
if (args.length == 3) { // cgi-input-mode
try {
String queryString = args[1];
int sepIdx = queryString.indexOf('=');
if (sepIdx >= 0) queryString = queryString.substring(sepIdx + 1);
System.setProperty("segmentBaseDir", args[0]);
System.setProperty("profileBaseDir", args[1]);
String queryString = args[2];
queryString = URLDecoder.decode(queryString, "ISO-8859-1");
int ntokens = 1;
for (int ic = 0; ic < queryString.length(); ic++) {
if (queryString.charAt(ic) == '_') ntokens++;
}
String[] a2 = new String[ntokens + 1];
int idx = 1;
int pos = 0;
for (; ; ) {
int p = queryString.indexOf('_', pos);
if (p < 0) {
a2[idx++] = queryString.substring(pos);
break;
}
a2[idx++] = queryString.substring(pos, p);
pos = p + 1;
}
int lonIdx = queryString.indexOf("lonlats=");
int sepIdx = queryString.indexOf("&", lonIdx);
String lonlats = queryString.substring(lonIdx+8, sepIdx);
RoutingContext rc = new RoutingContext();
RoutingParamCollector routingParamCollector = new RoutingParamCollector();
List<OsmNodeNamed> wplist = routingParamCollector.getWayPointList(lonlats);
Map<String, String> params = routingParamCollector.getUrlParams(queryString);
routingParamCollector.setParams(rc, wplist, params);
// cgi-header
System.out.println("Content-type: text/plain");
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
String sMaxRunningTime = System.getProperty("maxRunningTime");
if (sMaxRunningTime != null) {
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);
if (re.getErrorMessage() != null) {
System.out.println(re.getErrorMessage());
@ -78,15 +61,17 @@ public class BRouter {
System.exit(0);
}
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("usage: java -jar brouter.jar <segmentdir> <lon-from> <lat-from> <lon-to> <lat-to> <profile>");
return;
System.out.println("usage: java -jar brouter.jar <segmentdir> <profiledir> <engineMode> <profile> <lonlats-list> [parameter-list] [profile-parameter-list] ");
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;
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
String filename = SearchBoundary.getFileName(wplist.get(0));
@ -108,14 +93,46 @@ public class BRouter {
}
dos.close();
} else {
wplist.add(readPosition(args, 3, "to"));
RoutingContext rc = readRoutingContext(args);
re = new RoutingEngine("mytrack", "mylog", new File(args[0]), wplist, rc);
re.doRun(0);
int engineMode = 0;
try {
engineMode = Integer.parseInt(args[2]);
} catch (NumberFormatException e) {
}
RoutingParamCollector routingParamCollector = new RoutingParamCollector();
List<OsmNodeNamed> wplist = routingParamCollector.getWayPointList(args[4]);
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());
}
if (re.getErrorMessage() != null) {
System.out.println(re.getErrorMessage());
}
}