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

📄 countdis.java

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

import net.aetherial.gis.our.FrameOur;
import java.io.File;
import java.io.IOException;
import net.aetherial.gis.surface.CreateFile;
import org.w3c.dom.Node;
import net.aetherial.gis.surface.ItemValue;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2004</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class CountDis {
  FrameOur fo = null;
  java.text.DecimalFormat df = new java.text.DecimalFormat("#.0000000");
  private String allN = "";
  private double allDis = 0.0;
  private String grade = "";
  private double allAlreadyDone = 0.0;
  public CountDis() {
  }

  public CountDis(FrameOur fo) {
    this.fo = fo;
  }

  public void countAllFile(String inputDirectory, String outputDirectory) {
    /*
         在inputDirectory文件夹下的所有文件都会被计算(不包括目录下面的目录)
         计算结果输出到outputDirectory
     */
    String n = "";
    File f = new File(inputDirectory);
    File[] all = f.listFiles();
    String filename = "";
    for (int i = 0; i < all.length; i++) {
      if(all[i].isDirectory()){
        continue;
      }
      filename = all[i].getName();
      fo.openFile(all[i]);
      this.allN = this.allN + this.getRidOfSuffix(filename) + ":";
      n = this.countLicheng();
      this.savedFile(outputDirectory, filename, n);
      fo.reset();
    }
    this.allN = this.allN + "总计:" + this.allDis + "M = " + (this.allDis / 1000) + "KM\r\n"
        +"待建里程总计:" + (allDis - allAlreadyDone) + "M = " + ((this.allDis - allAlreadyDone) / 1000) + "KM\r\n";
    this.savedFile(outputDirectory, "总", this.allN);
  }

  public void setGrade(String grade) {
    this.grade = grade;
  }

  private void savedFile(String outputDirectory, String fileName,
                         String content) {
    File cff = new File(outputDirectory + this.getRidOfSuffix(fileName) +
                        "里程计算.txt");
    try {
      cff.createNewFile();
    }
    catch (IOException ex) {
    }
    CreateFile cf = new CreateFile(cff);
    cf.memoryToFile(content);
  }

  String countLicheng() {
    String n = "";
    double dis = 0.0;
    double alreadyDone = 0.0;
    double distemp = 0.0;
    int[] tracks = ItemValue.getPosition("track");
    Node node = null;
    for (int i = 0; i < tracks.length; i++) {
      node = ItemValue.getTracks(tracks[i]);
      if (ItemValue.getTracksName(node).equals("ACTIVE LOG")) {
        System.out.println("发现:ACTIVE LOG,不计算");
      }
      else {
        if (this.isRequiredGrade(node)) {
          distemp = ItemValue.getTracksDistance(node);
          if (distemp > 100000000) {
            distemp = 0.0;
          }
          dis = dis + distemp;

            if ("水泥".equals(ItemValue.getTracksType(node)) ||
                "油路".equals(ItemValue.getTracksType(node))) {
              alreadyDone += distemp;
            }else if(!"村道".equals(ItemValue.getTracksGrade(node)) && !"乡道".equals(ItemValue.getTracksGrade(node))){
              alreadyDone += distemp;
            }

          n = n + ItemValue.getTracksName(node) + "  " + df.format(distemp) +
              "M " + ItemValue.getTracksGrade(node) + " " +
              ItemValue.getTracksType(node) + " \r\n";
        }
      }
    }
    this.allDis = this.allDis + dis;
    this.allAlreadyDone += alreadyDone;
    n = n + "总里程:  " + df.format(dis) + "M";
    this.allN = this.allN + "  总里程 " + df.format(dis) + "M";
    if("村道".equals(ItemValue.getTracksGrade(node)) || "乡道".equals(ItemValue.getTracksGrade(node))){

      n += "   待建里程:  " + df.format(dis - alreadyDone) + "M";
      this.allN += "   待建里程:  " + df.format(dis - alreadyDone) + "M";
    }
    n += "\r\n\r\n";
    this.allN += "\r\n";
    return n;
  }

  private boolean isRequiredGrade(Node node) {
    if (ItemValue.getTracksGrade(node).equals(this.grade)) {
        System.out.println("符合\"" + this.grade + "\"的道路有:" +
                           ItemValue.getTracksName(node));
    }
    return true;
  }

  private String getRidOfSuffix(String fileName) { //去除后缀名
    return fileName.replaceAll(".gps", "");
  }

  private String addSuffix(String fileName) { //添加后缀名
    if (fileName.indexOf(".gps") == -1) {
      return fileName + ".gps";
    }
    else {
      return fileName;
    }
  }

  public static void main(String[] args) {
    CountDis countdis = new CountDis();
  }
}

⌨️ 快捷键说明

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