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

📄 itemvalue.java

📁 基于Java的地图数据管理软件。使用MySQL数据库管理系统。
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    double yA = (m + hA) * Math.cos(latA) * Math.sin(lonA);
    double zA = (m + hA - m * ee) * Math.sin(latA);
    m = 6378137 / Math.sqrt(1 - ee * Math.pow(Math.sin(latB), 2.0));
    double xB = (m + hB) * Math.cos(latB) * Math.cos(lonB);
    double yB = (m + hB) * Math.cos(latB) * Math.sin(lonB);
    double zB = (m + hB - m * ee) * Math.sin(latB);

    distance = Math.sqrt( (xA - xB) * (xA - xB) + (yA - yB) * (yA - yB) +
                         (zA - zB) * (zA - zB));
    return distance;
  }

  public static double calculateDistanceBetween2Nodes1(double a_x, double a_y,
      double a_z, double b_x, double b_y, double b_z) {
    /*
       可以编个小程序实现这个功能。具体的计算方法如下:

     void myTestCalc (double n,double e,double h,double *x,double *y,double *z)
     {
      double m;
      const double ee = 0.00669437999013;

      m = 6378137/sqrt( 1-ee*pow(sin(n),2.0) );
     *x = ( m+h )*cos(n)*cos(e);
     *y = ( m+h )*cos(n)*sin(e);
     *z = ( m+h - m*ee )*sin(n);  //已知点坐标
      return;
     }
// h 为高度, n 为纬度(以弧度表示), e 为经度 (以弧度表示), x、y、z 为空间直角坐标

     计算出两点的空间直角坐标后,直接用空间两点间距离公式即可计算出距离。
     */

    /*
     参数名称 		        符号及单位 	WGS-84大地坐标系 	1980西安坐标系 		1954年北京坐标系
     长半径 			a(m) 		6378137 		6378140 		6378245
     短半径 			b(m) 		6356752.31420 		6356755.28820 		6356863.01880
     平均半径    	        R=(2a+b)/3(m) 	6371008.77140 		6371011.76273 		6371117.67293
     地球自转角速度    	ω(10-11rad/s) 	7292115 		7292115  
     地球引力常数(含大气层) 	GM(108m3/s2) 	3986005 		3986005  
     正常化二阶带谐系数  	C2.0(10-6) 	-484.16685    
        二阶带谐系数  	J2(10-6)   				1082.63  
     扁率         	α=(a-b)/a 	1/298.257223563 	1/298.257 		1/298.3
     第一偏心率平方   	e2 		0.00669437999013 	0.00669438499959 	0.006693421622966
     第二偏心率平方   	e'2 		0.006739496742227 	0.00673950181947 	0.006738525414683
     椭球正常重力位   	u0(m2s-2) 	62636860.85 		62636830  
     赤道正常重力位    	γe(ms-2) 	9.970326771 		9.780318  

     */
    double distance = 0.0;
    double lonA = a_x * Math.PI / 180;
    double latA = a_y * Math.PI / 180;
    double hA = a_z;
    double lonB = b_x * Math.PI / 180;
    double latB = b_y * Math.PI / 180;
    double hB = b_z;

    double ee = 0.00669437999013;
    double m = 6378137 / Math.sqrt(1 - ee * Math.pow(Math.sin(latA), 2.0));
    double xA = (m + hA) * Math.cos(latA) * Math.cos(lonA);
    double yA = (m + hA) * Math.cos(latA) * Math.sin(lonA);
    double zA = (m + hA - m * ee) * Math.sin(latA);
    m = 6378137 / Math.sqrt(1 - ee * Math.pow(Math.sin(latB), 2.0));
    double xB = (m + hB) * Math.cos(latB) * Math.cos(lonB);
    double yB = (m + hB) * Math.cos(latB) * Math.sin(lonB);
    double zB = (m + hB - m * ee) * Math.sin(latB);

    distance = Math.sqrt( (xA - xB) * (xA - xB) + (yA - yB) * (yA - yB) +
                         (zA - zB) * (zA - zB));
    return distance;
  }

  public static double calculateDistanceWithDegreeDis(double degree) {
    double distance = 0.0;
    double lonA = 112 * Math.PI / 180;
    double latA = 33 * Math.PI / 180;
    double hA = 10;
    double lonB = (112 + degree) * Math.PI / 180;
    double latB = 33 * Math.PI / 180;
    double hB = 10;

    double ee = 0.00669437999013;
    double m = 6378137 / Math.sqrt(1 - ee * Math.pow(Math.sin(latA), 2.0));
    double xA = (m + hA) * Math.cos(latA) * Math.cos(lonA);
    double yA = (m + hA) * Math.cos(latA) * Math.sin(lonA);
    double zA = (m + hA - m * ee) * Math.sin(latA);
    m = 6378137 / Math.sqrt(1 - ee * Math.pow(Math.sin(latB), 2.0));
    double xB = (m + hB) * Math.cos(latB) * Math.cos(lonB);
    double yB = (m + hB) * Math.cos(latB) * Math.sin(lonB);
    double zB = (m + hB - m * ee) * Math.sin(latB);

    distance = Math.sqrt( (xA - xB) * (xA - xB) + (yA - yB) * (yA - yB) +
                         (zA - zB) * (zA - zB));
    return distance;
  }

  public static double getTrackPointDistance(Node A, Node B) {
    double xa = Double.parseDouble(getTracksPointX(A));
    double ya = Double.parseDouble(getTracksPointY(A));
    double xb = Double.parseDouble(getTracksPointX(B));
    double yb = Double.parseDouble(getTracksPointY(B));

    double distance = Math.acos(Math.sin(ya) * Math.sin(yb) +
                                Math.cos(ya) * Math.cos(yb) * Math.cos(xa - xb)) *
        (6371008.77140);
    //double distance = 0.11112*Math.cos(1/(Math.sin(xa)*Math.sin(xb)+Math.cos(xa)*Math.cos(xb)*Math.cos(yb-ya)));
    //double distance = 111.31955*Math.sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
    return distance;
  }

  public static double getLongestDistance(Node tracksNode) { //得到最长的两个点之间的距离
    NodeList nl = getTracksPoint(tracksNode);
    Node nodetemp = null;
    double distance = 0.0;
    double lastDis = 0.0;
    for (int i = 0; i < nl.getLength(); i++) {
      if (nodetemp != null) {
        distance = calculateDistanceBetween2Nodes1(nodetemp, nl.item(i));
        if (lastDis < distance) {
          lastDis = distance;
        }
      }
      nodetemp = nl.item(i);
    }
    return lastDis;
  }

  public static double getTracksDistance(Node tracksNode) {
    NodeList nl = getTracksPoint(tracksNode);
    Node nodetemp = null;
    double distance = 0.0;
    for (int i = 0; i < nl.getLength(); i++) {
      if (nodetemp != null) {
        distance = distance +
            calculateDistanceBetween2Nodes1(nodetemp, nl.item(i));
        //System.out.println(""+distance);
        testPointIncrease();
      }
      nodetemp = nl.item(i);
    }
    return distance;
  }

  public static String getTracksStringDistance(Node tracksNode) {

    //String distance = getTracksDistance(tracksNode)+"";
    try {
//      String distance = (getTracksDistance(tracksNode) / 1000) + "";
//      String d1 = distance.substring(0, distance.indexOf("."));
//      String d2 = distance.substring(distance.indexOf("."),
//                                     distance.indexOf(".") + 3);
//      return d1 + d2;
      double distance = ItemValue.getRound(getTracksDistance(tracksNode) / 1000,
                                           3);
      return distance + "";
    }
    catch (Exception ex) {
      return "null";
    }
  }

  public static String getStringDistance(double dis) {

    //String distance = getTracksDistance(tracksNode)+"";
    try {
      String distance = dis + "";
      String d1 = distance.substring(0, distance.indexOf("."));
      String d2 = distance.substring(distance.indexOf("."),
                                     distance.indexOf(".") + 2);
      return d1 + d2;
    }
    catch (Exception ex) {
      return "null";
    }
  }

  private static double getDistance(Node tp, Node wp) {
    double tpx = Double.parseDouble(ItemValue.getTracksPointX(tp));
    double tpy = Double.parseDouble(ItemValue.getTracksPointY(tp));
    double wpx = Double.parseDouble(ItemValue.getWaypointX(wp));
    double wpy = Double.parseDouble(ItemValue.getWaypointY(wp));
    return Math.sqrt( (tpx - wpx) * (tpx - wpx) + (tpy - wpy) * (tpy - wpy));
  }

  private static Node getNearpoint(Node track, Node waypoint) {
    double distance = 0.0;
    double minDis = 0.5;
    Node minTp = null;
    NodeList nl = ItemValue.getTracksPoint(track);
    for (int i = 0; i < nl.getLength(); i++) {
      distance = getDistance(nl.item(i), waypoint);
      if (minDis > distance) {
        minDis = distance;
        minTp = nl.item(i);
      }
    }
    if (minDis == 0.5) {
      System.out.println("没有发现与" + ItemValue.getWaypointName(waypoint) +
                         "相近的点!");
    }
    return minTp;
  }

  public static Node getMostNearWaypoint(Node trackPoint, Node[] waypoint) {
    double distance = 0.0;
    double minDis = 0.5;
    Node minTp = null;
    if (waypoint == null) {
      return null;
    }
    for (int i = 0; i < waypoint.length; i++) {
      distance = getDistance(trackPoint, waypoint[i]);
      if (minDis > distance) {
        minDis = distance;
        minTp = waypoint[i];
      }
    }
    if (minDis == 0.5) {
      System.out.println("没有发现与该航迹点最近的点!");
    }
    return minTp;
  }

  public static Node getWaypoint(int item) {
    NodeList nl = GarminGMLDoc.root.getChildNodes();
    return nl.item(item);
  }

  public static Node getWaypointByWaypointPos(int waypointPos) {
    if (getPosition("waypoint") == null) {
      return null;
    }
    int[] position = getPosition("waypoint");
    if (position.length == 0) {
      return null;
    }
    return getWaypoint(position[waypointPos]);
  }

  public static String getWaypointName(Node node) {
    try {
      return node.getChildNodes().item(0).getChildNodes().item(0).getChildNodes().
          item(0).getNodeValue();
    }
    catch (Exception ex) {
      return "null";
    }
  }

  public static String getWaypointName(int pos) {
    if (getPosition("waypoint") == null) {
      return "";
    }
    int[] position = getPosition("waypoint");
    if (position.length == 0) {
      return "";
    }
    Node node = getWaypoint(position[pos]);
    return getWaypointName(node);
  }

  public static String getWaypointShortName(Node node) {
    String wn = getWaypointName(node);
    wn = StringOper.deleteAllChar(wn, '\\');
    if (wn.length() > 6) {
      try {
        wn = StringOper.deleteAllChar(wn, '(');
        wn = StringOper.deleteAllChar(wn, '-');
        wn = StringOper.deleteAllChar(wn, '(');
        wn = StringOper.deleteAllChar(wn, ')');
        wn = StringOper.deleteAllChar(wn, '(');
      }
      catch (Exception ex) {
        System.err.println(ex.getMessage() +
                           " in ItemValue.getWaypointShortName(Node node)");
      }

      if (wn.length() > 6) {
        wn = wn.substring(0, 6);
      }
    }
    return wn;
  }

  public static String getWaypointX(Node node) {
    try {
      return node.getChildNodes().item(0).getChildNodes().item(1).getChildNodes().
          item(0).getChildNodes().item(0).getNodeValue();
    }
    catch (Exception ex) {
      return "0.0";
    }
  }

  public static String getWaypointY(Node node) {
    try {
      return node.getChildNodes().item(0).getChildNodes().item(1).getChildNodes().
          item(1).getChildNodes().item(0).getNodeValue();
    }
    catch (Exception ex) {
      return "0.0";
    }
  }

  public static String getWaypointZ(Node node) {
    try {
      return node.getChildNodes().item(0).getChildNodes().item(1).getChildNodes().
          item(2).getChildNodes().item(0).getNodeValue();
    }
    catch (DOMException ex) {
      return "0.0";
    }
  }

  public static String getWaypointTime(Node node) {
    return node.getChildNodes().item(0).getChildNodes().item(1).getChildNodes().
        item(3).getChildNodes().item(0).getNodeValue();
  }

  public static String getWaypointRS(Node node) {
    return node.getChildNodes().item(0).getChildNodes().item(1).getChildNodes().
        item(4).getChildNodes().item(0).getNodeValue();
  }

  public static String getWaypointRWa(Node node) {
    return node.getChildNodes().item(0).getChildNodes().item(1).getChildNodes().
        item(5).getChildNodes().item(0).getNodeValue();
  }

  public static String getWaypointRWb(Node node) {
    return node.getChildNodes().item(0).getChildNodes().item(1).getChildNodes().
        item(6).getChildNodes().item(0).getNodeValue();
  }

  public static String getWaypointKP(Node node) {
    return node.getChildNodes().item(0).getChildNodes().item(1).getChildNodes().
        item(7).getChildNodes().item(0).getNodeValue();
  }

  public static String getWaypointTracksID(Node node) {
    return node.getChildNodes().item(0).getChildNodes().item(1).getChildNodes().
        item(8).getChildNodes().item(0).getNodeValue();
  }

  /**
   * 得到行政村的数组
   */
  public static String[] getWaypointXZC(Node node) {
    Node xzc = null;
    try {
      xzc = node.getChildNodes().item(0).getChildNodes().item(1).getChildNodes().
          item(9);
    }
    catch (Exception ex) {
      return null;
    }
    if (isHaveChild(xzc)) {
      String[] array = new String[11];
      array[0] = xzc.getChildNodes().item(1).getChildNodes().item(0).
          getChildNodes().item(0).getNodeValue();
      array[1] = xzc.getChildNodes().item(1).getChildNodes().item(1).
          getChildNodes().item(0).getNodeValue();
      array[2] = xzc.getChildNodes().item(1).getChildNodes().item(2).
          getChildNodes().item(0).getNodeValue();
      array[3] = xzc.getChildNodes().item(1).getChildNodes().item(3).
          getChildNodes().item(0).getNodeValue();
      array[4] = xzc.getChildNodes().item(1).getChildNodes().item(4).
          getChildNodes().item(0).getNodeValue();
      array[5] = xzc.getChildNodes().item(1).getChildNodes().item(5).
          getChildNodes().item(0).getNodeValue();
      array[6] = xzc.getChildNodes().item(1).getChildNodes().item(6).
          getChildNodes().item(0).getNodeValue();
      array[7] = xzc.getChildNodes().item(1).getChildNodes().item(7).
          getChildNodes().item(0).getNodeValue();
      array[8] = xzc.getChildNodes().item(1).getChildNodes().item(8).
          getChildNodes().item(0).getNodeValue();
      array[9] = xzc.getChildNodes().item(1).getChildNodes().item(9).
          getChildNodes().item(0).getNodeValue();

⌨️ 快捷键说明

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