📄 luxiannodes.java
字号:
package net.aetherial.gis.output.toTable.zouxiang;
import java.util.*;
import org.w3c.dom.*;
import net.aetherial.gis.publicuse.track.ConcatenatedTrack;
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 LuxianNodes {
private Vector conTrks = new Vector();
private Node[] nodes = new Node[5];
private String[] nodesName = new String[5];
public LuxianNodes(Vector conTrks) {
this.conTrks = conTrks;
}
public void intNodes(){
try {
System.out.println("this.conTrks.size()" + this.conTrks.size());
if (this.conTrks.size() == 1) {
this.getNodesIfOneConTrks();
}
else {
this.getNodesIfMoreConTrks();
}
}
catch (Exception ex) {
// ex.printStackTrace();
}
for (int i = 0; i < nodesName.length; i++) {
try {
nodesName[i] = ItemValue.getWaypointName(nodes[i]);
}
catch (Exception ex1) {
nodesName[i] = "";
}
}
}
private void getNodesIfOneConTrks() throws Exception{
Node[] trks = ( (ConcatenatedTrack)this.conTrks.get(0)).
getConcatenatedTrack();
System.out.println("trks.length:" + trks.length);
if (trks.length == 1) {
try {
this.nodes[0] = this.getTracksWaypoint(0, trks[0]);
this.nodes[1] = this.getTracksWaypoint(1 / 5.0, trks[0]);
this.nodes[2] = this.getTracksWaypoint(2 / 5.0, trks[0]);
this.nodes[3] = this.getTracksWaypoint(3 / 5.0, trks[0]);
this.nodes[4] = this.getTracksWaypoint(4 / 5.0, trks[0]);
this.nodes[5] = this.getTracksWaypoint(1, trks[0]);
}
catch (Exception ex) {
}
}
else if (trks.length == 2) {
try {
this.nodes[0] = this.getTracksWaypoint(0, trks[0]);
this.nodes[1] = this.getTracksWaypoint(1 / 2.0, trks[0]);
this.nodes[2] = this.getTracksWaypoint(1, trks[0]);
this.nodes[3] = this.getTracksWaypoint(0, trks[1]);
this.nodes[4] = this.getTracksWaypoint(1 / 2.0, trks[1]);
this.nodes[5] = this.getTracksWaypoint(1, trks[1]);
}
catch (Exception ex) {
}
}
else {
try {
this.nodes[0] = this.getTracksWaypoint(0, trks[0]);
this.nodes[1] = this.getTracksWaypoint(1, trks[0]);
this.nodes[2] = this.getTracksWaypoint(0, trks[ (int) (trks.length / 2)]);
this.nodes[3] = this.getTracksWaypoint(1, trks[ (int) (trks.length / 2)]);
this.nodes[4] = this.getTracksWaypoint(0, trks[trks.length - 1]);
this.nodes[5] = this.getTracksWaypoint(1, trks[trks.length - 1]);
}
catch (Exception ex) {
}
}
}
private void getNodesIfMoreConTrks() throws Exception {
ConcatenatedTrack temp = null;
Hashtable ht = new Hashtable();
for (int i = 0; i < this.conTrks.size(); i++) {
temp = (ConcatenatedTrack)this.conTrks.get(i);
ht.put(temp.getFirstTrackPoint(), temp);
ht.put(temp.getLastTrackPoint(), temp);
}
Enumeration keys = ht.keys();
Vector tps = new Vector();
while (keys.hasMoreElements()) {
tps.add( (Node) keys.nextElement());
}
Node[] twopints = this.getFarPoints(tps);
ConcatenatedTrack ct1 = (ConcatenatedTrack) ht.get(twopints[0]);
ConcatenatedTrack ct2 = (ConcatenatedTrack) ht.get(twopints[1]);
Node[] trks1 = ct1.getConcatenatedTrack();
Node[] trks2 = ct2.getConcatenatedTrack();
try {
this.nodes[0] = this.getTracksWaypoint(0, trks1[0]);
this.nodes[1] = this.getTracksWaypoint(1 / 2.0, trks1[0]);
this.nodes[2] = this.getTracksWaypoint(1, trks1[0]);
this.nodes[3] = this.getTracksWaypoint(0, trks2[0]);
this.nodes[4] = this.getTracksWaypoint(1 / 2.0, trks2[0]);
this.nodes[5] = this.getTracksWaypoint(1, trks2[0]);
}
catch (Exception ex) {
}
}
private Node[] getFarPoints(Vector tps) {
Node[] temp2 = new Node[2];
double max = 0;
for (int i = 0; i < tps.size(); i++) {
temp2[0] = (Node) tps.get(i);
for (int j = 0; j < tps.size(); j++) {
try {
if (max < this.getDisOfTp( (Node) tps.get(i), (Node) tps.get(j))) {
temp2[0] = (Node) tps.get(i);
temp2[1] = (Node) tps.get(j);
}
}
catch (Exception ex) {
}
}
}
return temp2;
}
/**
*
* @param weizhi 0,1/2,1/3,1/4/,1/5,2/4
* @return Node waypoint
*/
private Node getTracksWaypoint(double weizhi, Node track) throws Exception {
if (weizhi > 1 || weizhi < 0) {
throw new Exception("选取的位置错误:" + weizhi);
}
NodeList nl = ItemValue.getTracksPoint(track);
int pos = 0;
if (nl != null) {
pos = (int) (weizhi * nl.getLength());
// System.out.println("pos:" + pos + ",weizhi:" + weizhi);
if (pos == nl.getLength()) {
pos = pos -1;
}
}
Node trackpoint = nl.item(pos);
Node getWpt = this.getNearWaypoint(trackpoint);
// if (trackpoint == null) {
// System.out.println("pos:" + pos +",nl:" + nl.getLength() + ",trackpoint == null," + ItemValue.getWaypointName(getWpt));
// }else{
// System.out.println("pos:" + pos +",nl:" + nl.getLength() + ",trackpoint != null," + ItemValue.getWaypointName(getWpt));
// }
this.usedWaypoints.add(getWpt);
return getWpt;
}
private Vector usedWaypoints = new Vector();
private boolean isUsed(Node waypoint){
for (int i = 0; i < usedWaypoints.size(); i++) {
if ((Node)usedWaypoints.get(i) == waypoint) {
return true;
}
}
return false;
}
private Node getNearWaypoint(Node trackPoint) {
Node[] wpts = ItemValue.getWaypoint();
double distance = 1000;
Node temp = null;
for (int i = 0; wpts != null && i < wpts.length; i++) {
try {
if ((this.isCanIdentify(wpts[i]) || wpts.length <= 10) && (!this.isUsed(wpts[i]))) {
if (distance > this.getDis(wpts[i], trackPoint)) {
distance = this.getDis(wpts[i], trackPoint);
temp = wpts[i];
}
}
}
catch (Exception ex) {
// ex.printStackTrace();
}
}
return temp;
}
private boolean isCanIdentify(Node waypoint){
String name = ItemValue.getWaypointName(waypoint).trim();
if (name.equals("交叉") || name.equals("交叉点") || name.equals("涵")) {
return false;
}else{
return true;
}
}
private double getDis(Node wpt, Node trackpoint) throws Exception {
double wpt_x = Double.parseDouble(ItemValue.getWaypointX(wpt));
double wpt_y = Double.parseDouble(ItemValue.getWaypointY(wpt));
double tp_x = Double.parseDouble(ItemValue.getTracksPointX(trackpoint));
double tp_y = Double.parseDouble(ItemValue.getTracksPointY(trackpoint));
return Math.sqrt( (wpt_x - tp_x) * (wpt_x - tp_x) +
(wpt_y - tp_y) * (wpt_y - tp_y));
}
private double getDisOfTp(Node trackpoint1, Node trackpoint2) throws
Exception {
double wpt_x = Double.parseDouble(ItemValue.getTracksPointX(trackpoint1));
double wpt_y = Double.parseDouble(ItemValue.getTracksPointY(trackpoint1));
double tp_x = Double.parseDouble(ItemValue.getTracksPointX(trackpoint2));
double tp_y = Double.parseDouble(ItemValue.getTracksPointY(trackpoint2));
return Math.sqrt( (wpt_x - tp_x) * (wpt_x - tp_x) +
(wpt_y - tp_y) * (wpt_y - tp_y));
}
public String[] getNodesName() {
return nodesName;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -