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

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

package com.earthview.world.product.weblg.test;

public class Test06 {

    public static String ECEFtoWGS84(double longitude , double latitude, 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 WGS84toECEF(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;
    }


    public static void main(String[] args) {
        String s = ECEFtoWGS84(79.88, 37.03, 1407);
        String s1 = WGS84toECEF(895966.8677905983, 5019779.545835937, 3820898.904965419);
        System.out.println(s);
        System.out.println(s1);

    }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值