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

📄 txtelement.java

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

import org.w3c.dom.Node;
import java.io.File;
import net.aetherial.gis.our.FrameOur;
import net.aetherial.gis.surface.ItemValue;
import java.util.Vector;
import net.aetherial.gis.output.toTable.readglj.LdRow;
import net.aetherial.gis.output.toTable.readglj.ReadAll;
import net.aetherial.gis.publicuse.track.ConcatenatedTrack;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2004</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class TxtElement {
  private static final String NORTH_TO_SOUTH = "北 -> 南";
  private static final String SOUTH_TO_NORTH = "南 -> 北";
  private static final String EAST_TO_WEST = "东 -> 西";
  private static final String WEST_TO_EAST = "西 -> 东";

  FrameOur fo = null;
  private double licheng = 0;
  Vector glj_luduans = new Vector();
  LdRow ld = null;
  private String number = "";
  private String name = "";
  private String qidianName = "";
  private String zhidianName = "";
  private String fangxiang = "";
  private String shixianName = "";
  private String xiangzhen = "";
  private String[] guanjiandian = null;
  File thisFile = null;
  public TxtElement(FrameOur fo, File luxian) {
    this.setFrameOur(fo);
    thisFile = luxian;

  }

  public void getText(){

    this.fo.openFile(thisFile);
//    this.getText();


    Node[] trks = ItemValue.getTracks();
    this.getLicheng(trks);
//    this.getQidianZhidian(trks);
    Vector conTrks = ConcatenatedTrack.addTracks(trks);
    LuxianNodes nodes = new LuxianNodes(conTrks);
    nodes.intNodes();
    this.guanjiandian = nodes.getNodesName();
    this.xiangzhen = this.getXiangzhen(trks);
    this.getNumber(trks);
    try {
      this.shixianName = this.getShiXian();
    }
    catch (Exception ex) {
    }

    this.fo.reset();
    this.glj_luduans = null;
  }

  public String toString(){
    /**
     * 市	县	乡镇	路线代码	路线简称	里程
     * 路线起点名称	路线节点	路线节点	路线节点	路线节点	路线止点名称	是否与年报方向吻合	年报路线走向
     */
    String n = "";
    n += this.shixianName + "\t" + this.xiangzhen + "\t";
    n += number + "\t";
    n += this.name + "\t";
    n += this.licheng + "\t";
    for (int i = 0; i < this.guanjiandian.length; i++) {
      n += getNewString(this.guanjiandian[i]) + "\t";
    }
    return n;
  }

  private String getXiangzhen(Node[] trks){
    String xiangzhen = "";
    for (int i = 0; trks != null && i < trks.length; i++) {
      xiangzhen = ItemValue.getTracksT3(trks[i]).trim();
      if(! (xiangzhen.equals(""))) {
        return xiangzhen;
      }
    }
    return "";
  }

  private String getNewString(String str){
    if (str.trim().equals("null")) {
      return "";
    }else{
      return str;
    }
  }

  private String getShiXian() throws Exception{
    String filePath = this.thisFile.getAbsolutePath();
    int zl_pos = filePath.lastIndexOf("整理完毕");
    File xian = new File(filePath.substring(0,zl_pos));
    return xian.getParentFile().getName() + "\t" + xian.getName();
  }
  private void getLicheng(Node[] trks) {
//    Node[] trks = ItemValue.getTracks();
    for (int i = 0; trks != null && i < trks.length; i++) {
      this.licheng += ItemValue.getTracksDistance(trks[i]) / 1000;
    }
  }

  private void getQidianZhidian(Node[] trks) {
    Vector conTrks = ConcatenatedTrack.addTracks(trks);
    if (conTrks.size() == 1) {
      ConcatenatedTrack contrk = (ConcatenatedTrack) conTrks.get(0);
      Node firstWaypoint = getNearWaypoint(contrk.getFirstTrackPoint());
      Node lastWaypoint = getNearWaypoint(contrk.getLastTrackPoint());
      Node firstTrackpoint = contrk.getFirstTrackPoint();
      Node lastTrackpoint = contrk.getLastTrackPoint();
      if (firstWaypoint != null) {
        this.qidianName = ItemValue.getWaypointName(firstWaypoint);
      }
      if (lastWaypoint != null) {
        this.zhidianName = ItemValue.getWaypointName(lastWaypoint);
      }
      try {
        this.fangxiang = this.getFangxiang(firstTrackpoint, lastTrackpoint);
        System.out.println(this.fangxiang);
      }
      catch (Exception ex) {
      }
    }
  }

  private String getFangxiang(Node first, Node last) throws Exception {
    double f_x = Double.parseDouble(ItemValue.getTracksPointX(first));
    double f_y = Double.parseDouble(ItemValue.getTracksPointY(first));
    double l_x = Double.parseDouble(ItemValue.getTracksPointX(last));
    double l_y = Double.parseDouble(ItemValue.getTracksPointY(last));
    double x_diff = l_x - f_x;
    double y_diff = l_y - f_y;
    System.out.println("x_diff:" + x_diff + ",y_diff:" + y_diff);
    if (x_diff == 0 && y_diff != 0) {
      if (y_diff > 0) {
        return this.SOUTH_TO_NORTH;//南 -> 北
      }
      else {
        return this.NORTH_TO_SOUTH;
      }
    }
    else if (x_diff != 0 && y_diff == 0) {
      if (x_diff > 0) {
        return this.WEST_TO_EAST;
      }
      else {
        return this.EAST_TO_WEST;
      }
    }
    else if (x_diff == 0 && y_diff == 0) {
      return "";
    }
    else {
      if (x_diff > 0 && y_diff > 0) { //西南 - 东北
        if (x_diff / y_diff >= 1) {
          return this.WEST_TO_EAST;
        }
        else {
          return this.SOUTH_TO_NORTH;//南 -> 北
        }
      }
      else if (x_diff > 0 && y_diff < 0) { //西北 - 东南
        if (Math.abs(x_diff / y_diff) >= 1) {
          return this.WEST_TO_EAST;
        }
        else {
          return this.NORTH_TO_SOUTH;
        }

      }
      else if (x_diff < 0 && y_diff > 0) { //东南 - 西北
        if (Math.abs(x_diff / y_diff) >= 1) {
          return this.EAST_TO_WEST;
        }
        else {
          return this.SOUTH_TO_NORTH;//南 -> 北
        }

      }
      else if (x_diff < 0 && y_diff < 0) { //东北 - 西南
        if (Math.abs(x_diff / y_diff) >= 1) {
          return this.EAST_TO_WEST;
        }
        else {
          return this.NORTH_TO_SOUTH;
        }

      }

      else {
        return "";
      }
    }
  }

  private Node getNearWaypoint(Node trackPoint) {
    Node[] wpts = ItemValue.getWaypoint();
    double distance = 1000;
    Node temp = null;
    for (int i = 0; wpts != null && i < wpts.length; i++) {
      try {
        if (distance > this.getDis(wpts[i], trackPoint)) {
          distance = this.getDis(wpts[i], trackPoint);
          temp = wpts[i];
        }
      }
      catch (Exception ex) {
      }
    }
    return temp;
  }

  private double getDis(Node wpt, Node trackpoint) throws Exception {
    double wpt_x = Double.parseDouble(ItemValue.getWaypointX(wpt));
    double wpt_y = Double.parseDouble(ItemValue.getWaypointY(wpt));
    double tp_x = Double.parseDouble(ItemValue.getTracksPointX(trackpoint));
    double tp_y = Double.parseDouble(ItemValue.getTracksPointY(trackpoint));
    return Math.sqrt( (wpt_x - tp_x) * (wpt_x - tp_x) +
                     (wpt_y - tp_y) * (wpt_y - tp_y));
  }

  private void getNumber(Node[] trks) {
    if (trks != null) {
      LdRow ldrow = null;
      String gpsNumber = ItemValue.getTracksNumber(trks[0]).trim().toUpperCase();
      for (int i = 0; glj_luduans != null && i < glj_luduans.size(); i++) {
        ldrow = (LdRow) glj_luduans.get(i);
        if (ldrow.getLxNumber().toUpperCase().indexOf(gpsNumber) != -1) {
          this.number = ldrow.getLxNumber().toUpperCase();
          this.name = ldrow.getLxName();
          break;
        }
      }
      if (this.number.trim().equals("")) {
        this.number = this.name = gpsNumber;
      }
    }
  }

  public static void main(String[] args) {
    TxtElement txtelement = new TxtElement(null, null);
  }

  public void setFrameOur(FrameOur fo) {
    this.fo = fo;
  }

  public void setGlj_luduans(Vector glj_luduans) {
    this.glj_luduans = glj_luduans;
  }
}

⌨️ 快捷键说明

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