added write/read area info
This commit is contained in:
parent
a3c3b1e17b
commit
ddeb08c67d
@ -1,11 +1,19 @@
|
||||
package btools.router;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import btools.codec.DataBuffers;
|
||||
import btools.codec.MicroCache;
|
||||
import btools.expressions.BExpressionContextWay;
|
||||
import btools.mapaccess.MatchedWaypoint;
|
||||
import btools.mapaccess.NodesCache;
|
||||
import btools.mapaccess.OsmFile;
|
||||
import btools.mapaccess.OsmLink;
|
||||
@ -99,7 +107,8 @@ public class AreaReader {
|
||||
|
||||
// check for quadrant border
|
||||
boolean intersects = checkBorder && dataRect.intersects(searchRect.points.get(0).x, searchRect.points.get(0).y, searchRect.points.get(2).x, searchRect.points.get(2).y);
|
||||
if (!intersects && checkBorder) intersects = dataRect.intersects(searchRect.points.get(1).x, searchRect.points.get(1).y, searchRect.points.get(2).x, searchRect.points.get(3).y);
|
||||
if (!intersects && checkBorder)
|
||||
intersects = dataRect.intersects(searchRect.points.get(1).x, searchRect.points.get(1).y, searchRect.points.get(2).x, searchRect.points.get(3).y);
|
||||
if (intersects) {
|
||||
return false;
|
||||
}
|
||||
@ -159,7 +168,7 @@ public class AreaReader {
|
||||
}
|
||||
|
||||
boolean ignoreCenter(int maxscale, int idxLon, int idxLat) {
|
||||
int centerScale = (int) Math.round(maxscale * .2) -1;
|
||||
int centerScale = (int) Math.round(maxscale * .2) - 1;
|
||||
if (centerScale < 0) return false;
|
||||
if (idxLon >= -centerScale && idxLon <= centerScale &&
|
||||
idxLat >= -centerScale && idxLat <= centerScale) return true;
|
||||
@ -173,4 +182,55 @@ public class AreaReader {
|
||||
return searchRect.isWithin((long) p1x, (long) p1y) &&
|
||||
searchRect.isWithin(p2x, p2y);
|
||||
}
|
||||
|
||||
public void writeAreaInfo(String filename, MatchedWaypoint wp, List<AreaInfo> ais) throws Exception {
|
||||
DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(filename)));
|
||||
|
||||
wp.writeToStream(dos);
|
||||
for (AreaInfo ai : ais) {
|
||||
dos.writeInt(ai.direction);
|
||||
dos.writeDouble(ai.elevStart);
|
||||
dos.writeInt(ai.ways);
|
||||
dos.writeInt(ai.greenWays);
|
||||
dos.writeInt(ai.riverWays);
|
||||
dos.writeInt(ai.elev50);
|
||||
}
|
||||
dos.close();
|
||||
}
|
||||
|
||||
public void readAreaInfo(File fai, MatchedWaypoint wp, List<AreaInfo> ais) {
|
||||
DataInputStream dis = null;
|
||||
MatchedWaypoint ep = null;
|
||||
try {
|
||||
dis = new DataInputStream(new BufferedInputStream(new FileInputStream(fai)));
|
||||
ep = MatchedWaypoint.readFromStream(dis);
|
||||
if (Math.abs(ep.waypoint.ilon - wp.waypoint.ilon) > 500 &&
|
||||
Math.abs(ep.waypoint.ilat - wp.waypoint.ilat) > 500) {
|
||||
return;
|
||||
}
|
||||
if (Math.abs(ep.radius - wp.radius) > 500) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int direction = dis.readInt();
|
||||
AreaInfo ai = new AreaInfo(direction);
|
||||
ai.elevStart = dis.readDouble();
|
||||
ai.ways = dis.readInt();
|
||||
ai.greenWays = dis.readInt();
|
||||
ai.riverWays = dis.readInt();
|
||||
ai.elev50 = dis.readInt();
|
||||
ais.add(ai);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
ais.clear();
|
||||
} finally {
|
||||
if (dis != null) {
|
||||
try {
|
||||
dis.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -36,6 +36,7 @@ public final class RoutingContext {
|
||||
public Map<String, String> keyValues;
|
||||
|
||||
public String rawTrackPath;
|
||||
public String rawAreaPath;
|
||||
|
||||
public String getProfileName() {
|
||||
String name = localFunction == null ? "unknown" : localFunction;
|
||||
|
||||
@ -583,7 +583,19 @@ public class RoutingEngine extends Thread {
|
||||
|
||||
MatchedWaypoint wpt1 = new MatchedWaypoint();
|
||||
wpt1.waypoint = wp;
|
||||
wpt1.name = "start_info";
|
||||
wpt1.name = "info";
|
||||
wpt1.radius = searchRadius * 1.5;
|
||||
|
||||
List<AreaInfo> ais = new ArrayList<>();
|
||||
AreaReader areareader = new AreaReader();
|
||||
if (routingContext.rawAreaPath != null) {
|
||||
File fai = new File(routingContext.rawAreaPath);
|
||||
if (fai.exists()) {
|
||||
areareader.readAreaInfo(fai, wpt1, ais);
|
||||
}
|
||||
}
|
||||
|
||||
if (ais.isEmpty()) {
|
||||
List<MatchedWaypoint> listStart = new ArrayList<>();
|
||||
listStart.add(wpt1);
|
||||
|
||||
@ -592,7 +604,7 @@ public class RoutingEngine extends Thread {
|
||||
|
||||
List<OsmNodeNamed> listOne = new ArrayList<>();
|
||||
|
||||
for (int a = 45; a < 360; a +=90) {
|
||||
for (int a = 45; a < 360; a += 90) {
|
||||
int[] pos = CheapRuler.destination(wp.ilon, wp.ilat, searchRadius * 1.5, a);
|
||||
OsmNodeNamed onn = new OsmNodeNamed(new OsmNode(pos[0], pos[1]));
|
||||
onn.name = "via" + a;
|
||||
@ -608,7 +620,7 @@ public class RoutingEngine extends Thread {
|
||||
RoutingContext rc = new RoutingContext();
|
||||
String name = routingContext.localFunction;
|
||||
int idx = name.lastIndexOf(File.separator);
|
||||
rc.localFunction = idx == -1 ? "dummy" : name.substring(0, idx+1) + "dummy.brf";
|
||||
rc.localFunction = idx == -1 ? "dummy" : name.substring(0, idx + 1) + "dummy.brf";
|
||||
|
||||
re = new RoutingEngine(null, null, segmentDir, wpliststart, rc, BROUTER_ENGINEMODE_ROUNDTRIP);
|
||||
rc.useDynamicDistance = true;
|
||||
@ -622,12 +634,11 @@ public class RoutingEngine extends Thread {
|
||||
|
||||
double elev = (start1 == null ? 0 : start1.getElev()); // listOne.get(0).crosspoint.getElev();
|
||||
|
||||
List<AreaInfo> ais = new ArrayList<>();
|
||||
int maxlon = Integer.MIN_VALUE;
|
||||
int minlon = Integer.MAX_VALUE;
|
||||
int maxlat = Integer.MIN_VALUE;
|
||||
int minlat = Integer.MAX_VALUE;
|
||||
for (OsmNodeNamed on: listOne) {
|
||||
for (OsmNodeNamed on : listOne) {
|
||||
maxlon = Math.max(on.ilon, maxlon);
|
||||
minlon = Math.min(on.ilon, minlon);
|
||||
maxlat = Math.max(on.ilat, maxlat);
|
||||
@ -640,7 +651,7 @@ public class RoutingEngine extends Thread {
|
||||
searchRect.addVertex(minlon, maxlat);
|
||||
|
||||
for (int a = 0; a < 4; a++) {
|
||||
rc.ai = new AreaInfo(a * 90 +90);
|
||||
rc.ai = new AreaInfo(a * 90 + 90);
|
||||
rc.ai.elevStart = elev;
|
||||
rc.ai.numForest = numForest;
|
||||
rc.ai.numRiver = numRiver;
|
||||
@ -648,22 +659,33 @@ public class RoutingEngine extends Thread {
|
||||
rc.ai.polygon = new OsmNogoPolygon(true);
|
||||
rc.ai.polygon.addVertex(wp.ilon, wp.ilat);
|
||||
rc.ai.polygon.addVertex(listOne.get(a).ilon, listOne.get(a).ilat);
|
||||
if (a==3)
|
||||
if (a == 3)
|
||||
rc.ai.polygon.addVertex(listOne.get(0).ilon, listOne.get(0).ilat);
|
||||
else
|
||||
rc.ai.polygon.addVertex(listOne.get(a+1).ilon, listOne.get(a+1).ilat);
|
||||
rc.ai.polygon.addVertex(listOne.get(a + 1).ilon, listOne.get(a + 1).ilat);
|
||||
|
||||
ais.add(rc.ai);
|
||||
}
|
||||
|
||||
int maxscale = Math.abs(searchRect.points.get(2).x - searchRect.points.get(0).x);
|
||||
maxscale = Math.max(1, Math.round(maxscale/31250f/2)+1);
|
||||
maxscale = Math.max(1, Math.round(maxscale / 31250f / 2) + 1);
|
||||
|
||||
new AreaReader().getDirectAllData(segmentDir, rc, wp, maxscale, rc.expctxWay, searchRect, ais);
|
||||
areareader.getDirectAllData(segmentDir, rc, wp, maxscale, rc.expctxWay, searchRect, ais);
|
||||
|
||||
if (routingContext.rawAreaPath != null) {
|
||||
try {
|
||||
wpt1.radius = searchRadius * 1.5;
|
||||
areareader.writeAreaInfo(routingContext.rawAreaPath, wpt1, ais);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
rc.ai = null;
|
||||
|
||||
}
|
||||
|
||||
logInfo("round trip execution time = " + (System.currentTimeMillis() - start) / 1000. + " seconds");
|
||||
|
||||
//for (AreaInfo ai: ais) {
|
||||
// for (AreaInfo ai: ais) {
|
||||
// System.out.println("\n" + ai.toString());
|
||||
//}
|
||||
|
||||
@ -693,8 +715,6 @@ public class RoutingEngine extends Thread {
|
||||
return (int) (Math.random()*360);
|
||||
}
|
||||
|
||||
rc.ai = null;
|
||||
|
||||
int angle = ais.get(0).direction;
|
||||
return angle - 45 + (int) (Math.random()*90);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user