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

📄 wipewaypoint.java

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

import org.w3c.dom.*;
import net.aetherial.gis.surface.ItemValue;
import net.aetherial.gis.dataType.WptType;
/**
 * 此类实现的功能如下:
 * 1.两点同位置,同名
 *   去除掉其中一个
 * 2.两点同位置,不同名
 *   if(有一个是数字名称)
 *      去除掉该数字点
 *   else{
 *      去除任意一点
 *   }
 * 3.两点太近,同名
 *    将其中一个名称清空
 * 4.两点太近,不同名
 *   看看两点名称是否有相同部分,如果有,两点同时去掉该相同部分
 */
public class WipeWaypoint {
  double nearx = 0.008;
  final double neary = 0.008;
  private String info ="";
  private int del =0,emp =0;
  public WipeWaypoint() {
  }
  public void compareWaypoint(Node a,Node b){
    String namea = ItemValue.getWaypointName(a);
    String nameb = ItemValue.getWaypointName(b);
    double lonXa = Double.parseDouble(ItemValue.getWaypointX(a));
    double latYa = Double.parseDouble(ItemValue.getWaypointY(a));
    double lonXb = Double.parseDouble(ItemValue.getWaypointX(b));
    double latYb = Double.parseDouble(ItemValue.getWaypointY(b));
    System.out.println("比较:("+namea+","+nameb+")");
    if(lonXa<lonXb){
      nearx = neary * namea.length();
    }else{
      nearx = neary * nameb.length();
    }

    if(SamePosition(lonXa,latYa,lonXb,latYb)&&(namea.equals(nameb))){//1.两点同位置,同名
      ItemValue.removeWaypoint(b);
      System.out.println("1.两点同位置,同名. delete:"+nameb);
      info = info+ "("+namea+","+nameb+")"+"1.两点同位置,同名. delete:"+nameb+"\n";
      this.del++;
    }else if(SamePosition(lonXa,latYa,lonXb,latYb)&&(!(namea.equals(nameb)))){//2.两点同位置,不同名
      if(this.isNumeric(namea)){
        ItemValue.removeWaypoint(a);
        System.out.println("("+namea+","+nameb+")"+"2.两点同位置,不同名. delete:"+namea);
        info = info+ "("+namea+","+nameb+")"+"2.两点同位置,不同名. delete:"+namea+"\n";
        this.del++;
      }else if(this.isNumeric(nameb)){
        ItemValue.removeWaypoint(b);
        System.out.println("2.两点同位置,不同名. delete:"+nameb);
        info = info+ "("+namea+","+nameb+")"+"2.两点同位置,不同名. delete:"+nameb+"\n";
        this.del++;
      }else{
        ItemValue.setWaypointName(b,".");
        System.out.println("2.两点同位置,不同名. 把一个点名字清空:"+nameb);
        info = info+ "("+namea+","+nameb+")"+"2.两点同位置,不同名. 把一个点名字清空:"+nameb+"\n";
        this.emp++;
      }
    }else if(nearPosition(lonXa,latYa,lonXb,latYb)&&(namea.equals(nameb))){//3.两点太近,同名
      ItemValue.setWaypointName(b,".");
      System.out.println("3.两点太近,同名. 把一个点名字清空:"+nameb);
      info = info+ "("+namea+","+nameb+")"+"3.两点太近,同名. 把一个点名字清空:"+nameb+"\n";
      this.emp++;
    }else if(nearPosition(lonXa,latYa,lonXb,latYb)&&(!(namea.equals(nameb)))){//4.两点太近,不同名
      info = info+ "("+namea+","+nameb+")"+"4.两点太近,不同名 "+"\n";
    }
  }
  /**
   * 仅仅删除同名同点的数据
   */
  public boolean  onlyDeleteSamepoint(Node a,Node b){
    String namea = ItemValue.getWaypointName(a);
    String nameb = ItemValue.getWaypointName(b);
    double lonXa = Double.parseDouble(ItemValue.getWaypointX(a));
    double latYa = Double.parseDouble(ItemValue.getWaypointY(a));
    double lonXb = Double.parseDouble(ItemValue.getWaypointX(b));
    double latYb = Double.parseDouble(ItemValue.getWaypointY(b));
    if(SamePosition(lonXa,latYa,lonXb,latYb)&&(namea.equals(nameb))){//两点同位置,同名
      ItemValue.removeWaypoint(a);
      System.out.println("两点同位置,同名. 删除第一个点:"+namea);
      info = info+ "("+namea+","+nameb+")"+"1.两点同位置,同名. delete:"+namea+"\n";
      this.del++;
      return true;
    }
    return false;
  }
  /**
   * 删除同名接近的两个点
   */
  public boolean  DeleteSameNameNearPoint(Node a,Node b){
    String namea = ItemValue.getWaypointName(a);
    String nameb = ItemValue.getWaypointName(b);
    double lonXa = Double.parseDouble(ItemValue.getWaypointX(a));
    double latYa = Double.parseDouble(ItemValue.getWaypointY(a));
    double lonXb = Double.parseDouble(ItemValue.getWaypointX(b));
    double latYb = Double.parseDouble(ItemValue.getWaypointY(b));
    if(nearPosition(lonXa,latYa,lonXb,latYb)&&(namea.equals(nameb))){//两点同位置,同名
      //如果其中一个是行政村
      if(ItemValue.getWaypointKP(a).equals(WptType.W1XingZhengCun)){
        if (ItemValue.getWaypointKP(b).equals(WptType.W1XingZhengCun)) {
          ItemValue.removeWaypoint(a);
          System.out.println("两点太近,同名.而且都是行政村.删除第一个点:" + namea);
          info = info + "(" + namea + "," + nameb + ")" + "两点太近,同名.而且都是行政村. delete:" +
              namea + "\n";
          this.del++;
          return true;
        }
      }else{
        ItemValue.removeWaypoint(a);
        System.out.println("两点太近,同名.第一点不是行政村.删除第一个点:" + namea);
        info = info + "(" + namea + "," + nameb + ")" +
            "两点太近,同名.第一点不是行政村. delete:" +
            namea + "\n";
        this.del++;
        return true;
      }
    }
    return false;
  }
  /**
   * 判断是否相近,而且同名称
   */
  private boolean isNear(Node a , Node b){
    String namea = ItemValue.getWaypointName(a);
    String nameb = ItemValue.getWaypointName(b);
    double lonXa = Double.parseDouble(ItemValue.getWaypointX(a));
    double latYa = Double.parseDouble(ItemValue.getWaypointY(a));
    double lonXb = Double.parseDouble(ItemValue.getWaypointX(b));
    double latYb = Double.parseDouble(ItemValue.getWaypointY(b));

    if(nearPosition(lonXa,latYa,lonXb,latYb)&&(namea.equals(nameb))){
      return true;
    }else{
      return false;
    }
  }
  public void run(){
    int[] pos = ItemValue.getPosition("waypoint");
    Node nodea = null,nodeb = null;
    for(int i = 0;i < pos.length;i++){
      nodea = ItemValue.getWaypointByWaypointPos(i);

      for(int j =0;j<pos.length;j++){
        System.out.println("i="+i+",j="+j+",pos.length="+pos.length);
        nodeb = ItemValue.getWaypointByWaypointPos(j);
        if(nodea!=nodeb){
          this.compareWaypoint(nodea,nodeb);
          pos = ItemValue.getPosition("waypoint");
        }
      }
    }
    System.out.println(this.info);
    System.out.println("删除掉:"+this.del+"个点,清空为.的有"+this.emp+"个");
  }

  public void run2(){//only delete same node
    int[] pos = ItemValue.getPosition("waypoint");
    String log = "";
    Node nodea = null,nodeb = null;
    for(int i = 0;i < pos.length;i++){
      nodea = ItemValue.getWaypointByWaypointPos(i);
      System.out.println("i=" + i + ",pos.length=" + pos.length);
      for(int j = i +1;j<pos.length;j++){
        //以前的都不需要比较了,因为已经比较过了
//          System.out.println("i=" + i + ",j=" + j + ",pos.length=" + pos.length);
          nodeb = ItemValue.getWaypointByWaypointPos(j);
          if (nodea != nodeb) {
            /**
             * 如果发现有相同的点,那么就可以删除并重新计算
             */
            if(this.onlyDeleteSamepoint(nodea, nodeb)){
              i--;
              pos = ItemValue.getPosition("waypoint");
              break;
            }
          }else{
            log = log + "遇到相同点进行比较,这是错误比较:i = " + i + ",j = " + j + "\r\n";
          }

      }
    }
    System.out.println(this.info);
    System.out.println(log);
    System.out.println("删除掉:"+this.del+"个点,清空为.的有"+this.emp+"个");
  }

  public void run3(){//only delete same node
    //int[] pos = ItemValue.getPosition("waypoint");
    Node[] wpts = ItemValue.getWaypoint();
    if(wpts == null){
      return;
    }
    String log = "";
    Node nodea = null,nodeb = null;
    for(int i = 0;i < wpts.length;i++){
      nodea = wpts[i];
      System.out.println("i=" + i + ",pos.length=" + wpts.length);
      for(int j = i +1;j<wpts.length;j++){
        //以前的都不需要比较了,因为已经比较过了
//          System.out.println("i=" + i + ",j=" + j + ",pos.length=" + pos.length);
          nodeb = wpts[j];
          if (nodea != nodeb) {
            /**
             * 如果发现有相同相近的点,那么删除第一个点
             */
            if(this.onlyDeleteSamepoint(nodea, nodeb)){
              //reset node
              wpts = this.resetArray(wpts,i);
              i--;
              break;
            }else if(this.DeleteSameNameNearPoint(nodea, nodeb)){
              //reset node
              wpts = this.resetArray(wpts, i);
              i--;
              break;
            }
          }else{
            log = log + "遇到相同点进行比较,这是错误比较:i = " + i + ",j = " + j + "\r\n";
          }

      }
    }
    System.out.println(this.info);
    System.out.println(log);
    System.out.println("删除掉:"+this.del+"个点,清空为.的有"+this.emp+"个");
  }
  public void run4(){//only delete same node
    //int[] pos = ItemValue.getPosition("waypoint");
    Node[] wpts = ItemValue.getWaypoint();
    if(wpts == null){
      return;
    }
    String log = "";
    Node nodea = null,nodeb = null;
    for(int i = 0;i < wpts.length;i++){
      nodea = wpts[i];
      System.out.println("i=" + i + ",pos.length=" + wpts.length);
      for(int j = i +1;j<wpts.length;j++){
        //以前的都不需要比较了,因为已经比较过了
//          System.out.println("i=" + i + ",j=" + j + ",pos.length=" + pos.length);
          nodeb = wpts[j];
          if (nodea != nodeb) {
            /**
             * 如果发现有相同点,那么删除第一个点
             */
            if(this.onlyDeleteSamepoint(nodea, nodeb)){
              //reset node
              wpts = this.resetArray(wpts,i);
              i--;
              break;
            }
            /**
             * 如果两点太近,而且同名
             */
            else if(this.isNear(nodea, nodeb)){
              if (ItemValue.getWaypointKP(nodea).equals(WptType.W1XingZhengCun)) {
                if (ItemValue.getWaypointKP(nodeb).equals(WptType.W1XingZhengCun)) {
                  /**
                   * 如果两点都是行政村,那么删除掉第一个点
                   */
                  ItemValue.removeWaypoint(nodea);
                  System.out.println("两点太近,同名.而且都是行政村.删除第一个点:");
                  info = info + "(" + ItemValue.getWaypointName(nodeb) + ")" +
                      "两点太近,同名.而且都是行政村. delete:" + "\n";
                  this.del++;
                  //reset node
                  wpts = this.resetArray(wpts, i);
                  i--;
                  break;
                }else{
                  /**
                   * 如果第二点不是行政村,删除掉第二点
                   */
                  ItemValue.removeWaypoint(nodeb);
                  System.out.println("两点太近,同名.如果第二点不是行政村,删除掉第二点:");
                  info = info + "(" + ItemValue.getWaypointName(nodea) + ")" +
                      "两点太近,同名.如果第二点不是行政村,删除掉第二点. delete:" + "\n";
                  this.del++;
                  //reset node
                  wpts = this.resetArray(wpts, j);
                  j--;
                }
              }else{
                /**
                 * 如果第一个点不是行政村,那么直接删除掉第一个点
                 */
                ItemValue.removeWaypoint(nodea);
                System.out.println("两点太近,同名.第一个点不是行政村.删除第一个点:");
                info = info + "(" + ItemValue.getWaypointName(nodeb) + ")" +
                    "两点太近,同名.第一个点不是行政村. delete:" + "\n";
                this.del++;
                //reset node
                wpts = this.resetArray(wpts, i);
                i--;
                break;
              }
            }
          }else{
            log = log + "遇到相同点进行比较,这是错误比较:i = " + i + ",j = " + j + "\r\n";
          }

      }
    }
    System.out.println(this.info);
    System.out.println(log);
    System.out.println("删除掉:"+this.del+"个点,清空为.的有"+this.emp+"个");
  }

  /**
   * 当数组删除掉一个元素时,重新构造数组
   * removed:删除的元素下标
   */
  private Node[] resetArray(Node[] array,int removed){
    Node[] temp = new Node[array.length-1];
    for (int i = 0; i < temp.length; i++) {
      if(i<removed){
        temp[i] = array[i];
      }else{
       temp[i] = array[i+1];
      }
    }
    return temp;
  }
  public boolean SamePosition(double xa,double ya,double xb,double yb){//相同点
    if((xa==xb)&&(ya==yb)){
      return true;
    }else{
      return false;
    }
  }

  public boolean nearPosition(double xa,double ya,double xb,double yb){//相近点
    if(Math.abs(xa-xb)<this.nearx){
      if(Math.abs(ya-yb)<this.neary){
        return true;
      }else{
        return false;
      }
    }else{
      return false;
    }
  }

  public boolean isNumeric(String name){
    char[] num = {'0','1','2','3','4','5','6','7','8','9'};
    char[] ch = name.toCharArray();
    boolean temp = false,temp2 = false;
    for(int i =0;i<ch.length;i++){
      for(int j=0;j<num.length;j++){
        if(ch[i]==num[j]){
          temp = true;
          temp2 = true;
          break;
        }
      }
      if(temp!=true){
        temp2 = false;
        break;
      }else{
        temp = false;
      }
    }
    if(temp2== true){
      return true;
    }else{
      return false;
    }
  }
  public String getNoNumericName(Node node){//Only for waypoint,如果名字里面包含数字的话,把数字去掉.
    String name = ItemValue.getWaypointName(node);
    System.out.println(name+",name.length():"+name.length());
    if(name.length()>4){
      String namePre = name.substring(0,4);
      System.out.println("namePre:"+namePre);
      if(this.isNumeric(namePre)){
        name = name.substring(4,name.length());
        System.out.println("Get rid of "+namePre+",And the name turn into "+name);
      }
    }
    return name;
  }
  public static void main(String[] args) {
    WipeWaypoint wipewaypoint = new WipeWaypoint();
  }
}

⌨️ 快捷键说明

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