本文主要是介绍wgs84坐标系转化为中国大地坐标CGCS2000 / 3-degree Gauss-Kruger CM 120E,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
gps角分秒格式经纬度转double经纬度:getPosition方法
private static String getPosition(String position){String[] degree = position.split("\\°");if(degree.length == 1){return position;}String d = degree[0];String[] one = degree[1].split("\\′");String a = one[0];if(!a.contains(".")){if(a.substring(0,1).equals("0")){a = a.substring(1);}}else if(a.contains(".") && a.split("\\.").length > 1){a = a.substring(1);}String[] two = one[1].split("\\″");String b= two[0];if(!b.contains(".")){if(b.substring(0,1).equals("0")){b = b.substring(1);}}else if(b.contains(".") && b.split("\\.").length > 1){if(b.substring(0,1).equals("0")){b = b.substring(1);}}BigDecimal fen = new BigDecimal(a);BigDecimal miao = new BigDecimal(b);BigDecimal du = new BigDecimal(d);
// float f = Float.valueOf(a)+ Float.valueOf(Float.valueOf(b)/60);
// float du = Float.valueOf(f/60)+Float.valueOf(d);BigDecimal add = fen.add(miao.divide(new BigDecimal("60"),6, BigDecimal.ROUND_HALF_UP)).divide(new BigDecimal("60"),6, BigDecimal.ROUND_HALF_UP).add(du);return String.valueOf(add);}
wgs84转CGCS2000 / 3-degree Gauss-Kruger CM 120E方法:getXY
/**** @param B 纬度* @param L 经度* @param degree 角度* @return*/public static String getXY(double B, double L, double degree) {double[] xy = new double[]{0.0D, 0.0D};double a = 6378137.0D;double b = 6356752.314245179D;double e = 0.081819190842621D;double eC = 0.0820944379496957D;double L0 = 0.0D;int n;if (degree == 6.0D) {n = (int)Math.round((L + degree / (double)2) / degree);L0 = degree * (double)n - degree / (double)2;} else {n = (int)Math.round(L / degree);L0 = degree * (double)n;}double radB = B * 3.141592653589793D / (double)180;double radL = L * 3.141592653589793D / (double)180;double deltaL = (L - L0) * 3.141592653589793D / (double)180;double N = a * a / b / Math.sqrt((double)1 + eC * eC * Math.cos(radB) * Math.cos(radB));double C1 = 1.0D + 0.75D * e * e + 0.703125D * Math.pow(e, 4.0D) + 0.68359375D * Math.pow(e, 6.0D) + 0.67291259765625D * Math.pow(e, 8.0D);double C2 = 0.75D * e * e + 0.9375D * Math.pow(e, 4.0D) + 1.025390625D * Math.pow(e, 6.0D) + 1.07666015625D * Math.pow(e, 8.0D);double C3 = 0.234375D * Math.pow(e, 4.0D) + 0.41015625D * Math.pow(e, 6.0D) + 0.538330078125D * Math.pow(e, 8.0D);double C4 = 0.068359375D * Math.pow(e, 6.0D) + 0.15380859375D * Math.pow(e, 8.0D);double C5 = 0.00240325927734375D * Math.pow(e, 8.0D);double t = Math.tan(radB);double eta = eC * Math.cos(radB);double X = a * ((double)1 - e * e) * (C1 * radB - C2 * Math.sin((double)2 * radB) / (double)2 + C3 * Math.sin((double)4 * radB) / (double)4 - C4 * Math.sin((double)6 * radB) / (double)6 + C5 * Math.sin((double)8 * radB));xy[0] = X + N * Math.sin(radB) * Math.cos(radB) * Math.pow(deltaL, 2.0D) * ((double)1 + Math.pow(deltaL * Math.cos(radB), 2.0D) * ((double)5 - t * t + (double)9 * eta * eta + (double)4 * Math.pow(eta, 4.0D)) / (double)12 + Math.pow(deltaL * Math.cos(radB), 4.0D) * ((double)61 - (double)58 * t * t + Math.pow(t, 4.0D)) / (double)360) / (double)2;xy[1] = N * deltaL * Math.cos(radB) * ((double)1 + Math.pow(deltaL * Math.cos(radB), 2.0D) * ((double)1 - t * t + eta * eta) / (double)6 + Math.pow(deltaL * Math.cos(radB), 4.0D) * ((double)5 - (double)18 * t * t + Math.pow(t, 4.0D) - (double)14 * eta * eta - (double)58 * eta * eta * t * t) / (double)120) + (double)500000;return "纬度Y:"+xy[0]+"---经度X"+xy[1];}
测试代码:
public static void main(String[] args) {//度分秒格式坐标转double格式double x = Double.parseDouble(getPosition("119°40′07.673544″"));double y = Double.parseDouble(getPosition("32°11′26.493186″"));System.out.println(x);System.out.println(y);//wgs84转大地2000System.out.println(GetXY(y,x,3.0));}
打印信息:
下面再附上中国大地坐标CGCS2000 / 3-degree Gauss-Kruger CM 120E坐标系转化为wgs84:
package com.example.androiddaggerstudy.lat;
import org.jetbrains.annotations.NotNull;
import kotlin.jvm.internal.Intrinsics;
/*** 版权:渤海新能 版权所有** @author feiWang* 版本:1.5* 创建日期:2020/10/16* 描述:AndroidDaggerStudy* E-mail : 1276998208@qq.com* CSDN:https://blog.csdn.net/m0_37667770/article* GitHub:https://github.com/luhenchang*/
public class JavaRtkUtils {private double p = 206264.80624709636D;@NotNullpublic Tuple xyTowgs84(double x, double y, double L0) {double a = 6378137.0D;double efang = 0.0066943799901413D;double e2fang = 0.0067394967422764D;y = y - (double)500000;double m0 = 0.0D;double m2 = 0.0D;double m4 = 0.0D;double m6 = 0.0D;double m8 = 0.0D;m0 = a * ((double)1 - efang);m2 = 1.5D * efang * m0;m4 = efang * m2 * 5.0D / 4.0D;m6 = efang * m4 * 7.0D / 6.0D;m8 = efang * m6 * 9.0D / 8.0D;double a0 = 0.0D;double a2 = 0.0D;double a4 = 0.0D;double a6 = 0.0D;double a8 = 0.0D;a0 = m0 + m2 / 2.0D + m4 * 3.0D / 8.0D + m6 * 5.0D / 16.0D + m8 * 35.0D / 128.0D;a2 = m2 / 2.0D + m4 / 2.0D + m6 * 15.0D / 32.0D + m8 * 7.0D / 16.0D;a4 = m4 / 8.0D + m6 * 3.0D / 16.0D + m8 * 7.0D / 32.0D;a6 = m6 / 32.0D + m8 / 16.0D;a8 = m8 / 128.0D;double FBf = 0.0D;double Bf0 = x / a0;for(double Bf1 = 0.0D; Bf0 - Bf1 >= 1.0E-4D; Bf0 = (x - FBf) / a0) {Bf1 = Bf0;FBf = -a2 * Math.sin((double)2 * Bf0) / (double)2 + a4 * Math.sin((double)4 * Bf0) / (double)4 - a6 * Math.sin((double)6 * Bf0) / (double)6 + a8 * Math.sin((double)8 * Bf0) / (double)8;}double Wf = Math.sqrt((double)1 - efang * Math.sin(Bf0) * Math.sin(Bf0));double Nf = a / Wf;double Mf = a * ((double)1 - efang) / Math.pow(Wf, 3.0D);double nffang = e2fang * Math.cos(Bf0) * Math.cos(Bf0);double tf = Math.tan(Bf0);double B = Bf0 - tf * y * y / ((double)2 * Mf * Nf) + tf * ((double)5 + (double)3 * tf * tf + nffang - (double)9 * nffang * tf * tf) * Math.pow(y, 4.0D) / ((double)24 * Mf * Math.pow(Nf, 3.0D)) - tf * ((double)61 + (double)90 * tf * tf + (double)45 * Math.pow(tf, 4.0D)) * Math.pow(y, 6.0D) / ((double)720 * Mf * Math.pow(Nf, 5.0D));double l = y / (Nf * Math.cos(Bf0)) - ((double)1 + (double)2 * tf * tf + nffang) * Math.pow(y, 3.0D) / ((double)6 * Math.pow(Nf, 3.0D) * Math.cos(Bf0)) + ((double)5 + (double)28 * tf * tf + (double)24 * Math.pow(tf, 4.0D)) * Math.pow(y, 5.0D) / ((double)120 * Math.pow(Nf, 5.0D) * Math.cos(Bf0));double L = l + L0;double[] array_B = this.rad2dms(B);double[] array_L = this.rad2dms(L);double Bdec = this.dms2dec(array_B);double Ldec = this.dms2dec(array_L);return new Tuple(Bdec, Ldec);}public double gaussLongToDegreen(double B, double L, int N) {double L00 = (double)Math.round(L / (double)3) * (double)3;return L00 / (double)180 * 3.1415926D;}@NotNullpublic double[] rad2dms(double rad) {double[] a = new double[]{0.0D, 0.0D, 0.0D};double dms = rad * p;a[0] = Math.floor(dms / 3600.0D);a[1] = Math.floor((dms - a[0] * (double)3600) / 60.0D);a[2] = (double)((int)Math.floor(dms - a[0] * (double)3600)) - a[1] * (double)60;return a;}public double dms2dec(@NotNull double[] dms) {Intrinsics.checkNotNullParameter(dms, "dms");double dec = 0.0D;dec = dms[0] + dms[1] / 60.0D + dms[2] / 3600.0D;return dec;}@NotNullpublic Tuple GetXY(double B, double L, double degree) {double[] xy = new double[]{0.0D, 0.0D};double a = 6378137.0D;double b = 6356752.314245179D;double e = 0.081819190842621D;double eC = 0.0820944379496957D;double L0 = 0.0D;int n;if (degree == 6.0D) {n = (int)Math.round((L + degree / (double)2) / degree);L0 = degree * (double)n - degree / (double)2;} else {n = (int)Math.round(L / degree);L0 = degree * (double)n;}double radB = B * 3.141592653589793D / (double)180;double radL = L * 3.141592653589793D / (double)180;double deltaL = (L - L0) * 3.141592653589793D / (double)180;double N = a * a / b / Math.sqrt((double)1 + eC * eC * Math.cos(radB) * Math.cos(radB));double C1 = 1.0D + 0.75D * e * e + 0.703125D * Math.pow(e, 4.0D) + 0.68359375D * Math.pow(e, 6.0D) + 0.67291259765625D * Math.pow(e, 8.0D);double C2 = 0.75D * e * e + 0.9375D * Math.pow(e, 4.0D) + 1.025390625D * Math.pow(e, 6.0D) + 1.07666015625D * Math.pow(e, 8.0D);double C3 = 0.234375D * Math.pow(e, 4.0D) + 0.41015625D * Math.pow(e, 6.0D) + 0.538330078125D * Math.pow(e, 8.0D);double C4 = 0.068359375D * Math.pow(e, 6.0D) + 0.15380859375D * Math.pow(e, 8.0D);double C5 = 0.00240325927734375D * Math.pow(e, 8.0D);double t = Math.tan(radB);double eta = eC * Math.cos(radB);double X = a * ((double)1 - e * e) * (C1 * radB - C2 * Math.sin((double)2 * radB) / (double)2 + C3 * Math.sin((double)4 * radB) / (double)4 - C4 * Math.sin((double)6 * radB) / (double)6 + C5 * Math.sin((double)8 * radB));xy[0] = X + N * Math.sin(radB) * Math.cos(radB) * Math.pow(deltaL, 2.0D) * ((double)1 + Math.pow(deltaL * Math.cos(radB), 2.0D) * ((double)5 - t * t + (double)9 * eta * eta + (double)4 * Math.pow(eta, 4.0D)) / (double)12 + Math.pow(deltaL * Math.cos(radB), 4.0D) * ((double)61 - (double)58 * t * t + Math.pow(t, 4.0D)) / (double)360) / (double)2;xy[1] = N * deltaL * Math.cos(radB) * ((double)1 + Math.pow(deltaL * Math.cos(radB), 2.0D) * ((double)1 - t * t + eta * eta) / (double)6 + Math.pow(deltaL * Math.cos(radB), 4.0D) * ((double)5 - (double)18 * t * t + Math.pow(t, 4.0D) - (double)14 * eta * eta - (double)58 * eta * eta * t * t) / (double)120) + (double)500000;return new Tuple(xy[0], xy[1]);}}
这篇关于wgs84坐标系转化为中国大地坐标CGCS2000 / 3-degree Gauss-Kruger CM 120E的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!