欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

java 地心坐标系(ECEF)和WGS-84坐标系(WGS84)互转的实现

程序员文章站 2022-08-03 20:47:47
本文介绍了java 地心坐标系(ecef)和wgs-84坐标系(wgs84)互转的实现,分享给大家,具体如下: public static string w...

本文介绍了java 地心坐标系(ecef)和wgs-84坐标系(wgs84)互转的实现,分享给大家,具体如下:

 public static string wgs84toecef(double latitude, double longitude, double height)
  {
    double x;
    double y;
    double z;
    double a = 6378137;
    double b = 6356752.314245;
    double e = (a * a - b * b) / (a * a);
    double coslat = math.cos(latitude * math.pi / 180);
    double sinlat = math.sin(latitude * math.pi / 180);
    double coslong = math.cos(longitude * math.pi / 180);
    double sinlong = math.sin(longitude * math.pi / 180);
    double n = a / (math.sqrt(1 - e * sinlat * sinlat));
    double nh = n + height;
    x = nh * coslat * coslong;
    y = nh * coslat * sinlong;
    z = (b * b * n / (a * a) + height) * sinlat;
    return x + "," + y + "," + z;
  }
 
 
  public static string eceftowgs84(double x, double y, double z)
 
  {
    double a, b, c, d;
    double longitude;//经度
    double latitude;//纬度
    double altitude;//海拔高度
    double p, q;
    double n;
    a = 6378137.0;
    b = 6356752.31424518;
    c = math.sqrt(((a * a) - (b * b)) / (a * a));
    d = math.sqrt(((a * a) - (b * b)) / (b * b));
    p = math.sqrt((x * x) + (y * y));
    q = math.atan2((z * a), (p * b));
    longitude = math.atan2(y, x);
    latitude = math.atan2((z + (d * d) * b * math.pow(math.sin(q), 3)), (p - (c * c) * a * math.pow(math.cos(q), 3)));
    n = a / math.sqrt(1 - ((c * c) * math.pow(math.sin(latitude), 2)));
    altitude = (p / math.cos(latitude)) - n;
    longitude = longitude * 180.0 / math.pi;
    latitude = latitude * 180.0 / math.pi;
    return longitude + "," + latitude + "," + altitude;
  }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。