package urt; import java.text.DecimalFormat; public class xytoutm { static DecimalFormat df = new DecimalFormat("0.0000000"); /**½«dx,dyתΪ¾­Î³¶È¸ß³Ì·µ»Ødouble[]·µ»ØµÄ½á¹ûÊǶȷָñʽµÄ * a[0]¾­¶È¶È¸ñʽ * a[1]ά¶È¶È¸ñʽ * a[2]¾­¶È¶È·Ö¸ñʽ * a[3]¾­¶È¶È·Ö¸ñʽ*/ public static String[] xy2jwd(String dx,String dy,double[] xycs) { String xy2jwd[]=new String[4]; double x=Double.valueOf(dx); double y=Double.valueOf(dy); x=x/100; y=y/100; double utme0=xycs[0]; double utmn0=xycs[1]; double c=xycs[2]; double s=xycs[3]; double f=xycs[5]; double[] utm = xyutm(x,y,utme0, utmn0,c,s); double jwd[]= utm2ll_wgs84(utm[0],utm[1],f); xy2jwd[0]=String.valueOf(df.format(jwd[0])); xy2jwd[1]=String.valueOf(df.format(jwd[1])); jwd[0]=xytognss.ublox_d2dm(jwd[0]); jwd[1]=xytognss.ublox_d2dm(jwd[1]); xy2jwd[2]=String.valueOf(df.format(jwd[0])); xy2jwd[3]=String.valueOf(df.format(jwd[1])); return xy2jwd; } /**xÊÇÐèҪת»»µÄ * yÐèҪת»»µÄ * utme0³õʼ»¯µÄʱºò»ñµÃµÄÊý¾Ý*/ public static double[] xyutm(double x,double y,double utme0, double utmn0,double c, double s) { double[] utm=new double[2]; double x1, y1, dx, dy, utme, utmn; x1=y; y1=x; dx = c*x1 + s*y1; dy = -s*x1 + c*y1; utme = dx + utme0; utmn = dy + utmn0; utm[0] = utme; utm[1] = utmn; return utm; } // function [lat,lon]=utm2ll_wgs84(x,y,f) public static double[] utm2ll_wgs84(double x,double y,double f) { double[] latlon = new double[2]; double A1 = 6378137.0; double F1 = 298.257223563; // constants double D0 = 180/Math.PI; double maxiter = 100; double eps = 1e-11; double K0 = 0.9996; double X0 = 500000; // double Y0 = 1e7*(f < 0); double Y0 = 0; if(f < 0){ Y0 = 1e7; } double P0 = 0; double L0 = (6*Math.abs(f) - 183)/D0; double E1 = Math.sqrt(( A1*A1 - (A1*(1 - 1/F1))*(A1*(1 - 1/F1)))/(A1*A1)); double N = K0*A1; double[] C = coef(E1,0); double YS = Y0 - N*(C[0]*P0 + C[1]*Math.sin(2*P0) + C[2]*Math.sin(4*P0) + C[3]*Math.sin(6*P0) + C[4]*Math.sin(8*P0)); C = coef(E1,1); double zta = (y - YS)/N/C[0]; double ztb = (x - X0)/N/C[0]; double L = zta; double LS = ztb; // for i = 2:5 for(int i = 2; i < 6; i++) { double zta_temp = zta*(i-1)*2; double ztb_temp = ztb*(i-1)*2; L = L - C[i-1]*Math.sin(zta_temp)*Math.cosh(ztb_temp); LS = LS - C[i-1]*Math.cos(zta_temp)*Math.sinh(ztb_temp); } double l = L0 + Math.atan(Math.sinh(LS)/Math.cos(L)); double p = Math.asin(Math.sin(L)/Math.cosh(LS)); L = Math.log(Math.tan(Math.PI/4 + p/2)); p = 2*Math.atan(Math.exp(L)) - Math.PI/2; double p0 = 0; double n = 0; while ((p0==0 || Math.abs(p - p0) > eps) && n < maxiter) { p0 = p; double es = E1*Math.sin(p0); p = 2*Math.atan(Math.pow((1 + es)/(1 - es), E1/2)*Math.exp(L)) - Math.PI/2; n = n + 1; } latlon[0] = p*D0; latlon[1] = l*D0; return latlon; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // function c = coef(e,m) public static double[] coef(double e,int m) { double[][] c0; double[] c = new double[5]; // switch m // case 0 if (m==0) { c0 = new double[][] { {-175.0/16384.0,0.0, -5/256.0, 0.0, -3/64.0, 0.0, -1/4.0, 0.0, 1.0}, {-105/4096.0, 0.0, -45/1024.0, 0.0, -3/32.0, 0.0, -3/8.0, 0.0, 0.0}, {525 /16384.0, 0.0, 45/1024.0, 0.0, 15/256.0, 0.0, 0.0, 0.0, 0.0}, {-175/12288.0, 0.0, -35/3072.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {315 /131072.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0} // 5x9 }; } else { c0 = new double[][] { {-175/16384.0, 0.0, -5/256.0, 0.0, -3/64.0, 0.0, -1/4.0, 0.0, 1.0}, { 1/61440.0, 0.0, 7/2048.0, 0.0, 1/48.0, 0.0, 1/8.0, 0.0, 0.0}, { 59/368640.0, 0.0, 3/1280.0, 0.0, 1/768.0, 0.0, 0.0, 0.0, 0.0}, { 283/430080.0, 0.0, 17/30720.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {4397/41287680.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0} // 5x9 }; } for(int i =1; i < 6; i++) { for(int j =1; j < 10; j++) { c[i-1] = c[i-1] + c0[i-1][j-1]*Math.pow(e, 9-j); } } return c; } }