📄 tracktablename.java
字号:
package net.aetherial.gis.table;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import net.aetherial.gis.surface.ItemValue;
/**
* <p>Title: </p>
*
* <p>Description: 航迹的名称构造成起乾点命名,如果找不到最近的起乾点,则以原路名命名</p>
*
* <p>Copyright: Copyright (c) 2004</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class TrackTableName {
/**
* 10M
*/
private final double NEAR_DISTANCE = 0.0006;
private String primalName = "";
private String chengeName = "";
private Node trk = null;
private Node[] hiswpt = null;
private NodeList tpoint = null;
public TrackTableName(Node trk) {
this.trk = trk;
String code = ItemValue.getTracksNumber(trk);
this.primalName = ItemValue.getTracksName(trk);
this.primalName = primalName.replaceAll("(","(").replaceAll(")",")");
if(primalName.lastIndexOf("(") > -1
&& primalName.lastIndexOf(")") > -1
&& primalName.lastIndexOf("(") < primalName.lastIndexOf(")")){
this.primalName = this.primalName.substring(primalName.lastIndexOf("(")+1,primalName.lastIndexOf(")"));
}
// if(code != null && code.length() > 2){
// this.primalName = code;
// }
this.chengeName = "";
this.hiswpt = ItemValue.getTracksWaypoint(this.trk);
this.tpoint = ItemValue.getTracksPoint(this.trk);
}
/**
* 得到起点的航点
*/
private Node getStartNode(){
if ((hiswpt == null)||(tpoint == null)) {
return null;
}else{
return this.getMostNearWpt(this.hiswpt,this.tpoint.item(0),true);
}
}
/**
* 得到终点的航点
*/
private Node getEndNode(){
if ((hiswpt == null)||(tpoint == null)) {
return null;
}else{
return this.getMostNearWpt(this.hiswpt,this.tpoint.item(this.tpoint.getLength()-1),false);
}
}
public String getStartEndName(){
Node start = this.getStartNode();
Node end = this.getEndNode();
if ((start == null)||(end == null)) {
return this.primalName;
}else{
return ItemValue.getWaypointName(start) + "-" + ItemValue.getWaypointName(end);
}
}
/**
* 得到最近的航点
* qidian:是否是判断起点,如果是起点,应该从航点的顺序进行,否则倒序
*/
private Node getMostNearWpt(Node[] wpts,Node tp,boolean qidian){
if ((wpts == null)||(tp == null)) {
return null;
}
double tpX = Double.parseDouble(ItemValue.getTracksPointX(tp));
double tpY = Double.parseDouble(ItemValue.getTracksPointY(tp));
double wptX = 0.0,wptY = 0.0;
if (qidian) {
for (int i = 0; i < wpts.length; i++) {
wptX = Double.parseDouble(ItemValue.getWaypointX(wpts[i]));
wptY = Double.parseDouble(ItemValue.getWaypointY(wpts[i]));
if (this.getDistance(tpX, tpY, wptX, wptY) < this.NEAR_DISTANCE) {
return wpts[i];
}
}
}
else {
for (int i = wpts.length - 1; i >= 0; i--) {
wptX = Double.parseDouble(ItemValue.getWaypointX(wpts[i]));
wptY = Double.parseDouble(ItemValue.getWaypointY(wpts[i]));
if (this.getDistance(tpX, tpY, wptX, wptY) < this.NEAR_DISTANCE) {
return wpts[i];
}
}
}
return null;
}
/**
* 求经纬度距离
*/
private double getDistance(double tpX,double tpY,double wptX,double wptY){
return Math.abs(Math.pow(((tpX-wptX) * (tpX-wptX) + (tpY-wptY) * (tpY-wptY)),0.5));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -