📄 lxbepoint.java
字号:
package net.aetherial.gis.jiaotongbu.outputJTB.txtOutput.module.gpsdata.lxld.lx;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import net.aetherial.gis.surface.ItemValue;
import java.util.Hashtable;
import java.util.Vector;
import net.aetherial.gis.our.auto.check.repeattrk.TrackRectangle;
import java.util.Collection;
import java.util.Map;
import java.util.HashMap;
/**
* <p>Title: </p>
*
* <p>Description:路线的起点\终点航点 </p>
*
* <p>Copyright: Copyright (c) 2004</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class LXBEPoint {
/**
* 路线的起点和终点航点
*/
private Node bPoint = null,ePoint = null;
/**
* 给定的路线航迹
*/
private Node trk = null;
/**
* 给定的路线航迹---两个节点代表一条路线
*/
private TwoNode ttrk = null;
private Node[] wpts = null;
public LXBEPoint() {
}
public LXBEPoint(Node trk) {
this.trk = trk;
}
public LXBEPoint(TwoNode ttrk) {
this.ttrk = ttrk;
}
public void setTrack(Node trk){
this.trk = trk;
}
public void setTwoNode(TwoNode ttrk){
this.ttrk = ttrk;
}
public void setAllWpt(Node[] wpts){
this.wpts = wpts;
}
public void reset(){
this.bPoint = null;
this.ePoint = null;
this.trk = null;
this.ttrk = null;
// this.wpts = null;
}
/**
* 扫描并得到起点和终点的航点
*/
public void scanToGetBE(){
if (this.trk != null) {
this.scanTrkBE();
}else if(this.ttrk != null){
this.scanTTrkBE();
}
}
private double getDisOfTwoTP(Node tp1,Node tp2){
double tp1x = Double.parseDouble(ItemValue.getTracksPointX(tp1));
double tp1y = Double.parseDouble(ItemValue.getTracksPointY(tp1));
double tp2x = Double.parseDouble(ItemValue.getTracksPointX(tp2));
double tp2y = Double.parseDouble(ItemValue.getTracksPointY(tp2));
return Math.pow((tp1x - tp2x)*(tp1x - tp2x) +(tp1y - tp2y)*(tp1y - tp2y),0.5);
}
/**
* 两节点顺序的关系
* 0 代表首1 首2相连
* 1 代表首1 尾2相连
* 2 代表尾1 首2相连
* 3 代表尾1 尾2相连
* 4 不相连
*/
public int getNodesShunxu(Node n1, Node n2){
NodeList nl1 = ItemValue.getTracksPoint(n1);
NodeList nl2 = ItemValue.getTracksPoint(n2);
double b1b2 = getDisOfTwoTP(nl1.item(0),nl2.item(0));
double b1e2 = getDisOfTwoTP(nl1.item(0),nl2.item(nl2.getLength()-1));
double e1b2 = getDisOfTwoTP(nl1.item(nl1.getLength() -1),nl2.item(0));
double e1e2 = getDisOfTwoTP(nl1.item(nl1.getLength() -1),nl2.item(nl2.getLength()-1));
double min = Math.min(Math.min(b1b2,b1e2),Math.min(e1b2,e1e2));
if(min > TrackRectangle.NEAR_DISTANCE) {
return 4;
}
if ((b1b2 < b1e2)&&(b1b2 < e1b2)&&(b1b2 < e1e2)) {
return 0;
}else if((b1e2 < b1b2)&&(b1e2 < e1b2)&&(b1e2 < e1e2)){
return 1;
}else if((e1b2 < b1b2)&&(e1b2 < b1e2)&&(e1b2 < e1e2)){
return 2;
}else{
return 3;
}
}
public void scanToGetBE(Vector nodes){
Node begin = null;
Node end = null;
if(nodes != null){
// double distance = 0;
//
// Node temp = null;
// for(int i = 0; i < nodes.size(); i++){
// double dist = ItemValue.getTracksDistance((Node)nodes.get(i));
// if(distance<dist){
// distance = dist;
// temp = (Node)nodes.get(i);
// }
// }
// NodeList nl1 = ItemValue.getTracksPoint(temp);
// end = nl1.item(nl1.getLength() - 1);
// begin = nl1.item(0);
// for (int j = 0; j < nodes.size(); j++) {
// if (!nodes.get(j).equals(temp)) {
// NodeList nl2 = ItemValue.getTracksPoint( (Node) nodes.get(j));
// int shunXu = getNodesShunxu( (Node) nodes.get(0),
// (Node) nodes.get(j));
// if (shunXu == 2) {
// end = nl2.item(nl2.getLength() - 1);
// }
// if (shunXu == 3) {
// end = nl2.item(0);
// }
// }
// }
// for (int j = 0; j < nodes.size(); j++) {
// if (!nodes.get(j).equals(temp)) {
// NodeList nl2 = ItemValue.getTracksPoint( (Node) nodes.get(j));
// int shunXu = getNodesShunxu( (Node) nodes.get(0),
// (Node) nodes.get(j));
// if (shunXu == 0) {
// begin = nl2.item(nl2.getLength() - 1);
// }
// if (shunXu == 1) {
// begin = nl2.item(0);
// }
// }
// }
begin = ItemValue.getTracksPoint( (Node) nodes.get(0)).item(0);
NodeList nl = ItemValue.getTracksPoint( (Node) nodes.get(nodes.size()-1));
end = nl.item(nl.getLength()-1);
this.bPoint = this.getMostNearWPT(begin);
this.ePoint = this.getMostNearWPT(end);
}
}
/**
* 单条航迹的B点\E点取法
*/
private void scanTrkBE(){
NodeList nl = ItemValue.getTracksPoint(this.trk);
this.bPoint = this.getMostNearWPT(nl.item(0));
this.ePoint = this.getMostNearWPT(nl.item(nl.getLength() -1));
// System.out.println("this.trk == " + ItemValue.getTracksName(this.trk));
// System.out.println("this.bPoint == " + ItemValue.getWaypointName(this.bPoint));
}
/**
* 两条航迹的B点\E点取法
*/
private void scanTTrkBE(){
NodeList nl1 = ItemValue.getTracksPoint(this.ttrk.getNode1());
NodeList nl2 = ItemValue.getTracksPoint(this.ttrk.getNode2());
int sx = this.ttrk.getNodesShunxu();
if (sx == 0) {
this.ePoint = this.getMostNearWPT(nl2.item(nl2.getLength() - 1));
this.bPoint = this.getMostNearWPT(nl1.item(nl1.getLength() - 1));
}
else if (sx == 1) {
this.ePoint = this.getMostNearWPT(nl2.item(0));
this.bPoint = this.getMostNearWPT(nl1.item(nl1.getLength() - 1));
}else if (sx == 2) {
this.ePoint = this.getMostNearWPT(nl2.item(nl2.getLength() - 1));
this.bPoint = this.getMostNearWPT(nl1.item(0));
}else {
this.ePoint = this.getMostNearWPT(nl2.item(0));
this.bPoint = this.getMostNearWPT(nl1.item(0));
}
}
/**
* 按照给定的航迹点
* 得到距离最近的航点
*/
private Node getMostNearWPT(Node trackPoint){
double tpx = Double.parseDouble(ItemValue.getTracksPointX(trackPoint));
double tpy = Double.parseDouble(ItemValue.getTracksPointY(trackPoint));
double wptx,wpty,dis;
double nearData = 1000;
Node result = null;
if (wpts == null) {
return null;
}else{
// Hashtable ht = new Hashtable();
for (int i = 0; i < wpts.length; i++) {
wptx = Double.parseDouble(ItemValue.getWaypointX(wpts[i]));
wpty = Double.parseDouble(ItemValue.getWaypointY(wpts[i]));
dis = Math.pow((wptx - tpx) * (wptx - tpx) + (wpty - tpy) * (wpty - tpy),0.5);
if(dis < nearData){
nearData = dis;
result = wpts[i];
}
}
String name = "端点";
if(result != null){
name = ItemValue.getWaypointName(result);
}
result = ItemValue.turnTracksPointToWaypoint(trackPoint);
// ItemValue.setWaypointX(result,ItemValue.getTracksPointX(trackPoint));
// ItemValue.setWaypointY(result,ItemValue.getTracksPointY(trackPoint));
ItemValue.setWaypointName(result,name);
return result;
}
}
/**
* 得到终点
*/
public Node getEPoint() {
return ePoint;
}
/**
* 得到起点
*/
public Node getBPoint() {
return bPoint;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -