欢迎使用CSDN-markdown编辑器

  • 测量相关代码
    • 方位角
    • 高斯坐标转换
    • 空间直角坐标

测量相关代码

方位角

    // 计算方位角,正北向为0度,以顺时针方向递增
    public static double GetAzimuth(double lon1, double lat1, double lon2,
                                  double lat2) {
        double result = 0.0;

        int ilat1 = (int) (0.50 + lat1 * 360000.0);
        int ilat2 = (int) (0.50 + lat2 * 360000.0);
        int ilon1 = (int) (0.50 + lon1 * 360000.0);
        int ilon2 = (int) (0.50 + lon2 * 360000.0);

        lat1 = Math.toRadians(lat1);
        lon1 = Math.toRadians(lon1);
        lat2 = Math.toRadians(lat2);
        lon2 = Math.toRadians(lon2);

        if ((ilat1 == ilat2) && (ilon1 == ilon2)) {
            return result;
        } else if (ilon1 == ilon2) {
            if (ilat1 > ilat2)
                result = 180.0;
        } else {
            double c = Math
                    .acos(Math.sin(lat2) * Math.sin(lat1) + Math.cos(lat2)
                            * Math.cos(lat1) * Math.cos((lon2 - lon1)));
            double A = Math.asin(Math.cos(lat2) * Math.sin((lon2 - lon1))
                    / Math.sin(c));
            result = Math.toDegrees(A);
            if ((ilat2 > ilat1) && (ilon2 > ilon1)) {
            } else if ((ilat2 < ilat1) && (ilon2 < ilon1)) {
                result = 180.0 - result;
            } else if ((ilat2 < ilat1) && (ilon2 > ilon1)) {
                result = 180.0 - result;
            } else if ((ilat2 > ilat1) && (ilon2 < ilon1)) {
                result += 360.0;
            }
        }
        return result;
    }

高斯坐标转换

  /* 参数说明
所有投影转换公式都基于椭球体
椭球体长半轴
北京54 a = 6378245
西安80 a = 6378140
WGS 84 a = 6378137
椭球体短半轴
北京54 b = 6356863.0188
西安80 b = 6356755.2882
WGS 84 b = 6356752.3142
扁率    f = (a - b) / a
第一偏心率   e = sqrt(1 - (b / a) * (b / a))
第二偏心率   e' = sqrt((a / b) * (a / b) - 1)
卯酉圈曲率半径  N = (a * a / b) / sqrt(1 + e' * e' * cosβ * cosβ
子午圈曲率半径  R = a * (1 - e * e) / sqrt((1 - e * e * sinβ * sinβ) * (1 - e * e * sinβ * sinβ) * (1 - e * e * sinβ * sinβ))
B -- 纬度,L -- 经度,单位弧度(RAD)
N X -- 纵直角坐标, E Y -- 横直角坐标,单位米(M)
//*/
    public static  double L0;   // 中央经度
    // 高斯 - 克吕格投影比例因子
    public static  double k0 = 1;
    public static  long eastdiff= 500000L;
    public static  long northdiff= 0L;
    public static int degreeindex=0;
    // 高斯投影转换
    //void GaussCalc(double L, double B, double& X, double& Y)
    public double[] GaussToBLToGauss(double L, double B)
    {
        double[] xyval={0.0,0.0};
        double X,  Y;
        // 椭球体短半轴
        //double a = 6378245;     // 北京54
        //double b = 6356863.0188;    // 北京54
        //double a = 6378140;     // 西安80
        //double b = 6356755.2882;    // 西安80
        double a = 6378137;      // WGS 84
        double b = 6356752.3142;    // WGS 84
        double f = (a - b) / a;     // 扁率
        double e = 1 - (b / a) * (b / a);  // 第一偏心率平方
        double e2 = (a / b) * (a / b) - 1;  // 第二偏心率平方
        double dblPI = 3.1415926535898 / 180.0; // 角度弧度转换参数
        // 求经度所在带号
        int ZoneWide = 3; // 带宽 3度带或6度带
        int ZoneNumber;  // 带号

        if (3 == ZoneWide)
        {// 3度带
            ZoneNumber = (int)(L - ZoneWide / 2) / ZoneWide + 1;
        }
        else// if (6 == ZoneWide)
        {// 6度带
            ZoneNumber = (int)(L) / ZoneWide + 1;
        }
        // 角度转换成弧度
        double L1 = L * dblPI;
        double B1 = B * dblPI;
        L0 = L0 * dblPI;

        // 子午圈曲率半径
        double R = a * (1 - e) / Math.sqrt((1 - e * Math.sin(B1) * Math.sin(B1)) * (1 - e * Math.sin(B1) * Math.sin(B1)) * (1 - e * Math.sin(B1) * Math.sin(B1)));
        double T = Math.tan(B1) * Math.tan(B1);
        double C = e2 * Math.cos(B1) * Math.cos(B1);
        double A = (L1 - L0) * Math.cos(B1);
        // 子午线弧长
        double M = a * ((1 - e / 4 - 3 * e * e / 64 - 5 * e * e * e / 256) * B1
                - (3 * e / 8 + 3 * e * e / 32 + 45 * e * e * e / 1024) * Math.sin(2 * B1)
                + (15 * e * e / 256 + 45 * e * e * e / 1024) * Math.sin(4 * B1)
                - (35 * e * e * e / 3072) * Math.sin(6 * B1));
        // 卯酉圈曲率半径
        double N = a / Math.sqrt(1 - e * Math.sin(B1) * Math.sin(B1));
        // 东纬度偏移
        double FE = ZoneNumber * 1000000L + eastdiff;


        // 根据投影公式计算点在投影坐标系中的位置
        Y= FE + k0 * N * (A + (1 - T + C) * A * A * A / 6 + (5 - 18 * T + T * T + 14 * C - 58 * T * C) * A * A * A * A * A / 120);
        X = northdiff+k0 * (M + N * Math.tan(B1) * (A * A / 2 + (5 - T + 9 * C + 4 * C * C) * A * A * A * A / 24)
                + (61 - 58 * T + T * T + 270 * C - 330 * T * C) * A * A * A * A * A * A / 720);
        xyval[0] = X ; xyval[1] =Y;
        return xyval;
    }

空间直角坐标


    //空间坐标
    /* transform geodetic to ecef position -----------------------------------------
    * transform geodetic position to ecef position
    * args   : double *pos      I   geodetic position {lon,lat,h} (rad,m)
    *          double *r        O   ecef position {x,y,z} (m)
    * return : none
    * notes  : WGS84, ellipsoidal height
    *-----------------------------------------------------------------------------*/  
    public double[] pos2ecef(double pos1,double pos0, double pos2)
    {
        double[] xyz = {0.0,0.0,0.0};
        try {
            pos0 = pos0 * Math.PI / 180;
            pos1 = pos1 * Math.PI / 180;
            //pos2 = pos2 * Math.PI / 180;
            double RE_WGS84 = 6378137.0;           /* earth semimajor axis (WGS84) (m) */
            double FE_WGS84 = (1.0 / 298.257223563); /* earth flattening (WGS84) */
            double sinp = Math.sin(pos0), cosp = Math.cos(pos0), sinl = Math.sin(pos1), cosl = Math.cos(pos1);
            double e2 = FE_WGS84 * (2.0 - FE_WGS84), v = RE_WGS84 / Math.sqrt(1.0 - e2 * sinp * sinp);

            xyz[0]=(v+pos2)*cosp*cosl;
            xyz[1]=(v+pos2)*cosp*sinl;
            xyz[2]=(v*(1.0-e2)+pos2)*sinp;

        } catch (Exception e) {
            // TODO: handle exception
            System.out.print("空间坐标转换失败!");
        }

        return xyz;
    }

你可能感兴趣的:(android)