⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cutbyrs.java

📁 基于Java的地图数据管理软件。使用MySQL数据库管理系统。
💻 JAVA
字号:
package net.aetherial.gis.our.auto;

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;

/**
 * <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;
  public CutByRS(FrameOur fo) {
    this.fo = fo;
  }

  private boolean haveRSChenge() {
    if (this.myWpt == null) {
      this.print("该航迹没有路面变化点!");
      return false;
    }
    else {
      this.print("该航迹发现路面变化点!");
      return true;
    }
  }

  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;
  }

  private Node[] getThisTrackRSWpt(Node track) { //得到该航迹的所有航点
    String tID = ItemValue.getTracksID(track);
    String wID = "null";
    Node[] wpt = ItemValue.getWaypoint();
    if (wpt == null) {
      return null;
    }
    Vector ve = new Vector();
    for (int i = 0; i < wpt.length; i++) {
      wID = ItemValue.getWaypointTracksID(wpt[i]);
      if (wID.equals(tID) && (! (ItemValue.getWaypointRS(wpt[i]).equals("")))) {
        ve.add(wpt[i]);
      }
    }
    Node[] hisWpt = new Node[ve.size()];
    for (int i = 0; i < ve.size(); i++) {
      hisWpt[i] = (Node) ve.elementAt(i);
    }
    return hisWpt;
  }

  public void getTrackRSToString() {
    Node[] tracks = ItemValue.getTracks();
    if (tracks == null) {
      this.print("该文件没有航迹!");
      return;
    }
    for (int i = 0; i < tracks.length; i++) {
      n = n + "航迹[" + ItemValue.getTracksName(tracks[i]) + "]:\r\n";
      this.myWpt = getThisTrackRSWpt(tracks[i]);
      if (this.haveRSChenge()) {
        //n = n +"在航迹发现路面变化点:\r\n";
        if (this.myWpt != null) {
          for (int j = 0; j < this.myWpt.length; j++) {
            this.print("---------------->>----------------------->>" +
                       ItemValue.getWaypointName(this.myWpt[j]));
          }
        }
      }
      this.myWpt = null;
      //if(tracks[i])
    }
  }

  public void getTrackRSToThis() {

    Node[] tracks = ItemValue.getTracks();
    if (tracks == null) {
      this.print("该文件没有航迹!");
      return;
    }
    for (int i = 0; i < tracks.length; i++) {
      this.print("航迹[" + ItemValue.getTracksName(tracks[i]) + "]:\r\n");
      this.myWpt = getThisTrackRSWpt(tracks[i]);
      if (this.haveRSChenge()) {
        //做航点插入航迹动作;
        for (int j = 0; j < this.myWpt.length; j++) {
          this.print("---------------->>----------------------->>" +
                     ItemValue.getWaypointName(this.myWpt[j]));
        }
        getWptIntoTracks(tracks[i]);
      }
      this.myWpt = null;
      //if(tracks[i])
    }
  }

  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;
    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);
          createNewTrack(trk, ve, RS_tPoint[j]);
          find = true;
          ve = null;
          ve = new Vector();
          ve.add(newTP);
          break;
        }
      }
    }
    if (find == true) {
      createNewTrack(trk, ve, RS_tPoint[RS_tPoint.length - 1]);
      ItemValue.removeTrack(trk);
    }
  }

  private void createNewTrack(Node sourceTrack, Vector ve, String RS) {
    if (ve.size() > 1) {
      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));
      }
    }
  }

  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 + -