📄 trackoper.java
字号:
else {
PointLineDistance pd = new PointLineDistance();
pd.setPoint0(x, y);
double dis = 1000.0;
for (int i = 0; i < trackPoints.size(); i++) {
if (i >= trackPoints.size() - 1) {
break;
}
else {
pd.setPoint1(Double.parseDouble(ItemValue.getTracksPointX( (Node)
trackPoints.get(i))),
Double.parseDouble(ItemValue.getTracksPointY( (Node)
trackPoints.get(i))));
pd.setPoint2(Double.parseDouble(ItemValue.getTracksPointX( (Node)
trackPoints.get(i +
1))),
Double.parseDouble(ItemValue.
getTracksPointY( (Node) trackPoints.
get(i + 1))));
dis = Math.min(dis, pd.getDis());
}
}
return dis;
}
}
public static double getDisOfTracksWithPointInMid(double x, double y,
ConcatenatedTrack track) {
Vector nl = track.getTrackPoints();
if ( (nl == null) || (nl.size() < 2)) {
return 1000.0;
}
else {
PointLineDistance pd = new PointLineDistance();
pd.setPoint0(x, y);
double dis = 1000.0;
for (int i = 0; i < nl.size(); i++) {
if (i >= nl.size() - 1) {
break;
}
else {
pd.setPoint1(Double.parseDouble(ItemValue.getTracksPointX( (Node) nl.
get(i))),
Double.parseDouble(ItemValue.getTracksPointY( (Node) nl.
get(i))));
pd.setPoint2(Double.parseDouble(ItemValue.getTracksPointX( (Node) nl.
get(i +
1))),
Double.parseDouble(ItemValue.getTracksPointY( (Node) nl.
get(i + 1))));
if ( (pd.getDisOfChuizuAndAnyPoint(Double.parseDouble(ItemValue.
getTracksPointX( (Node) nl.get(0))),
Double.parseDouble(ItemValue.
getTracksPointY( (Node) nl.get(0)))) >=
TrackRectangle.NEAR_DISTANCE * 5) &&
(pd.
getDisOfChuizuAndAnyPoint(Double.parseDouble(ItemValue.
getTracksPointX( (Node) nl.get(nl.size() - 1))),
Double.
parseDouble(ItemValue.
getTracksPointY( (Node) nl.get(nl.size() - 1)))) >=
TrackRectangle.NEAR_DISTANCE * 5)) {
dis = Math.min(dis, pd.getDis());
}
}
}
return dis;
}
}
private static void printTrks(Node[] trks) {
if (trks == null) {
System.out.println("printTrks == null");
}
else {
for (int i = 0; i < trks.length; i++) {
if (trks[i] == null) {
// System.out.println("printTrks[" + i +"]: == null!");
// try {
// throw new Exception("printTrks[" + i + "]: == null!");
// }
// catch (Exception ex) {
// ex.printStackTrace();
// }
}
else {
// System.out.println("printTrks[" + i +"]:" + ItemValue.getTracksName(trks[i]));
}
}
}
}
/*/**
* 点P(x,y)
* 得到离该点距离较远的航迹(但是,不包含航迹矩形方框包含P点的航迹)
*/
private static Node[] getForaneTrack(double x, double y, Node[] trks) {
// System.out.println("getForaneTrack->*********************");
// printTrks(trks);
Vector ve = new Vector();
if (trks == null) {
return null;
}
TrackRectangle tr = null;
for (int i = 0; i < trks.length; i++) {
tr = new TrackRectangle(trks[i]);
/**
* TrackRectangle.NEAR_DISTANCE * 200 = 4000米
*/
if (tr.getDistanceWithThisRectangle(x, y) >
TrackRectangle.NEAR_DISTANCE * 200) {
if (! (TrackRectangle.isPointInIt(x, y, tr))) {
ve.add(trks[i]);
}
}
}
if (ve.size() <= 0) {
return null;
}
else {
Node[] temp = null;
temp = new Node[ve.size()];
for (int i = 0; i < temp.length; i++) {
temp[i] = (Node) ve.elementAt(i);
}
return temp;
}
}
/**
* 除去数组@param allNode 的一部份@param someNode
*/
public static Node[] getRidOfArray(Node[] allNode, Node[] someNode) {
// System.out.println("getRidOfArray->*********************");
// printTrks(allNode);
// Node[] temp = new Node[allNode.length];
// for (int i = 0; i < temp.length; i++) {
// temp[i] = allNode[i];
// }
Vector ve = new Vector();
for (int i = 0; i < allNode.length; i++) {
if (! (isEqualsInIt(someNode, allNode[i]))) {
ve.add(allNode[i]);
}
}
if (ve.size() == 0) {
return null;
}
else {
Node[] temp = new Node[ve.size()];
for (int i = 0; i < temp.length; i++) {
temp[i] = (Node) ve.elementAt(i);
}
return temp;
}
}
private static Node[] getRidOf(Node[] trks, Node trk) {
// System.out.println("getRidOf->*********************");
// printTrks(trks);
if (trks == null) {
return null;
}
else {
Node[] temp = new Node[trks.length - 1];
boolean find = false;
for (int i = 0; i < temp.length; i++) {
if (trks[i] == trk) {
find = true;
}
else {
if (find == true) {
temp[i] = trks[i + 1];
}
else {
temp[i] = trks[i];
}
}
}
if (find == false) {
return trks;
}
return temp;
}
}
private static boolean isEqualsInIt(Node[] someNode, Node trk) {
for (int i = 0; someNode != null && i < someNode.length; i++) {
if (someNode[i] == trk) {
return true;
}
else if (ItemValue.getTracksID(someNode[i]).equals(ItemValue.getTracksID(
trk))) {
return true;
}
}
return false;
}
/**
* 得到点到航迹的距离
*/
public static double getDisOfTracksWithPoint(double x, double y, String track) {
Vector nodes = (Vector) ItemValue.namedTracks.get(track);
double dist = 99999999d;
if (nodes != null) {
for (int n = 0; n < nodes.size(); n++) {
Node node = (Node) nodes.get(n);
NodeList nl = ItemValue.getTracksPoint(node);
if ( (nl == null) || (nl.getLength() < 2)) {
return 1000.0;
}
else {
PointLineDistance pd = new PointLineDistance();
pd.setPoint0(x, y);
double dis = 1000.0;
for (int i = 0; i < nl.getLength(); i++) {
{
double x1 = Double.parseDouble(ItemValue.getTracksPointX(nl.item(
i)));
double y1 = Double.parseDouble(ItemValue.getTracksPointY(nl.item(
i)));
// Math.sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));
// pd.setPoint1(),
// );
// pd.setPoint2(Double.parseDouble(ItemValue.getTracksPointX(nl.item(i + 1))),
// Double.parseDouble(ItemValue.getTracksPointY(nl.item(i + 1))));
dis = Math.min(dis,
Math.sqrt( (x - x1) * (x - x1) +
(y - y1) * (y - y1)));
}
}
if (dis < dist) {
dist = dis;
}
}
}
}
return dist;
}
/**
* 得到路线在本航迹@param trk矩形框交叉或者包含的航迹
*/
public static Node[] getIntersectTracks(Node[] trks, Node trk) {
if ( (trks == null) || (trk == null)) {
return null;
}
else {
Node[] temp = null;
Vector ve = new Vector();
TrackRectangle tr1 = new TrackRectangle(trk);
TrackRectangle tr2 = null;
for (int i = 0; i < trks.length; i++) {
if (trk != trks[i]) {
tr2 = new TrackRectangle(trks[i]);
if ( (tr1.isIntersect(tr2)) || (tr1.isContain(tr2))) {
ve.addElement(trks[i]);
}
}
}
temp = new Node[ve.size()];
for (int i = 0; i < temp.length; i++) {
temp[i] = (Node) ve.elementAt(i);
}
return temp;
}
}
/**
* 得到离P点最近的航迹
* @param distance 范围,单位为米
*/
public static Node getTDTrackNearest(double longitude, double latitude,
Node[] trks, long distance) {
Node trk = null;
trks = TrackOper.getRidOfArray(trks,
getForaneTrack(longitude, latitude, trks));
if (trks == null) {
System.out.println("getRidOfArray getForaneTrack");
return null;
}
else {
printTrks(trks);
double min = (TrackRectangle.NEAR_DISTANCE / 20) * distance, temp;
for (int i = 0; i < trks.length; i++) {
temp = getDisOfTracksWithPoint(longitude, latitude, trks[i]);
if (min > temp) {
min = temp;
trk = trks[i];
}
}
}
return trk;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -