📄 trackoper.java
字号:
package net.aetherial.gis.publicuse;
import net.aetherial.gis.surface.ItemValue;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.util.Vector;
import net.aetherial.gis.our.auto.check.repeattrk.TrackRectangle;
import java.util.Enumeration;
import net.aetherial.gis.publicuse.track.ConcatenatedTrack;
import net.aetherial.gis.dataType.TrackType;
import java.util.Hashtable;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2004</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class TrackOper {
public TrackOper() {
}
/**
* 得到离P点(longitude,latitude)最近的航迹
*/
public static Node getTDTrack(double longitude, double latitude, Node[] trks) {
Node trk = null;
// trks = TrackOper.getRidOfArray(trks,
// getForaneTrack(longitude, latitude, trks));
// if (trks == null) {
// return null;
// }
// else {
// double min = 1000.0;
// for (int i = 0; i < trks.length; i++) {
// if (min > getDisOfTracksWithPoint(longitude, latitude, trks[i])) {
// trk = trks[i];
// }
// }
// }
return trk;
}
/**
* 得到离P点(longitude,latitude)distance米范围内的航迹
* @param distance 范围,单位为米
*/
public static Node[] getTDTracks(double longitude, double latitude,
Node[] trks, long distance) {
Node[] trk = null;
// Vector ve = new Vector();
// 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;
// for (int i = 0; i < trks.length; i++) {
// if ( (trks[i] != null) &&
// (min > getDisOfTracksWithPoint(longitude, latitude, trks[i]))) {
// ve.add(trks[i]);
//
// }
// }
// }
//
// if (ve.size() <= 0) {
// return null;
// }
//
// else {
// trk = new Node[ve.size()];
// }
//
// for (int i = 0; i < ve.size(); i++) {
// trk[i] = (Node) ve.elementAt(i);
// }
return trk;
}
public static String[] getTDTracks(double longitude, double latitude,
long distance) {
String[] trk = null;
Vector ve = new Vector();
Hashtable ht = new Hashtable();
double min = (TrackRectangle.NEAR_DISTANCE / 20) * distance,
temp = 999999999d;
Enumeration keys = ItemValue.namedTracks.keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
// Vector nodes = (Vector)ItemValue.namedTracks.get(key);
// if(nodes != null){
// for (int i = 0; i < nodes.size(); i++) {
temp = getDisOfTracksWithPoint(longitude, latitude, key);
// }
// }
// System.out.println("name is: " + key + " == distance: " + temp);
if (min > temp) {
// min = temp;
ht.put(key, temp + "");
// ve.add(key);
}
}
ve = getSuitTongda(ht);
if (ve.size() <= 0) {
return new String[0];
}
else {
trk = new String[ve.size()];
// System.out.println("td length: " + ve.size());
}
for (int i = 0; i < ve.size(); i++) {
trk[i] = (String) ve.elementAt(i);
}
return trk;
}
/**
* 针对3.5米无路面的路线的,
* 选择最优路线程序
*/
private static Vector getSuitTongda(Hashtable ht) {
Enumeration keys = ht.keys();
// boolean isAllLess = true;
int all = 0, less = 0;
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
all++;
if (isLuxianIn3Mi5OrWuLUMian(key)) {
less++;
}
// double dis = Double.parseDouble(ht.get(key)+"");
}
Vector temp = new Vector();
if (all == less) {
// 得到最合适的一条路线
Enumeration keys2 = ht.keys();
String tempKey = "";
double tempDis, minDis = Double.MAX_VALUE;
while (keys2.hasMoreElements()) {
String key = (String) keys2.nextElement();
tempDis = Double.parseDouble(ht.get(key) + "");
if (minDis > tempDis) {
minDis = tempDis;
tempKey = key;
}
}
temp.add(tempKey);
}
else if (all > less && less > 0) {
//删除所有不合适的路线
Enumeration keys2 = ht.keys();
while (keys2.hasMoreElements()) {
String key = (String) keys2.nextElement();
if (!isLuxianIn3Mi5OrWuLUMian(key)) {
temp.add(key);
}
}
}
else {
// 保留所有路线
Enumeration keys2 = ht.keys();
while (keys2.hasMoreElements()) {
String key = (String) keys2.nextElement();
temp.add(key);
}
}
return temp;
}
/**
* 指定的key得到的路线是否全路段小于3.5米或者无路面
*/
private static boolean isLuxianIn3Mi5OrWuLUMian(String key) {
Vector nodes = (Vector) ItemValue.namedTracks.get(key);
Node node = null;
boolean is3Mi5 = false, wulumian = false;
String type = "";
for (int i = 0; i < nodes.size(); i++) {
node = (Node) nodes.get(i);
type = ItemValue.getTracksType(node).trim();
if (! (Double.parseDouble(ItemValue.getTracksWidth(node).trim()) < 3.5 ||
(type.equals(TrackType.RS_D_bad) ||
type.equals(TrackType.RS_JTB_8_WuLumian) || type.equals("")))) {
return false;
}
}
return true;
}
/**
* 得到离P点最近的航迹
* @param distance 范围,单位为米
*/
public static String getTDTrackNearest(double longitude, double latitude,
String[] trks, long distance) {
String trk = null;
{
// printTrks(trks);
double min = (TrackRectangle.NEAR_DISTANCE / 20) * distance,
temp = 999999999d;
Enumeration keys = ItemValue.namedTracks.keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
Vector nodes = (Vector) ItemValue.namedTracks.get(key);
if (nodes != null) {
for (int i = 0; i < nodes.size(); i++) {
temp = Math.min(temp, getDisOfTracksWithPoint(longitude, latitude,
key));
}
}
if (min > temp) {
min = temp;
trk = key;
}
}
}
return trk;
}
public static double getDisOfTracksWithPoint(double x, double y, Node track) {
NodeList nl = ItemValue.getTracksPoint(track);
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++) {
if (i >= nl.getLength() - 1) {
break;
}
else {
pd.setPoint1(Double.parseDouble(ItemValue.getTracksPointX(nl.item(i))),
Double.parseDouble(ItemValue.getTracksPointY(nl.item(i))));
pd.setPoint2(Double.parseDouble(ItemValue.getTracksPointX(nl.item(i +
1))), Double.parseDouble(ItemValue.getTracksPointY(nl.item(i + 1))));
dis = Math.min(dis, pd.getDis());
}
}
return dis;
}
}
public static double getDisOfTracksWithPoint(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))));
dis = Math.min(dis, pd.getDis());
}
}
return dis;
}
}
public static double getDisOfTracksWithPoint(double x, double y,
Vector trackPoints) {
if ( (trackPoints == null) || (trackPoints.size() < 2)) {
return 1000.0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -