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

📄 trackdecussate.java

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

import org.w3c.dom.*;
import java.util.Vector;
import net.aetherial.gis.surface.ItemValue;
import net.aetherial.gis.publicuse.TrackOper;
import net.aetherial.gis.our.auto.check.repeattrk.TrackRectangle;
import net.aetherial.gis.garmin.GarminGMLDoc;
import net.aetherial.gis.our.FrameOur;
import java.io.File;
import java.util.Hashtable;
import net.aetherial.gis.output.toLd.cut.CreateNewTP;

/**
 * <p>Title: </p>
 *
 * <p>Description: 判断两条航迹 是否交叉\或者不交叉只是连接</p>
 *
 * <p>Copyright: Copyright (c) 2004</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class TrackDecussate {
  private Node trk1 = null;
  private Node trk2 = null;
  public TrackDecussate() {
  }

  /**
   * 给定航迹1
   */
  public void setTrack1(Node trk) {
    this.trk1 = trk;
  }

  /**
   * 给定航迹2
   */
  public void setTrack2(Node trk) {
    this.trk2 = trk;
  }

  /**
   * 给定两条相互比较的航迹
   */
  public void setTracks(Node trk1, Node trk2) {
    this.trk1 = trk1;
    this.trk2 = trk2;
  }

  /**
   * 是否T字型连接 或者 X型交叉
   * 如果是,返回true
   */
  public boolean isTLinkOrXDecussate() {
    if (this.isTLink()) {
//      System.out.println("XLink!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
//      System.out.println(ItemValue.getTracksName(this.trk1)+" jiaocha "+ ItemValue.getTracksName(this.trk2));
      return true;
    }
    else if (this.isDecussate()) {
      return true;
    }
    else {
      return false;
    }
  }

  /**
   * 判断航迹是否交叉
   */
  public boolean isDecussate() {
    if ( (this.trk1 == null) || (this.trk1 == null)) {
      return false;
    }
    NodeList nl1 = ItemValue.getTracksPoint(this.trk1);
    NodeList nl2 = ItemValue.getTracksPoint(this.trk2);
    if ( (nl1 == null) || (nl2 == null)) {
      return false;
    }
    else {
      for (int i = 0; i < nl1.getLength(); i++) {
        if (i >= nl1.getLength() - 1) {
          break;
        }
        for (int j = 0; j < nl2.getLength(); j++) {
          if (j >= nl2.getLength() - 1) {
            break;
          }
          if (isTrackPointDecussate(nl1.item(i), nl1.item(i + 1), nl2.item(j),
                                    nl2.item(j + 1))) {
            return true;
          }
        }
      }
    }
    return false;
  }

  /**
   * 判断四个航迹点组成的形状是否交叉
   */
  protected boolean isTrackPointDecussate(Node t1p1, Node t1p2, Node t2p1,
                                        Node t2p2) {
    double t1p1_Lon = Double.parseDouble(ItemValue.getTracksPointX(t1p1));
    double t1p1_Lat = Double.parseDouble(ItemValue.getTracksPointY(t1p1));
    double t1p2_Lon = Double.parseDouble(ItemValue.getTracksPointX(t1p2));
    double t1p2_Lat = Double.parseDouble(ItemValue.getTracksPointY(t1p2));
    double t2p1_Lon = Double.parseDouble(ItemValue.getTracksPointX(t2p1));
    double t2p1_Lat = Double.parseDouble(ItemValue.getTracksPointY(t2p1));
    double t2p2_Lon = Double.parseDouble(ItemValue.getTracksPointX(t2p2));
    double t2p2_Lat = Double.parseDouble(ItemValue.getTracksPointY(t2p2));

    double M1 = (t1p2_Lat - t1p1_Lat) / (t1p2_Lon - t1p1_Lon);
    double M2 = (t2p2_Lat - t2p1_Lat) / (t2p2_Lon - t2p1_Lon);
    double lon = (M1 * t1p1_Lon - M2 * t2p1_Lon + t2p1_Lat - t1p1_Lat) /
        (M1 - M2);
    double lat = (M1 * M2 * t1p1_Lon - M2 * t1p1_Lat - M1 * M2 * t2p1_Lon +
                  M1 * t2p1_Lat) / (M1 - M2);
    if ( ( ( (lon >= t1p1_Lon) && (lon <= t1p2_Lon)) ||
          ( (lon <= t1p1_Lon) && (lon >= t1p2_Lon))) &&
        ( ( (lat >= t1p1_Lat) && (lat <= t1p2_Lat)) ||
         ( (lat <= t1p1_Lat) && (lat >= t1p2_Lat)))) {
      if ( ( ( (lon >= t2p1_Lon) && (lon <= t2p2_Lon)) ||
            ( (lon <= t2p1_Lon) && (lon >= t2p2_Lon))) &&
          ( ( (lat >= t2p1_Lat) && (lat <= t2p2_Lat)) ||
           ( (lat <= t2p1_Lat) && (lat >= t2p2_Lat)))) {
        return true;
      }
    }
    return false;
  }

  /**
   * 判断两条航迹是否连接,这种连接包括T字型连接
   */
  public boolean isTLink() {
    NodeList nl1 = ItemValue.getTracksPoint(this.trk1);
    NodeList nl2 = ItemValue.getTracksPoint(this.trk2);
    if ( (nl1 == null) || (nl2 == null)) {
      return false;
    }
    Node t1p1 = nl1.item(0);
    Node t1p2 = nl1.item(nl1.getLength() - 1);
    Node t2p1 = nl2.item(0);
    Node t2p2 = nl2.item(nl2.getLength() - 1);
    double minDis = TrackOper.getDisOfTracksWithPoint(Double.parseDouble(
        ItemValue.getTracksPointX(t1p1)),
        Double.parseDouble(ItemValue.getTracksPointY(t1p1)), this.trk2);
    minDis = Math.min(minDis,
                      TrackOper.getDisOfTracksWithPoint(Double.
        parseDouble(ItemValue.getTracksPointX(t1p2)),
        Double.parseDouble(ItemValue.getTracksPointY(t1p2)),
        this.trk2));
    minDis = Math.min(minDis,
                      TrackOper.getDisOfTracksWithPoint(Double.
        parseDouble(ItemValue.getTracksPointX(t2p1)),
        Double.parseDouble(ItemValue.getTracksPointY(t2p1)),
        this.trk1));
    minDis = Math.min(minDis,
                      TrackOper.getDisOfTracksWithPoint(Double.
        parseDouble(ItemValue.getTracksPointX(t2p2)),
        Double.parseDouble(ItemValue.getTracksPointY(t2p2)),
        this.trk1));
    if (minDis < TrackRectangle.NEAR_DISTANCE * 5) {
      return true;
    }
    return false;
  }

  /**
   * 判断两条航迹是否连接,这种连接包括K字型连接
   */
  public boolean isKLink() {
    NodeList nl1 = ItemValue.getTracksPoint(this.trk1);
    NodeList nl2 = ItemValue.getTracksPoint(this.trk2);
    if ( (nl1 == null) || (nl2 == null)) {
      return false;
    }
    Node tp;
    double minDis;
    for (int i = 0; i < nl1.getLength(); i++) {
      tp = nl1.item(i);
      minDis = TrackOper.getDisOfTracksWithPoint(Double.parseDouble(
          ItemValue.getTracksPointX(tp)),
                                                 Double.parseDouble(ItemValue.
          getTracksPointY(tp)), this.trk2);
      if (minDis < TrackRectangle.NEAR_DISTANCE * 5) {
        return true;
      }

    }

    for (int i = 0; i < nl2.getLength(); i++) {
      tp = nl1.item(i);
      minDis = TrackOper.getDisOfTracksWithPoint(Double.parseDouble(
          ItemValue.getTracksPointX(tp)),
                                                 Double.parseDouble(ItemValue.
          getTracksPointY(tp)), this.trk1);
      if (minDis < TrackRectangle.NEAR_DISTANCE * 5) {
        return true;
      }

    }
    return false;
  }

  /**
   * 得到交叉的航迹点,
   * 返回的是由trk1航迹点
   * 在最终交叉的两个航迹点中选择前一个航迹点
   */
  public Node getDecussateTrackPoint() {
//    Vector ve = new Vector();
    NodeList nl1 = ItemValue.getTracksPoint(this.trk1);
    NodeList nl2 = ItemValue.getTracksPoint(this.trk2);
    if (nl1 == null) {
      return null;
    }
    else if (nl2 == null) {
      return null;
    }

    for (int i = 0; i < nl1.getLength() - 1; i++) {

      for (int j = 0; j < nl2.getLength() - 1; j++) {
        if (this.isTrackPointDecussate(nl1.item(i), nl1.item(i + 1), nl2.item(j),
                                       nl2.item(j + 1))) {
//          System.out.println("交叉********************************");

          double x, y, z, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4;
          double A1, B1, C1, A2, B2, C2, A3, B3, C3, A4, B4, C4;

          x1 = Double.parseDouble(ItemValue.getTracksPointX(nl1.item(i)));
          y1 = Double.parseDouble(ItemValue.getTracksPointY(nl1.item(i)));
          z1 = Double.parseDouble(ItemValue.getTracksPointZ(nl1.item(i)));

          x2 = Double.parseDouble(ItemValue.getTracksPointX(nl1.item(i + 1)));
          y2 = Double.parseDouble(ItemValue.getTracksPointY(nl1.item(i + 1)));
          z2 = Double.parseDouble(ItemValue.getTracksPointZ(nl1.item(i + 1)));

          x3 = Double.parseDouble(ItemValue.getTracksPointX(nl2.item(j)));
          y3 = Double.parseDouble(ItemValue.getTracksPointY(nl2.item(j)));
          z3 = Double.parseDouble(ItemValue.getTracksPointZ(nl2.item(j)));

          x4 = Double.parseDouble(ItemValue.getTracksPointX(nl2.item(j + 1)));
          y4 = Double.parseDouble(ItemValue.getTracksPointY(nl2.item(j + 1)));
          z4 = Double.parseDouble(ItemValue.getTracksPointZ(nl2.item(j + 1)));

          A1 = y2 - y1;
          B1 = x1 - x2;
          C1 = x2 * y1 - x1 * y2;

          A2 = y4 - y3;
          B2 = x3 - x4;
          C2 = x4 * y3 - x3 * y4;

          A3 = z2 - z1;
          B3 = x1 - x2;
          C3 = x2 * z1 - x1 * z2;

          A4 = z4 - z3;
          B4 = x3 - x4;
          C4 = x4 * z3 - x3 * z4;

          x = (B1 * C2 - B2 * C1) / (A1 * B2 - A2 * B1);
          y = (A1 * C2 - A2 * C1) / (A1 * B2 - A2 * B1);
          z = ( -C3 - A3 * x) / B3;
          if (x < 0) {
            x *= -1;
          }
          if (y < 0) {
            y *= -1;
          }
          return ItemValue.insertNewTrackPoint(this.trk2, nl2.item(j + 1),
                                               x + "", y + "", z + "");

        }
      }
    }
    return null;

  }

  public Node getTLinkTrackPoint() {
    NodeList nl1 = ItemValue.getTracksPoint(this.trk1);
    NodeList nl2 = ItemValue.getTracksPoint(this.trk2);
    if ( (nl1 == null) || (nl2 == null)) {
      return null;
    }
    Node t1p1 = nl1.item(0);
    Node t1p2 = nl1.item(nl1.getLength() - 1);
    Node t2p1 = nl2.item(0);
    Node t2p2 = nl2.item(nl2.getLength() - 1);
    double dis1, dis2, dis3, dis4;
    double minDis = dis1 = TrackOper.getDisOfTracksWithPoint(Double.parseDouble(
        ItemValue.getTracksPointX(t1p1)),
        Double.parseDouble(ItemValue.getTracksPointY(t1p1)), this.trk2);
    minDis = Math.min(minDis,
                      dis2 = TrackOper.getDisOfTracksWithPoint(Double.
        parseDouble(ItemValue.getTracksPointX(t1p2)),
        Double.parseDouble(ItemValue.getTracksPointY(t1p2)),
        this.trk2));
    minDis = Math.min(minDis,
                      dis3 = TrackOper.getDisOfTracksWithPoint(Double.
        parseDouble(ItemValue.getTracksPointX(t2p1)),
        Double.parseDouble(ItemValue.getTracksPointY(t2p1)),
        this.trk1));
    minDis = Math.min(minDis,
                      dis4 = TrackOper.getDisOfTracksWithPoint(Double.
        parseDouble(ItemValue.getTracksPointX(t2p2)),
        Double.parseDouble(ItemValue.getTracksPointY(t2p2)),
        this.trk1));
    if (minDis < TrackRectangle.NEAR_DISTANCE * 5) {
      if (minDis == dis1) {
        return this.createTLinkFitNode(t1p1, this.trk2);
      }
      else if (minDis == dis2) {
        return this.createTLinkFitNode(t1p2, this.trk2);
      }
      else if (minDis == dis3) {
        return t2p1;
      }
      else if (minDis == dis4) {
        return t2p2;
      }
    }
    return null;
  }

  private Node createTLinkFitNode(Node trackPoint, Node trk) {
    return (new CreateNewTP()).createNewFootPoint(trackPoint, trk);
  }

  public static void main(String args[]) {
    TrackDecussate td = new TrackDecussate();
    FrameOur fo = new FrameOur();
    fo.openFile(new File("E:\\temp\\S229.gps"));
    Node temp;
    Node[] trks = ItemValue.getTracks();
    for (int i = 0; i < trks.length; i++) {
      for (int j = i + 1; j < trks.length; j++) {
        if (j > i) {
          td.setTrack1(trks[i]);
          td.setTrack2(trks[j]);
          System.out.println("[" + ItemValue.getTracksName(trks[i]) + "] 与 [" +
                             ItemValue.getTracksName(trks[j]) + "]是否X字型交叉:" +
                             td.isDecussate() + ", 是否T字型相交:" + td.isTLink());
          Node tp = td.getDecussateTrackPoint();
//          System.out.println("td.getJiaoChaTrackPoint()" +tp.length);
//          for (int k = 0; k < tp.length; k++) {
          if (tp != null) {

            temp = ItemValue.turnTracksPointToWaypoint(tp);
            ItemValue.setWaypointName(temp, "X交叉");
            //            System.out.println(ItemValue.getTracksPointX().getWaypointName(tp[k]));
            System.out.println(ItemValue.getTracksPointX(tp));
            System.out.println(ItemValue.getTracksPointY(tp));
            System.out.println(ItemValue.getTracksPointZ(tp));
          }
          tp = td.getTLinkTrackPoint();
          if (tp != null) {

            temp = ItemValue.turnTracksPointToWaypoint(tp);
            ItemValue.setWaypointName(temp, "T交叉");
            //            System.out.println(ItemValue.getTracksPointX().getWaypointName(tp[k]));
            System.out.println(ItemValue.getTracksPointX(tp));
            System.out.println(ItemValue.getTracksPointY(tp));
            System.out.println(ItemValue.getTracksPointZ(tp));
          }

        }
//        }
      }

    }
    fo.saveFile(new File("E:\\temp\\S2291.gps"));
    fo.dispose();
    System.exit(0);
  }
}

⌨️ 快捷键说明

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