added write/read area info
This commit is contained in:
parent
a3c3b1e17b
commit
ddeb08c67d
@ -1,11 +1,19 @@
|
|||||||
package btools.router;
|
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.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import btools.codec.DataBuffers;
|
import btools.codec.DataBuffers;
|
||||||
import btools.codec.MicroCache;
|
import btools.codec.MicroCache;
|
||||||
import btools.expressions.BExpressionContextWay;
|
import btools.expressions.BExpressionContextWay;
|
||||||
|
import btools.mapaccess.MatchedWaypoint;
|
||||||
import btools.mapaccess.NodesCache;
|
import btools.mapaccess.NodesCache;
|
||||||
import btools.mapaccess.OsmFile;
|
import btools.mapaccess.OsmFile;
|
||||||
import btools.mapaccess.OsmLink;
|
import btools.mapaccess.OsmLink;
|
||||||
@ -99,7 +107,8 @@ public class AreaReader {
|
|||||||
|
|
||||||
// check for quadrant border
|
// 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);
|
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) {
|
if (intersects) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -173,4 +182,55 @@ public class AreaReader {
|
|||||||
return searchRect.isWithin((long) p1x, (long) p1y) &&
|
return searchRect.isWithin((long) p1x, (long) p1y) &&
|
||||||
searchRect.isWithin(p2x, p2y);
|
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 Map<String, String> keyValues;
|
||||||
|
|
||||||
public String rawTrackPath;
|
public String rawTrackPath;
|
||||||
|
public String rawAreaPath;
|
||||||
|
|
||||||
public String getProfileName() {
|
public String getProfileName() {
|
||||||
String name = localFunction == null ? "unknown" : localFunction;
|
String name = localFunction == null ? "unknown" : localFunction;
|
||||||
|
|||||||
@ -583,7 +583,19 @@ public class RoutingEngine extends Thread {
|
|||||||
|
|
||||||
MatchedWaypoint wpt1 = new MatchedWaypoint();
|
MatchedWaypoint wpt1 = new MatchedWaypoint();
|
||||||
wpt1.waypoint = wp;
|
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<>();
|
List<MatchedWaypoint> listStart = new ArrayList<>();
|
||||||
listStart.add(wpt1);
|
listStart.add(wpt1);
|
||||||
|
|
||||||
@ -622,7 +634,6 @@ public class RoutingEngine extends Thread {
|
|||||||
|
|
||||||
double elev = (start1 == null ? 0 : start1.getElev()); // listOne.get(0).crosspoint.getElev();
|
double elev = (start1 == null ? 0 : start1.getElev()); // listOne.get(0).crosspoint.getElev();
|
||||||
|
|
||||||
List<AreaInfo> ais = new ArrayList<>();
|
|
||||||
int maxlon = Integer.MIN_VALUE;
|
int maxlon = Integer.MIN_VALUE;
|
||||||
int minlon = Integer.MAX_VALUE;
|
int minlon = Integer.MAX_VALUE;
|
||||||
int maxlat = Integer.MIN_VALUE;
|
int maxlat = Integer.MIN_VALUE;
|
||||||
@ -659,7 +670,18 @@ public class RoutingEngine extends Thread {
|
|||||||
int maxscale = Math.abs(searchRect.points.get(2).x - searchRect.points.get(0).x);
|
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");
|
logInfo("round trip execution time = " + (System.currentTimeMillis() - start) / 1000. + " seconds");
|
||||||
|
|
||||||
@ -693,8 +715,6 @@ public class RoutingEngine extends Thread {
|
|||||||
return (int) (Math.random()*360);
|
return (int) (Math.random()*360);
|
||||||
}
|
}
|
||||||
|
|
||||||
rc.ai = null;
|
|
||||||
|
|
||||||
int angle = ais.get(0).direction;
|
int angle = ais.get(0).direction;
|
||||||
return angle - 45 + (int) (Math.random()*90);
|
return angle - 45 + (int) (Math.random()*90);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user