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

📄 cuttosection.java

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

import org.w3c.dom.*;
import net.aetherial.gis.surface.ItemValue;
import net.aetherial.gis.garmin.GarminGMLDoc;
import net.aetherial.gis.cutAndLink.TempDoc;
import net.aetherial.gis.cutAndLink.CLFrame;
/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2004</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class CutToSection {
  private Node track = null;
  private static int id = 0;
  private int findPoint =0;
  private String trackName = "分割的航迹";
  private Node start = null,end = null;
  private CLFrame clf = null;
  private TempDoc  tc = null;
  public CutToSection() {
  }
  public void setTempDoc(TempDoc tc){
    this.tc = tc;
  }
  public CutToSection(CLFrame clf){
    this.clf = clf;
  }
  private void setString(String s){
    try {
      clf.setJTextAreaText(s+"\n");
    }
    catch (Exception ex) {
    }
  }
  public void setTrack(Node trackNode){
    this.track = trackNode;
  }

  public void setStartEnd(Node start,Node end){
    this.start = start;
    this.end = end;
  }

  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 boolean isWaypointInTwoTrackPointRectangle(Node trackpoint1,Node trackpoint2,Node waypoint){
    if (trackpoint1 == null || trackpoint2 == null || waypoint == null) {
      return false;
    }
    double t1_x = Double.parseDouble(ItemValue.getTracksPointX(trackpoint1));
    double t1_y = Double.parseDouble(ItemValue.getTracksPointY(trackpoint1));
    double t2_x = Double.parseDouble(ItemValue.getTracksPointX(trackpoint2));
    double t2_y = Double.parseDouble(ItemValue.getTracksPointY(trackpoint2));
    double w_x = Double.parseDouble(ItemValue.getWaypointX(waypoint));
    double w_y = Double.parseDouble(ItemValue.getWaypointY(waypoint));

    if ((w_x >t1_x && w_x < t2_x) && (w_y >t1_y && w_y <t2_y)) {
      return true;
    }else if((w_x >t2_x && w_x < t1_x) && (w_y >t1_y && w_y <t2_y)){
      return true;
    }else if((w_x >t1_x && w_x < t2_x)&& (w_y >t2_y && w_y <t1_y)){
      return true;
    }else if((w_x >t2_x && w_x < t1_x) && (w_y >t2_y && w_y <t1_y)){
      return true;
    }else{
      return false;
    }
  }
  private Node getFirstNearpoint(Node track,Node waypoint){
    double distance = 0.0;
    double minDis = 0.5;
    Node minTp = null;
    NodeList nl = ItemValue.getTracksPoint(track);
    for(int i = 0;i<nl.getLength();i++){
      distance = this.getDistance(nl.item(i),waypoint);
      if(minDis>distance){
        minDis = distance;
        if (i+1 < nl.getLength() &&  (isWaypointInTwoTrackPointRectangle(nl.item(i+1),nl.item(i),waypoint))) {
          minTp = nl.item(i+1);
        }else{
          minTp = nl.item(i);
        }

      }
    }
    if(minDis == 0.5){
      this.setString("没有发现与"+ItemValue.getWaypointName(waypoint)+"相近的点!");
      System.out.println("没有发现与"+ItemValue.getWaypointName(waypoint)+"相近的点!");
    }
    return minTp;
  }
  private Node getLastNearpoint(Node track,Node waypoint){
    double distance = 0.0;
    double minDis = 0.5;
    Node minTp = null;
    NodeList nl = ItemValue.getTracksPoint(track);
    for(int i = 0;i<nl.getLength();i++){
      distance = this.getDistance(nl.item(i),waypoint);
      if(minDis>distance){
        minDis = distance;
        if (i-1 >= 0 &&  (isWaypointInTwoTrackPointRectangle(nl.item(i-1),nl.item(i),waypoint))) {
          minTp = nl.item(i-1);
        }else{
          minTp = nl.item(i);
        }

      }
    }
    if(minDis == 0.5){
      this.setString("没有发现与"+ItemValue.getWaypointName(waypoint)+"相近的点!");
      System.out.println("没有发现与"+ItemValue.getWaypointName(waypoint)+"相近的点!");
    }
    return minTp;
  }


  private Node getFirstNode(Node startWaypoint){
    return this.getFirstNearpoint(this.track,startWaypoint);
  }
  private Node getlastNode(Node endWaypoint){
    return this.getLastNearpoint(this.track,endWaypoint);
  }
  private Node[] getCuttedTrackPoint(Node start,Node end){
    this.trackName = this.trackName +"("+ItemValue.getWaypointName(start)+"-"+ItemValue.getWaypointName(end)+")";
    Node s = this.getFirstNode(start);
    Node e = this.getlastNode(end);
    NodeList nl = ItemValue.getTracksPoint(this.track);
    java.util.Vector team = new java.util.Vector();
    boolean findStart = false;
    boolean findEnd = false;
    team.add(start);
    for(int i =0;i<nl.getLength();i++){
      //////////////////////////
      if(findStart == false){
        if(nl.item(i).equals(s)){
          findStart = true;
          //加上一个起点(航点)
          team.add(nl.item(i));
          this.findPoint++;
//          System.out.println("发现起点  || at line 80 in CutToSection");
          this.setString("起点");
        }
      }else{
        team.add(nl.item(i));
//        System.out.println("发现一个点,添加进去  || at line 84 in CutToSection");
         this.setString("发现一个点,添加进去");
         this.findPoint++;
      }
      //////////////////////
      if(nl.item(i).equals(e)){
        findEnd = true;
//        team.add(end);//加上一个终点(航点)
//        System.out.println("到达终点--break  || at line 88 in CutToSection");
        this.setString("到达终点");
        break;
      }
    }
    team.add(end);
    Node[] node = null;
    if(team.size() == 0){
      return null;
    }else{
//      if(findEnd){
        node = new Node[team.size()];
        for (int i = 0; i < node.length; i++) {
          node[i] = (Node) team.get(i);
        }
        return node;
//      }else{
//        return null;
//      }
    }
  }
  public void insertIntoGarminDoc(){

    this.id++;
    Node[] node = this.getCuttedTrackPoint(start,end);
    System.out.println(node.length);
    if(node==null){
      return;
    }else{
      Element e = GarminGMLDoc.addTrack(this.trackName+"(分"+this.id+")",this.track);
      for(int i = 0;i<node.length;i++){
        GarminGMLDoc.addTrackPoint(e,node[i]);
      }
    }
  }

  public Node createNewDocNode(){
    this.id++;
    Node[] node = this.getCuttedTrackPoint(start,end);
    if(this.findPoint<=0){
      node = this.getCuttedTrackPoint(end,start);
    }
    if(node==null){
      return null;
    }else{
      Element e = GarminGMLDoc.addTrack(this.trackName, this.track);
      for (int i = 0; i < node.length; i++) {
        GarminGMLDoc.addTrackPoint(e,node[i]);
      }
      return e.getParentNode();
    }
  }


  public void insertIntoTempDoc(){//添加到CutAndLink.TempDoc.tadded里面去

    this.id++;
    this.trackName = "切"+ItemValue.getTracksName(tc.track);
    if(this.trackName.length()>24){
        this.trackName = "切"+this.id;
      }

    Node[] node = null;
    node = this.getCuttedTrackPoint(start,end);
    if(this.findPoint<=0){
      node = this.getCuttedTrackPoint(end,start);
    }
    if(this.findPoint<=0){
      this.setString("没有发现匹配的点.");
      this.id--;
      return;
    }
    System.out.println(node.length);
    if(node==null){
      return;
    }else{

      Element e = tc.addTrack(this.trackName,tc.track);
      /*
             String number,
                                        String grade, String type,
                                        String width,String structure,
                                        String status,String st1,String st2,
                                        String st3,String st4,String st5,
                                        String st6,String st7

      */
      //Element e = tc.addTrack()
      for(int i = 0;i<node.length;i++){
        tc.addTrackPoint(e,node[i]);
      }
    }
  }

  public static void main(String[] args) {
    CutToSection cs= new CutToSection();
  }
}

class NoElementException extends Exception {
  public NoElementException(){

  }
}



⌨️ 快捷键说明

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