📄 cutbyrs.java
字号:
package net.aetherial.gis.output.toLd.cut;
import net.aetherial.gis.our.FrameOur;
import org.w3c.dom.*;
import net.aetherial.gis.surface.ItemValue;
import java.util.Vector;
import java.io.File;
import net.aetherial.gis.dataType.WptType;
import net.aetherial.gis.surface.CreateFile;
import net.aetherial.gis.garmin.GarminGMLDoc;
import net.aetherial.gis.output.toLd.bianma.BmAtRepeate;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2004</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class CutByRS {
private FrameOur fo = null;
private Node[] myWpt = null;
private String Rs_Now = "";
private String n = "";
private Node[] tPoint = null;
private String[] RS_tPoint = null;
private BmAtRepeate bianma = new BmAtRepeate();
public CutByRS(FrameOur fo) {
this.fo = fo;
}
private Vector getRsChengedWPts(Node trk) {
Node[] wpts = ItemValue.getTracksWaypoint(trk);
Vector temp = new Vector();
for (int i = 0; wpts != null && i < wpts.length; i++) {
if (!ItemValue.getWaypointRS(wpts[i]).trim().equals("")) {
temp.add(wpts[i]);
}
}
return temp;
}
private String getRSBeforeChenge(Node wpt) { //在碰到路面变化点时,得到以前的路面类型,顺便取得现在的路面类型
String RS = ItemValue.getWaypointRS(wpt);
//if(RS.str)
String RSTemp = "";
RSTemp = RS.substring(3, 5);
if (RSTemp.equals(WptType.RS_C_bad)) {
RSTemp = WptType.RS_C_type;
}
this.Rs_Now = RSTemp;
RSTemp = RS.substring(0, 2);
if (RSTemp.equals(WptType.RS_C_bad)) {
RSTemp = WptType.RS_C_type;
}
return RSTemp;
}
public void getTrackRSToThis() {
Node[] tracks = ItemValue.getTracks();
if (tracks == null) {
return;
}
for (int i = 0; i < tracks.length; i++) {
if (bianma.isTrkCanBeCut(tracks[i])) {
Vector childsRS = this.getRsChengedWPts(tracks[i]);
if (childsRS.size() > 0) {
this.print("航迹[" + ItemValue.getTracksName(tracks[i]) + "]中有路面变化点");
for (int j = 0; j < childsRS.size(); j++) {
this.print(" " + ItemValue.getWaypointName((Node)childsRS.get(j)));
}
this.myWpt = new Node[childsRS.size()];
childsRS.copyInto(this.myWpt);
getWptIntoTracks(tracks[i]);
this.myWpt = null;
}
}
}
bianma.initBianmaAppointment(ItemValue.getTracks());
}
private void getWptIntoTracks(Node trk) {
Vector ve = new Vector();
this.tPoint = new Node[this.myWpt.length];
this.RS_tPoint = new String[this.myWpt.length + 1];
for (int i = 0; i < tPoint.length; i++) {
tPoint[i] = this.getNearpoint(trk, this.myWpt[i]);
RS_tPoint[i] = this.getRSBeforeChenge(this.myWpt[i]);
}
RS_tPoint[RS_tPoint.length - 1] = this.Rs_Now;
Node tp = null;
NodeList nl = ItemValue.getTracksPoint(trk);
boolean find = false;
Node newTrk1, newTrk2;
for (int i = 0; i < nl.getLength(); i++) {
tp = nl.item(i);
ve.add(tp);
for (int j = 0; j < tPoint.length; j++) {
if (tp.equals(tPoint[j])) {
Node newTP = ItemValue.getNewTrackPoint(ItemValue.getWaypointX(myWpt[
j]), ItemValue.getWaypointY(myWpt[j]),
ItemValue.getWaypointZ(myWpt[
j]), "");
ve.add(newTP);
newTrk1 = createNewTrack(trk, ve, RS_tPoint[j]);
if (newTrk1 != null) {
this.bianma.clearLdBianmaAtCut(newTrk1);
this.printNewTrack(newTrk1);
}
find = true;
ve = null;
ve = new Vector();
ve.add(newTP);
break;
}
}
}
if (find == true) {
newTrk2 = createNewTrack(trk, ve, RS_tPoint[RS_tPoint.length - 1]);
if (newTrk2 != null) {
this.bianma.clearLdBianmaAtCut(newTrk2);
this.printNewTrack(newTrk2);
}
ItemValue.removeTrack(trk);
}
}
private void printNewTrack(Node trk) {
System.out.println("*********新切割出航迹:" + ItemValue.getTracksName(trk));
}
private Node createNewTrack(Node sourceTrack, Vector ve, String RS) {
RelateWPTAfterCut relate = new RelateWPTAfterCut();
System.out.println("*********产生出航迹:");
if (ve.size() > 1 && this.isTrackPointSuitable(ve)) {
Element e = GarminGMLDoc.addTrack(ItemValue.getTracksName(sourceTrack) +
"(" + RS + ")", sourceTrack, RS);
for (int i = 0; i < ve.size(); i++) {
GarminGMLDoc.addTrackPoint(e, (Node) ve.elementAt(i));
}
relate.relateToNewTrk(sourceTrack,e.getParentNode());
return e.getParentNode();
}
else {
return null;
}
}
private boolean isTrackPointSuitable(Vector trackpoints){
String p0x = ItemValue.getTracksPointX((Node)trackpoints.get(0));
String p0y = ItemValue.getTracksPointY((Node)trackpoints.get(0));
String p1x,p1y;
for (int i = 1; i < trackpoints.size(); i++) {
p1x = ItemValue.getTracksPointX((Node)trackpoints.get(i));
p1y = ItemValue.getTracksPointY((Node)trackpoints.get(i));
if (!(p0x.equals(p1x) && p0y.equals(p1y))) {
return true;
}
}
return false;
}
public void createNewFile() {
}
/**
* 返回的是 新产生 的 航迹 点
*/
private Node getFootPoint(Node begin, Node end, Node wp) {
double bx, by, bz, ex, ey, ez, px, py, pz, fpx, fpy, fpz;
/**
* begin 经纬度
*/
bx = Double.parseDouble(ItemValue.getTracksPointX(begin));
by = Double.parseDouble(ItemValue.getTracksPointY(begin));
bz = Double.parseDouble(ItemValue.getTracksPointZ(begin));
/**
* end 经纬度
*/
ex = Double.parseDouble(ItemValue.getTracksPointX(end));
ey = Double.parseDouble(ItemValue.getTracksPointY(end));
ez = Double.parseDouble(ItemValue.getTracksPointZ(end));
/**
* 航点 经纬度
*/
px = Double.parseDouble(ItemValue.getWaypointX(wp));
py = Double.parseDouble(ItemValue.getWaypointY(wp));
pz = Double.parseDouble(ItemValue.getWaypointZ(wp));
double k = (ey - by) / (ex - bx);
fpx = (k * k * bx + k * (py - by) + px) / (k * k + 1);
fpy = k * (fpx - bx) + by;
if (bz - ez > 0.00001) {
double k1 = (ey - by) / (ez - bz);
fpz = (k1 * k1 * bz + k1 * (py - by) + pz) / (k1 * k1 + 1);
}
else {
fpz = bz;
}
double minx = Math.min(bx, ex);
double miny = Math.min(by, ey);
double minz = Math.min(bz, ez);
double maxx = Math.max(bx, ex);
double maxy = Math.max(by, ey);
double maxz = Math.max(bz, ez);
Node fp = ItemValue.getNewTrackPoint("" + fpx, "" + fpy, "" + fpz, "");
if (minx < fpx && fpx < maxx && miny < fpy && fpy < maxy) { // && minz<fpz && fpz<maxz){
return fp;
}
if (getDistance(begin, wp) < getDistance(end, wp)) {
return begin;
}
else {
return end;
}
}
/**
* 返回的是 新产生 的 航迹 点
*/
private Node getFootPoint_Wag(Node begin, Node end, Node trackPoint) {
double bx, by, bz, ex, ey, ez, px, py, pz, fpx, fpy, fpz;
/**
* begin 经纬度
*/
bx = Double.parseDouble(ItemValue.getTracksPointX(begin));
by = Double.parseDouble(ItemValue.getTracksPointY(begin));
bz = Double.parseDouble(ItemValue.getTracksPointZ(begin));
/**
* end 经纬度
*/
ex = Double.parseDouble(ItemValue.getTracksPointX(end));
ey = Double.parseDouble(ItemValue.getTracksPointY(end));
ez = Double.parseDouble(ItemValue.getTracksPointZ(end));
/**
* 航迹点 经纬度
*/
px = Double.parseDouble(ItemValue.getTracksPointX(trackPoint));
py = Double.parseDouble(ItemValue.getTracksPointY(trackPoint));
pz = Double.parseDouble(ItemValue.getTracksPointZ(trackPoint));
double k = (ey - by) / (ex - bx);
fpx = (k * k * bx + k * (py - by) + px) / (k * k + 1);
fpy = k * (fpx - bx) + by;
if (bz - ez > 0.00001) {
double k1 = (ey - by) / (ez - bz);
fpz = (k1 * k1 * bz + k1 * (py - by) + pz) / (k1 * k1 + 1);
}
else {
fpz = bz;
}
double minx = Math.min(bx, ex);
double miny = Math.min(by, ey);
double minz = Math.min(bz, ez);
double maxx = Math.max(bx, ex);
double maxy = Math.max(by, ey);
double maxz = Math.max(bz, ez);
Node fp = ItemValue.getNewTrackPoint("" + fpx, "" + fpy, "" + fpz, "");
// Node fp = ItemValue.insertNewTrackPoint(ItemValue.getTrackPoint_Track(end),end, "" + fpx, "" + fpy, "" + fpz);
if (minx < fpx && fpx < maxx && miny < fpy && fpy < maxy) { // && minz<fpz && fpz<maxz){
return fp;
}
if (getDistance_ByTp(begin, trackPoint) < getDistance_ByTp(end, trackPoint)) {
return begin;
}
else {
return end;
}
}
private double getDistance(Node begin, Node end, Node wp) {
return getDistance(getFootPoint(begin, end, wp), wp);
}
private double getDistance(Node tp, Node wp) {
double tpx = Double.parseDouble(ItemValue.getTracksPointX(tp));
double tpy = Double.parseDouble(ItemValue.getTracksPointY(tp));
double wpx = Double.parseDouble(ItemValue.getWaypointX(wp));
double wpy = Double.parseDouble(ItemValue.getWaypointY(wp));
return Math.sqrt( (tpx - wpx) * (tpx - wpx) + (tpy - wpy) * (tpy - wpy));
}
private double getDistance_ByTp(Node begin, Node end, Node tp) {
return getDistance_ByTp(getFootPoint_Wag(begin, end, tp), tp);
}
private double getDistance_ByTp(Node tp1, Node tp2) {
double tpx = Double.parseDouble(ItemValue.getTracksPointX(tp1));
double tpy = Double.parseDouble(ItemValue.getTracksPointY(tp1));
double wpx = Double.parseDouble(ItemValue.getTracksPointX(tp2));
double wpy = Double.parseDouble(ItemValue.getTracksPointY(tp2));
return Math.sqrt( (tpx - wpx) * (tpx - wpx) + (tpy - wpy) * (tpy - wpy));
}
private Node getNearpoint(Node track, Node waypoint) {
double distance = 0.0;
double minDis = 0.5;
Node minTp = null;
Node fp = null;
NodeList nl = ItemValue.getTracksPoint(track);
for (int i = 1; i < nl.getLength(); i++) {
distance = this.getDistance(nl.item(i - 1), nl.item(i), waypoint);
if (minDis > distance) {
minDis = distance;
minTp = nl.item(i - 1);
fp = getFootPoint(nl.item(i - 1), nl.item(i), waypoint);
}
}
if (minDis == 0.5) {
this.print("没有发现与" + ItemValue.getWaypointName(waypoint) + "相近的点!");
}
else {
if (fp != null) {
this.print("修改行点坐标到垂足");
ItemValue.setWaypointX(waypoint, ItemValue.getTracksPointX(fp));
ItemValue.setWaypointY(waypoint, ItemValue.getTracksPointY(fp));
ItemValue.setWaypointZ(waypoint, ItemValue.getTracksPointZ(fp));
}
}
return minTp;
}
public void setStringFileName(String fileName) {
this.print("文件的名称是:" + fileName);
}
public void savedString(String filePath) {
File f = new File(filePath);
CreateFile cfWpt = new CreateFile(f);
cfWpt.setEncode("GB2312");
cfWpt.memoryToFile(this.n);
}
public String getString() {
return this.n;
}
private void print(String string) {
n = n + string + "\r\n";
System.out.println(string);
}
public static void main(String test[]) {
String test1 = "砂石→油路";
//for(int i = 0;i<test1.length();i++){
System.out.println(test1.substring(0, 2));
//}
/*
0:
1:砂
2:砂石
3:砂石→
4:砂石→油
*/
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -