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

📄 repeatld.java

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

import java.io.File;
import net.aetherial.gis.our.FrameOur;
import java.util.Vector;
import net.aetherial.gis.surface.ItemValue;
import org.w3c.dom.Node;
import net.aetherial.gis.publicuse.NodeArrayOper;
import net.aetherial.gis.output.toLd.cut.CutByNode;
import net.aetherial.gis.output.toLd.repeate.*;
import java.io.*;
import net.aetherial.gis.output.toLd.bianma.BmAtRepeate;

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

  private String inputPath = "";
  private String outputPath = "";
  /**
   * 第几次处理
   */
  private static int chuliCishu = 0;
  private FrameOur fo = null;
  public RepeatLd() {

  }

  public void toRepeatFile() {
    /**
     * 将目标文件夹下存在和源文件同名的文件删除
     */
    FileOper fileOper = new FileOper();
    fileOper.setOutputPath(this.outputPath);
    fileOper.scanAllSourceFile(this.inputPath);
    fileOper.deleteTargetExistFile();

    FindMultiTrk fm = new FindMultiTrk();
    fm.setFo(this.fo);
    File[] mtFile = fm.getMultiTrackFile(this.inputPath);
    File[] hisFiles = null;
    LinkJudge lj = null;
    PartTrack[] pt = null;
//    File tempFile = null;
    TrackKeepAndDel keepdel = new TrackKeepAndDel();
    Vector newNodetoKeep = null;
    if (mtFile == null) {
      return;
    }
    for (int i = 0; i < mtFile.length; i++) {

//      System.out.println("运算多航迹的文件" + mtFile[i].getName());
      if (this.chuliCishu == 1) {
        hisFiles = fm.getAllExceptThis(mtFile[i]);
      }
      else {
        hisFiles = fm.getGradeMore_NumberLess_File(mtFile[i]);
      }

      for (int j = 0; hisFiles != null && j < hisFiles.length; j++) {

        lj = new LinkJudge();
        lj.setFo(this.fo);
        mtFile[i] = getDueledFile(mtFile[i]);
//        System.out.println("mtFile["+i+"]" + mtFile[i].getAbsolutePath());
        lj.createPartTrack(mtFile[i]);
        pt = lj.getPt();
//        if ((pt == null)||(pt.length < 2)) {
//          break;
//        }
        if ( (pt == null)) {
          System.out.println("mtFile.length = " + mtFile.length);
          System.out.println("mtFile[" + i + "].pt == null");
          break;
        }

        if ( (pt.length < 2)) {
          break;
        }

        keepdel.keepPrimal();
//        keepdel.printPrimalVector("RepeatLD.toRepeatFile(),Line 62");
        hisFiles[j] = getDueledFile(hisFiles[j]);

        this.fo.openFile(hisFiles[j]);

        System.out.println("运算和" + mtFile[i].getName() + "文件等级高\\编号小的文件:" +
                           hisFiles[j].getName());
        newNodetoKeep = this.getNewTrk(pt);
        if (newNodetoKeep.size() > 0) {
          System.out.println("发现和" + mtFile[i].getName() + "有重复航迹的文件:" +
                             hisFiles[j].getName());
          this.printMemoryData();
//          keepdel.printPrimalVector("RepeatLD.toRepeatFile(),Line 72");
          keepdel.addKeepNode_to_PrimalTrks(newNodetoKeep);
//          keepdel.printPrimalVector("RepeatLD.toRepeatFile(),Line 74");
          this.printNodePos(newNodetoKeep);

          this.initBinama(keepdel, newNodetoKeep);

          this.saveTwoFile(keepdel, hisFiles[j], mtFile[i]);

        }
//        else {
//          keepdel.thirdDeleteNodes();
//          keepdel.reset();
//          keepdel.keepPrimal();
//        }
        fo.reset();
        keepdel.reset();
      }
//      keepdel.thirdDeleteNodes();
//      keepdel.reset();
//      try {
//        tempFile = new File(this.outputPath +
//                            this.getleft(mtFile[i].getAbsolutePath(),
//                                         this.inputPath));
//        tempFile.getParentFile().mkdirs();
//        if (tempFile.exists()) {
//          tempFile.delete();
//        }
//        this.fo.saveFile(tempFile);
//      }
//      catch (Exception ex) {
//        System.err.println(ex.getMessage());
//      }

      this.fo.reset();
    }
    this.deleteTempFiles();
    fileOper.copyLeftToTarget(this.fo);
  }

  private void deleteTempFiles() {
    File tempFile = newFile(this.outputPath + "tempory\\temp.gps");
    try {
      tempFile.delete();
      tempFile.getParentFile().delete();
    }
    catch (Exception ex) {
    }
  }

  private void saveTwoFile(TrackKeepAndDel keepdel, File hisFile, File mtFile) {
    File tempFile = newFile(this.outputPath + "tempory\\temp.gps");
    if (tempFile.exists()) {
      tempFile.delete();
    }

    File outputCompareFile = null, primalFile = null;
    try {
      outputCompareFile = newFile(this.outputPath +
                                  this.getleft(hisFile.getAbsolutePath(),
                                               this.inputPath));
    }
    catch (Exception ex1) {
      outputCompareFile = hisFile;
    }
    try {
      primalFile = newFile(this.outputPath +
                           this.getleft(mtFile.getAbsolutePath(),
                                        this.inputPath));
    }
    catch (Exception ex) {
      primalFile = mtFile;
    }

    this.fo.saveFile(tempFile);
    keepdel.keepPrimalID();
    keepdel.firstDeleteNodes();
    this.fo.saveFile(outputCompareFile);
    System.out.println("  outputCompareFile:" +
                       outputCompareFile.getAbsolutePath());
    this.fo.reset();
    this.fo.openFile(tempFile);
    keepdel.secondDeleteNodes();
    this.fo.saveFile(primalFile);
    System.out.println("  primalFile:" + primalFile.getAbsolutePath());
//    return primalFile;
  }

  private Vector getNewTrk(PartTrack[] pt) {
    FindLackLd fl = null;
    CutByNode cut = null;
    Vector vc = new Vector();
    for (int i = 0; i < pt.length; i++) {
      for (int j = 0; j < pt.length; j++) {
        if (i < j) {
          fl = new FindLackLd();
          fl.setPtFirst(pt[i]);
          fl.setPtLast(pt[j]);
          fl.setTrks(ItemValue.getTracks());
          fl.getLackNode();
          cut = new CutByNode();
          cut.setTrk(fl.getFitNode());
//          System.out.println("!!!!!!!!!!!!!!!" +
//                             ItemValue.getTracksNumber(fl.getFitNode()));
          cut.setFitPointA(fl.getFitPointA());
          cut.setFitPointB(fl.getFitPointB());
          cut.createNewTrks();
          if (cut.getTrk_Mid() != null) {
            vc.add(cut.getTrk_Mid());
          }

        }
      }
    }
    return vc;
  }

  private void initBinama(TrackKeepAndDel keep, Vector newNode) {
    BmAtRepeate bianma = new BmAtRepeate();
    bianma.initBianmaAppointment(keep.getPrimalFileTrks());
    bianma.initBianmaAppointment(keep.getCompareFileTrks());
    Node[] trks = ItemValue.getTracks();
    for (int i = 0; trks != null && i < newNode.size(); i++) {
      try {
        bianma.correctRepeateBianma( (Node) newNode.get(i), trks[0]);
      }
      catch (Exception ex) {
        System.out.println("Error in bianma.correctRepeateBianma");
      }
    }
  }

  private void printMemoryData() {
    System.out.println("打印内存数据:......");
    Node[] all = ItemValue.getTracks();
    for (int i = 0; all != null && i < all.length; i++) {
      System.out.println("    Track[" + i + "]: " +
                         ItemValue.getTracksName(all[i]));
    }
  }

  private void printNodePos(Vector node) {

    Node[] all = ItemValue.getTracks();
    for (int i = 0; all != null && i < all.length; i++) {
      if (node.indexOf(all[i]) != -1) {
        System.out.println("    应保存在原始文件的航迹位于:Track[" + i + "]: ");
      }
    }
  }

  /**
   * 如果比较的文件被处理过的话,应该返回的是比较操作后的文件
   */
  private File getDueledFile(File hisFile) {
    File outputCompareFile = null;
    try {
      outputCompareFile = newFile(this.outputPath +
                                  this.getleft(hisFile.getAbsolutePath(),
                                               this.inputPath));
      if (outputCompareFile.exists()) {
        return outputCompareFile;
      }
      else {
        return hisFile;
      }
    }
    catch (Exception ex1) {
      return hisFile;
    }

  }

  private File newFile(String filePath) {
    File f = new File(filePath);
    if (!f.exists()) {
      f.getParentFile().mkdirs();
    }
    return f;
  }

  private String getleft(String rex, String replacement) throws Exception {
    if (rex.indexOf(replacement) == -1) {
      throw new Exception("字符不匹配!");
    }
    else {
      return rex.substring(replacement.length(), rex.length());
    }
  }

  public static void main(String[] args) {
    RepeatLd rd = new RepeatLd();
    rd.setFo(new FrameOur());
    ItemValue.setShowDialogMessage(false);
    rd.setInputPath(args[0]);
    rd.setOutputPath(args[1]);
    rd.toRepeatFile();
  }

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

  public void setOutputPath(String outputPath) {
    this.outputPath = outputPath;
  }

  public void setInputPath(String inputPath) {
    this.inputPath = inputPath;
  }

  public static void setChuliCishu(int chuliCishu) {
    RepeatLd.chuliCishu = chuliCishu;
  }
}

⌨️ 快捷键说明

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