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

📄 createrupture.java

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

import net.aetherial.gis.surface.ItemValue;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.util.Vector;
import java.util.Hashtable;
import net.aetherial.gis.publicuse.track.TrackDecussate;
import net.aetherial.gis.publicuse.TrackOper;
import net.aetherial.gis.dataType.TrackType;
import net.aetherial.gis.output.toLd.bianma.CreateBianma;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2004</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class CreateRupture {
  public CreateRupture() {
  }

  /**
   * 如果是断头路
   * 得到最近的航迹的航迹
   */
  private Node getNearstTrk(Node trk, Node[] allTrks) {
    Hashtable ht = new Hashtable();
    double minDis = 1000, temp;
    for (int i = 0; trk != null && allTrks != null && i < allTrks.length; i++) {
      if (trk != allTrks[i]) {
        temp = getMinDis(trk, allTrks[i]);
        ht.put("" + temp, allTrks[i]);
        minDis = Math.min(minDis, temp);
      }

    }
    return (Node) ht.get("" + minDis);
  }

  private double getMinDis(Node trk1, Node trk2) {
    Node[] temp = this.getMinDisDoubleTrackPoint(trk1, trk2);
    if (temp != null) {
      return this.getDis(temp[0], temp[1]);
    }
    else {
      return 1000;
    }
  }

  private Node[] getMinDisDoubleTrackPoint(Node trk, Node[] allTrks) {
    if (trk == null || allTrks == null) {
      return null;
    }
    Node trktemp = this.getNearstTrk(trk, allTrks);
    return this.getMinDisDoubleTrackPoint(trktemp, trk);
  }

  private Node[] getMinDisDoubleTrackPoint(Node trk1, Node trk2) {
    NodeList nl1 = ItemValue.getTracksPoint(trk1);
    NodeList nl2 = ItemValue.getTracksPoint(trk2);
    if (nl1 == null || nl2 == null) {
      return null;
    }
    Node tp11 = nl1.item(0), tp12 = nl1.item(nl1.getLength() - 1);
    Node tp21 = nl2.item(0), tp22 = nl2.item(nl2.getLength() - 1);
    Node[] twoPoint = new Node[2];
    double dis1121 = this.getDis(tp11, tp21);
    double dis1122 = this.getDis(tp11, tp22);
    double dis1221 = this.getDis(tp12, tp21);
    double dis1222 = this.getDis(tp12, tp22);
    double minDis = Math.min(Math.min(Math.min(dis1121, dis1122), dis1221),
                             dis1222);
    if (minDis == dis1121) {
      twoPoint[0] = tp11;
      twoPoint[1] = tp21;
    }
    else if (minDis == dis1122) {
      twoPoint[0] = tp11;
      twoPoint[1] = tp22;
    }
    else if (minDis == dis1221) {
      twoPoint[0] = tp12;
      twoPoint[1] = tp21;
    }
    else if (minDis == dis1222) {
      twoPoint[0] = tp12;
      twoPoint[1] = tp22;
    }
    else {
      return null;
    }
    return twoPoint;
  }

  /**
   * 求两点之间的距离
   */
  private double getDis(double xa, double ya, double xb, double yb) {
    return Math.sqrt( (xb - xa) * (xb - xa) + (yb - ya) * (yb - ya));
  }

  /**
   * 求两点之间的距离
   */
  private double getDis(Node tp1, Node tp2) {
    double xa = Double.parseDouble(ItemValue.getTracksPointX(tp1));
    double ya = Double.parseDouble(ItemValue.getTracksPointY(tp1));
    double xb = Double.parseDouble(ItemValue.getTracksPointX(tp2));
    double yb = Double.parseDouble(ItemValue.getTracksPointY(tp2));
    return Math.sqrt( (xb - xa) * (xb - xa) + (yb - ya) * (yb - ya));
  }

  /**
   * 判断指定编码的路线是否是多条航迹
   */
  private boolean isMultiTrack(String trackNumber, Node[] allTrks) {
    int flag = 0;
    for (int i = 0; allTrks != null && i < allTrks.length; i++) {
      if (ItemValue.getTracksNumber(allTrks[i]).trim().equals(trackNumber)) {
        flag++;
      }
    }
    if (flag >= 2) {
      return true;
    }
    else {
      return false;
    }
  }

  /**
   * 判断指定编码的路线是否是多条航迹
   */
  private boolean isMultiTrack(Node trk, Node[] allTrks) {
    String trackNumber = ItemValue.getTracksNumber(trk).trim();
    return this.isMultiTrack(trackNumber, allTrks);
  }

  public boolean isMultiFile() {
    Node[] allTrk = ItemValue.getTracks();
    if (allTrk != null && allTrk.length > 1) {
      return true;
    }
    else {
      return false;
    }
  }

  /**
   * 得到同编码的航迹
   */
  private Vector getSameNumberTrk(String trackNumber, Node[] allTrks) {
    Vector ve = new Vector();
    for (int i = 0; allTrks != null && i < allTrks.length; i++) {
      if (ItemValue.getTracksNumber(allTrks[i]).trim().equals(trackNumber)) {
        ve.add(allTrks[i]);
      }
    }
    return ve;
  }

  /**
   * 判断两条航迹是否相近?
   */
  private boolean isTwoTrkLink(Node trk1, Node trk2) {
    TrackDecussate td = new TrackDecussate();
    td.setTracks(trk1, trk2);
//    System.out.println("判断两条航迹是否连接:" + ItemValue.getTracksName(trk1) + "  &  " +
//                       ItemValue.getTracksName(trk1));
    if (td.isTLink()) {
//      System.out.println("TLink");
      return true;
    }
//    else if (td.isKLink()) {
//      System.out.println("KLink");
//      return true;
//    }
    else if (td.isDecussate()) {
//      System.out.println("Decussate");
      return true;
    }

    else {
      return false;
    }
  }

  /**
   * 判断该路线包含多条路段的情况下
   * 指定的航迹是否独立,即该路线的所有路段均不和该航迹相连
   */
  private boolean isTrkIndependency(Node trk, Node[] allTrk) {
//    Vector sameNumberTrk = this.getSameNumberTrk(ItemValue.getTracksNumber(trk).
//                                                 trim(), allTrk);
    for (int i = 0; allTrk != null && i < allTrk.length; i++) {
      if (allTrk[i] != trk) {
        if (this.isTwoTrkLink(trk, allTrk[i])) {
          return false;
        }
      }

    }
    return true;
  }

  public Node[] isHaveIndependency() {
    Node[] allTrk = ItemValue.getTracks();
    Vector independ = new Vector();
    for (int i = 0; allTrk != null && i < allTrk.length; i++) {
      if (isTrkIndependency(allTrk[i], allTrk)) {
        independ.add(allTrk[i]);
      }
    }
    Node[] temp = new Node[independ.size()];
    independ.copyInto(temp);
    return temp;
  }

  private Node createNewTrack(Node independTrk, Node[] allTrk) {
    Node[] twoPoints = this.getMinDisDoubleTrackPoint(independTrk, allTrk);
    Node newTrk = null;
    if (twoPoints != null) {
      newTrk = ItemValue.createNewTrack(twoPoints, independTrk);
      ItemValue.setTracksType(newTrk, TrackType.RS_D_bad);
      ItemValue.setTracksT5(newTrk, TrackType.Jishu6_Dengwai);
      CreateBianma cb = new CreateBianma();
      ItemValue.setTracks_ld_Number(newTrk, cb.getSameLxsLxLdNewNumber(newTrk));
      cb.setToRupture(newTrk);
      System.out.println("    产生断头路:" + ItemValue.getTracksName(newTrk));
    }
    return newTrk;
  }

  public void createNewTrks() {
    Node[] all = ItemValue.getTracks();
    Vector newAllTrks = new Vector();
    for (int i = 0; all != null && i < all.length; i++) {
      if (this.isTrkIndependency(all[i], all)) {
        newAllTrks.add(createNewTrack(all[i], all));
      }
    }
    this.deleteSameTrack(newAllTrks);
  }

  private void deleteSameTrack(Vector allNewTrks) {
    for (int i = 0; i < allNewTrks.size(); i++) {
      for (int j = i +1; j < allNewTrks.size(); j++) {
        if (i != j) {
          if (isNewTrackSamePoints( (Node) allNewTrks.get(i),
                                   (Node) allNewTrks.get(j))) {
            ItemValue.removeTrack( (Node) allNewTrks.get(j));
          }
          else {

          }
        }
      }
    }
  }

  private boolean isNewTrackSamePoints(Node trk1, Node trk2) {
    NodeList nl1 = ItemValue.getTracksPoint(trk1);
    NodeList nl2 = ItemValue.getTracksPoint(trk2);
    String tp11x = ItemValue.getTracksPointX(nl1.item(0));
    String tp11y = ItemValue.getTracksPointY(nl1.item(0));
    String tp12x = ItemValue.getTracksPointX(nl1.item(1));
    String tp12y = ItemValue.getTracksPointY(nl1.item(1));
    String tp21x = ItemValue.getTracksPointX(nl2.item(0));
    String tp21y = ItemValue.getTracksPointY(nl2.item(0));
    String tp22x = ItemValue.getTracksPointX(nl2.item(1));
    String tp22y = ItemValue.getTracksPointY(nl2.item(1));
    System.out.println("tp11x:" + tp11x + ", tp21x" + tp21x + ", tp11y" + tp11y +
                       ", tp21y" + tp21y);
    System.out.println("tp12x:" + tp12x + ", tp22x" + tp22x + ", tp12y" + tp12y +
                       ", tp22y" + tp22y);
    if (tp11x.equals(tp21x) && tp11y.equals(tp21y) && tp12x.equals(tp22x) &&
        tp12y.equals(tp22y)) {
      return true;
    }
    else if (tp11x.equals(tp21x) && tp12y.equals(tp21y) && tp12x.equals(tp22x) &&
             tp11y.equals(tp22y)) {
      return true;
    }
    else if (tp12x.equals(tp21x) && tp11y.equals(tp21y) && tp11x.equals(tp22x) &&
             tp12y.equals(tp22y)) {
      return true;
    }
    else if (tp12x.equals(tp21x) && tp12y.equals(tp21y) && tp11x.equals(tp22x) &&
             tp11y.equals(tp22y)) {
      return true;
    }
    else {
      return false;
    }
  }

  public static void main(String[] args) {
    CreateRupture createrupture = new CreateRupture();
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -