work.java

来自「基于Java的地图数据管理软件。使用MySQL数据库管理系统。」· Java 代码 · 共 497 行

JAVA
497
字号
package net.aetherial.gis.jiaotongbu.outputJTB.txtOutput.work;

import net.aetherial.gis.jiaotongbu.outputJTB.txtOutput.view.
    FrameToJTBInterface;
import javax.swing.JOptionPane;
import net.aetherial.gis.jiaotongbu.outputJTB.txtOutput.view.scan.ScanPath;
import java.io.File;
import org.w3c.dom.Node;
import net.aetherial.gis.jiaotongbu.outputJTB.txtOutput.module.colligate.Adder;
import net.aetherial.gis.jiaotongbu.outputJTB.txtOutput.module.colligate.
    XiangzhenJiBen;
import net.aetherial.gis.surface.ItemValue;
import net.aetherial.gis.jiaotongbu.outputJTB.txtOutput.module.gpsdata.ScanFile;
import net.aetherial.gis.jiaotongbu.outputJTB.txtOutput.module.colligate.
    XiangzhenTongDa;
import net.aetherial.gis.jiaotongbu.outputJTB.txtOutput.module.gpsdata.
    ReadGPSFile;
import net.aetherial.gis.our.FrameOur;
import net.aetherial.gis.jiaotongbu.outputJTB.txtOutput.module.gpsdata.tongda.
    GanxianTrack;
import net.aetherial.gis.jiaotongbu.outputJTB.txtOutput.module.colligate.
    JianzhicunJiBen;
import net.aetherial.gis.jiaotongbu.outputJTB.txtOutput.module.txt.Jzcjbqk;
import net.aetherial.gis.jiaotongbu.outputJTB.txtOutput.module.colligate.
    JianzhicunTongDa;
import net.aetherial.gis.jiaotongbu.outputJTB.txtOutput.module.gpsdata.lxld.lx.
    TrackNearBE;
import net.aetherial.gis.jiaotongbu.outputJTB.txtOutput.module.gpsdata.bianma.
    RoadBianma;
import net.aetherial.gis.jiaotongbu.outputJTB.txtOutput.module.colligate.Luxian;
import net.aetherial.gis.jiaotongbu.outputJTB.txtOutput.module.gpsdata.
    DeleteRepeateWpt;
import net.aetherial.gis.jiaotongbu.output.publicuse.Item;
import java.util.Enumeration;
import java.util.Vector;
import net.aetherial.gis.jiaotongbu.outputJTB.txtOutput.module.txt.ql;
import java.text.DecimalFormat;
import net.aetherial.gis.jiaotongbu.outputJTB.txtOutput.module.colligate.QSD;
import net.aetherial.gis.jiaotongbu.outputJTB.txtOutput.module.colligate.Luduan;
import net.aetherial.gis.table.WuWei;
import net.aetherial.gis.dataType.WptType;
import java.io.PrintStream;
import net.aetherial.gis.jiaotongbu.outputJTB.txtOutput.module.gpsdata.DeleteFarAwayWaypoint;

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

  private FrameToJTBInterface fi = null;
  private ScanPath scan = null;

  /**
   * 确认的路径
   */
  private String pathArray = "";
  private String pathWanbi = "";
  protected String[] pathBubao = null;
  protected String pathOut = "";

  private boolean[] selectedItem = null;

  protected boolean isError = false;

  protected ScanFile scanGPS = null;

  private FrameOur fo = null;
  public Work(FrameToJTBInterface fi, ScanPath scan) {
    this.fi = fi;
    this.scan = scan;
    this.setPath();
    this.scanGPS = new ScanFile(this.pathWanbi);
    setSelectedItem();
    Item.setShiName(fi.getShi());
    Item.setXianName(fi.getXian());

//    this.checkPath();
  }

  public Work(String baseDir, String shi, String xian) {
    ScanPath scan = new ScanPath();
    FrameOur fo = new FrameOur();
    FrameToJTBInterface fi = new FrameToJTBInterface(fo);

    scan.setPathArray(baseDir + "\\array\\");
    scan.setPathBubao(baseDir + "\\补报表格\\");
    scan.setPathOut(baseDir + "\\部接口\\");
    scan.setPathWanbi(baseDir + "\\整理完毕\\");

    pathArray = baseDir + "\\array\\";
    pathWanbi = baseDir + "\\整理完毕\\";
    pathOut = baseDir + "\\部接口\\";
    pathBubao = scan.getPathsBaobiaosString();

    this.scanGPS = new ScanFile(this.pathWanbi);
    Item.setShiName(shi);
    Item.setXianName(xian);
    ItemValue.setArrayPath(this.pathArray);
  }

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

  /**
   * 设置 路径
   */
  private void setPath() {
    pathArray = this.fi.getTable().getPathArray();
    pathWanbi = this.fi.getTable().getPathWanbi();
    pathBubao = this.scan.getPathsBaobiaosString();
    pathOut = this.fi.getTable().getPathOut();
    ItemValue.setArrayPath(this.pathArray);
  }

  /**
   * 设置 将要生成的文件
   * @param item boolean[]
   */
  private void setSelectedItem() {
    this.selectedItem = this.fi.getFunctionSelected();
  }

  public void runWithoutPrompt() {
    checkPath();
    if (isError) {
      return;
    }

    readGPSFile();

    try {
      fillJZC();
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
    createTableXiangzhen();
    createTableJianzhicunJB();
    createLuxian();
    createLuDuan();
    createQSD();
    createTableXiangzhenTD();
    createTableJianzhicunTD();

    clearGPSRead();
    ResetValue.resetValue();
  }

  protected void fillJZC() throws Exception{
    Node[] wpts = ItemValue.getWaypoint();
    WuWei array = new WuWei();
    String[] jzcNames = array.wuwei_cun;
    String[] xiangZhenNames = array.wuchen_xiangzhen;
    String name = "", type = "";
    Vector yiLou = new Vector();
    Vector xiangZhen = new Vector();
    boolean found = false;
    Node[] jzcWpts = ItemValue.getXingZCInWaypoint(wpts);
    System.out.print("开始检查遗漏的建制村...");
    String jzcName = "";
    String shortName = "";
    for (int i = 0; i < jzcNames.length; i++) {

      jzcName = jzcNames[i];
      shortName = jzcName.length() < 3 ? jzcName : jzcName.
          replaceAll("社区", "").
          replaceAll("社居委", "").
          replaceAll("街道", "").
          replaceAll("村支部", "").
          replaceAll("村委会", "").
          replaceAll("村", "").
          replaceAll("居委会", "");

      found = false;
      for (int j = 0; jzcWpts != null && j < jzcWpts.length; j++) {
        name = ItemValue.getWaypointName(jzcWpts[j]);
//      type = ItemValue.getWaypointKP(jzcWpts[j]);
        if (name.indexOf(shortName) == 0) {
//        System.out.println("发现 "+name+" 匹配 "+shortName);
        String pos = ItemValue.getWaypointX(jzcWpts[j]) + "|" +
                  ItemValue.getWaypointY(jzcWpts[j]);
         ItemValue.jzcZuoBiao.put(xiangZhenNames[i]+jzcName,pos)     ;
          found = true;
          break;
        }
      }
      if (!found) {
        yiLou.add(jzcNames[i]);
        xiangZhen.add(array.wuchen_xiangzhen[i]);
      }
    }
    int notFound = 0;
    java.io.PrintStream bo = new PrintStream(new java.io.FileOutputStream(new java.io.File(this.pathOut+"\\未标注的建制村.txt")));
    bo.println(""+Item.shiName+" "+Item.xianName);
    for (int i = 0; i < yiLou.size(); i++) {
      found = false;
      jzcName = (String) yiLou.get(i);
      shortName = jzcName.length() < 3 ? jzcName :
          jzcName.replaceAll("社区", "").
          replaceAll("社居委", "").
          replaceAll("街道", "").
          replaceAll("村支部", "").
          replaceAll("村委会", "").
          replaceAll("村", "").
          replaceAll("居委会", "");
      System.out.print("搜索 " + jzcName + " ==> ");
      for (int j = 0; j < wpts.length; j++) {
        name = ItemValue.getWaypointName(wpts[j]);
        type = ItemValue.getWaypointKP(wpts[j]);
        if (name.indexOf(shortName) == 0 && type.length() > 1 && "桥梁|隧道|涵洞|渡口".indexOf(type) < 0) {
          ItemValue.setWaypointKP(wpts[j], WptType.W1XingZhengCun);
          ItemValue.setWaypointName(wpts[j], jzcName + "村委会");
          found = true;
          String pos = ItemValue.getWaypointX(wpts[j]) + "|" +
                  ItemValue.getWaypointY(wpts[j]);
         ItemValue.jzcZuoBiao.put(xiangZhen.get(i)+jzcName,pos)     ;

          break;
        }
      }
      if (!found){
        notFound ++;
        bo.println((String) xiangZhen.get(i) + "\t" + jzcName);
        System.out.println(jzcName + " 没找到合适的航点,请手工标注");
      }
    }
    System.out.println("共遗漏" + notFound + "个建制村需要手工标注,内容在文件:\n"+this.pathOut+"\\未标注的建制村.txt");

    bo.close();
    System.out.println("检查遗漏的建制村操作结束!...");
  }

  public void run() {

    this.checkPath();
    /**
     * 如果出现错误,程序将运行到这里为止
     */
    if (this.isError) {
      return;
    }
    this.readGPSFile();

    try {
      fillJZC();
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
    /**
     * 生成路线信息
     */
    if (this.selectedItem[0] == true) {
      //      RoadBianma.printBianma();
      this.createTableXiangzhen();
      this.createTableJianzhicunJB();
      this.createLuxian();
    }

    /**
     * 生成路段信息
     */
    if (this.selectedItem[1] == true) {
      createLuDuan();
    }
    /**
     * 生成桥梁信息
     */
    if (this.selectedItem[2] == true) {
      createQSD();
    }
    /**
     * 生成隧道信息
     */
    if (this.selectedItem[3] == true) {
      //      RoadBianma.printBianma();
//              this.createLuxian();
    }
    /**
     * 生成渡口信息
     */
    if (this.selectedItem[4] == true) {
      //      RoadBianma.printBianma();
//          this.createLuxian();
    }

    /**
     * 制作乡镇基本信息
     */
    if (this.selectedItem[5] == true && this.selectedItem[0] != true) {
      this.createTableXiangzhen();
    }
    /**
     * 制作建制村基本信息
     */
    if (this.selectedItem[7] == true && this.selectedItem[0] != true) {
      this.createTableJianzhicunJB();
    }

//    new TrackNearBE(ItemValue.getTracks());

//    LXResume lx = new LXResume();
//    lx.isTracksSameFL();
    /**
     * 制作乡镇通达信息
     */
    if (this.selectedItem[6] == true) {
      this.createTableXiangzhenTD();
    }

    /**
     * 制作建制村通达信息
     */
    if (this.selectedItem[8] == true) {
      createTableJianzhicunTD();
    }

    this.clearGPSRead();
    ResetValue.resetValue();
    JOptionPane.showMessageDialog(this.fi, "程序运行结束", "完成",
                                  JOptionPane.INFORMATION_MESSAGE);
  }

  private void printPath() {
    System.out.println(this.pathArray);
    System.out.println(this.pathWanbi);

    for (int i = 0; i < pathBubao.length; i++) {
      System.out.println(pathBubao[i]);
    }
    System.out.println(this.pathOut);
  }

  /**
   * 检查一下路径有没有错误,包括
   * 1.Array的数组文件是否都存在
   * 2.Array数组的长度是否统一
   * 3.完毕里面是否存在其他类型的文件
   * 4.完毕里面是否按结构分类
   * 5.有没有路径为空
   * 6.保存的文件有没有只读
   */
  protected void checkPath() {
    if (! (this.scanGPS.check())) {
      this.error(this.scanGPS.getErrorString());
    }

  }

  /**
   * 生成乡镇基本信息
   */
  protected void createTableXiangzhen() {

    XiangzhenJiBen xiangzhenjiben = new XiangzhenJiBen(this.pathBubao[0]);
    xiangzhenjiben.setAdder( (new Adder(this.pathBubao[5])).getReadAdder());
    xiangzhenjiben.readAndTranslate();
    xiangzhenjiben.save(new File(pathOut + "Xzjbqk.txt"));
  }

  /**
   * 生成乡镇通达信息
   */
  protected void createTableXiangzhenTD() {
    GanxianTrack.setOverXiang();
    GanxianTrack.setGanxianValue();
    XiangzhenTongDa xiangzhenTongda = new XiangzhenTongDa(this.pathBubao[0],
        this.pathBubao[6]);
    xiangzhenTongda.setAdder( (new Adder(this.pathBubao[5])).getReadAdder());
    xiangzhenTongda.readAndTranslate();
    xiangzhenTongda.save(new File(pathOut + "Xztdqk.txt"));
  }

  private Jzcjbqk[] jzcArray = null;
  /**
   * 生成建制村基本信息
   */
  protected void createTableJianzhicunJB() {
    ItemValue.setArrayPath(this.pathArray);
    JianzhicunJiBen jianzhicunJB = new JianzhicunJiBen(this.pathBubao[1]);
    jianzhicunJB.setAdder( (new Adder(this.pathBubao[5])).getReadAdder());
    jianzhicunJB.readAndTranslate();
    jzcArray = jianzhicunJB.getJianzhicunContentArray();
    jianzhicunJB.save(new File(pathOut + "Jzcjbqk.txt"));
  }

  /**
   * 生成建制村通达信息
   */
  protected void createTableJianzhicunTD() {
    if (this.jzcArray != null) {
      JianzhicunTongDa jzctd = new JianzhicunTongDa();
      jzctd.setAdder( (new Adder(this.pathBubao[5])).getReadAdder());
      jzctd.setJzcjbqk(this.jzcArray);
      jzctd.readAndTranslate();
      jzctd.save(new File(pathOut + "Jzctdqk.txt"));
    }

  }

  /**
   * 生成路线信息
   */
  protected void createLuxian() {
    Luxian lx = new Luxian();
    lx.setAdder( (new Adder(this.pathBubao[5])).getReadAdder());
    lx.getGPSLXData();
    lx.save(new File(pathOut + "Lx.txt"));
  }

  /**
   * 生成路段信息
   */
  protected void createLuDuan() {
    Luduan lx = new Luduan();
    lx.setAdder( (new Adder(this.pathBubao[5])).getReadAdder());
    lx.getGPSLXData();
    lx.save(new File(pathOut + "Ld.txt"));
  }

  /**
   * 生成桥、隧、渡信息
   */
  protected void createQSD() {
    QSD qsd = new QSD();
    qsd.setAdder( (new Adder(this.pathBubao[5])).getReadAdder());
    qsd.setQlxx(this.pathBubao[2]);
    qsd.setSdxx(this.pathBubao[3]);
    qsd.setDkxx(this.pathBubao[4]);
    qsd.getGPSLXData();
    qsd.save(pathOut);
  }

  protected void readGPSFile() {
    Node[] trks = ItemValue.getTracks();
    if (trks == null) {
      ReadGPSFile readGPS = new ReadGPSFile(this.scanGPS.getAllFiles());
      readGPS.setFrameOur(this.fo);
      readGPS.readAll();
    }
    DeleteRepeateWpt dr = new DeleteRepeateWpt();
    dr.cleanRepeateWpt();
//    DeleteFarAwayWaypoint df = new DeleteFarAwayWaypoint();
//    df.deleteFarawayWpt();
//    ItemValue.calculateTrkAndWPT();
  }

  protected void clearGPSRead() {
    this.fo.reset();
  }

  protected void error(String errorMessage) {
    System.out.println(errorMessage);
    this.isError = true;
//    JOptionPane.showMessageDialog(this.fi, errorMessage, "错误",
//                                  JOptionPane.ERROR_MESSAGE);
  }

  public static void main(String[] args) {
    if (args.length < 3) {
      System.out.println("参数太少,无法运算!");
    }

    Work work = null;
    try {
      FrameOur fo = new FrameOur();

//      work = new Work(args[2], args[0], args[1]);安庆市
      work = new Work("D:\\数据备份\\报部数据\\安徽省\\安庆市\\枞阳县", "安庆市", "枞阳县");
      work.setFrameOur(fo);

      work.runWithoutPrompt();
      work.fo.dispose();
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }

    System.exit(0);
//    work.pathArray = ""; //this.fi.getTable().getPathArray();
//    work.pathWanbi = ""; //this.fi.getTable().getPathWanbi();
//    work.pathBubao = work.scan.getPathsBaobiaosString(); //this.scan.getPathsBaobiaosString();
//    work.pathOut = ""; //this.fi.getTable().getPathOut();

  }
}

⌨️ 快捷键说明

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