经纬度坐标转换到平面坐标Java

来源:互联网 发布:淘宝宝贝价格下调 编辑:程序博客网 时间:2024/05/16 03:48
http://blog.csdn.net/hc260164797/article/details/46122277
通常经纬度坐标转平面坐标有两种做法:
  • 墨卡托坐标投影(UTM坐标系)
  • 米勒坐标投影

  1. 米勒坐标系
[java] view plain copy
  1. package sg.edu.ntu.huangcheng;  
  2.   
  3. public class MillerCoordinate {  
  4.     public static double[] MillierConvertion(double lat, double lon)  
  5.     {  
  6.          double L = 6381372 * Math.PI * 2;//地球周长  
  7.          double W=L;// 平面展开后,x轴等于周长  
  8.          double H=L/2;// y轴约等于周长一半  
  9.          double mill=2.3;// 米勒投影中的一个常数,范围大约在正负2.3之间  
  10.          double x = lon * Math.PI / 180;// 将经度从度数转换为弧度  
  11.          double y = lat * Math.PI / 180;// 将纬度从度数转换为弧度  
  12.          y=1.25 * Math.log( Math.tan( 0.25 * Math.PI + 0.4 * y ) );// 米勒投影的转换  
  13.          // 弧度转为实际距离  
  14.          x = ( W / 2 ) + ( W / (2 * Math.PI) ) * x;  
  15.          y = ( H / 2 ) - ( H / ( 2 * mill ) ) * y;  
  16.          double[] result=new double[2];  
  17.          result[0]=x;  
  18.          result[1]=y;  
  19.          return result;  
  20.     }  
  21. }  


  1. UTM坐标系
          缺点:由于UTM坐标系将整个地球划分为不同的区域(ZONES),不同区域的坐标间距很难计算。
     
[java] view plain copy
  1. package sg.edu.ntu.huangcheng;  
  2.   
  3. /* 
  4.  * Author: Sami Salkosuo, sami.salkosuo@fi.ibm.com 
  5.  * 
  6.  * (c) Copyright IBM Corp. 2007 
  7.  */  
  8.   
  9. import java.util.Hashtable;  
  10. import java.util.Map;  
  11.   
  12. public class CoordinateConversion  
  13. {  
  14.   
  15.   public CoordinateConversion()  
  16.   {  
  17.   
  18.   }  
  19.   
  20.   public double[] utm2LatLon(String UTM)  
  21.   {  
  22.     UTM2LatLon c = new UTM2LatLon();  
  23.     return c.convertUTMToLatLong(UTM);  
  24.   }  
  25.   
  26.   public String latLon2UTM(double latitude, double longitude)  
  27.   {  
  28.     LatLon2UTM c = new LatLon2UTM();  
  29.     return c.convertLatLonToUTM(latitude, longitude);  
  30.   
  31.   }  
  32.   
  33.   private void validate(double latitude, double longitude)  
  34.   {  
  35.     if (latitude < -90.0 || latitude > 90.0 || longitude < -180.0  
  36.         || longitude >= 180.0)  
  37.     {  
  38.       throw new IllegalArgumentException(  
  39.           "Legal ranges: latitude [-90,90], longitude [-180,180).");  
  40.     }  
  41.   
  42.   }  
  43.   
  44.   public String latLon2MGRUTM(double latitude, double longitude)  
  45.   {  
  46.     LatLon2MGRUTM c = new LatLon2MGRUTM();  
  47.     return c.convertLatLonToMGRUTM(latitude, longitude);  
  48.   
  49.   }  
  50.   
  51.   public double[] mgrutm2LatLon(String MGRUTM)  
  52.   {  
  53.     MGRUTM2LatLon c = new MGRUTM2LatLon();  
  54.     return c.convertMGRUTMToLatLong(MGRUTM);  
  55.   }  
  56.   
  57.   public double degreeToRadian(double degree)  
  58.   {  
  59.     return degree * Math.PI / 180;  
  60.   }  
  61.   
  62.   public double radianToDegree(double radian)  
  63.   {  
  64.     return radian * 180 / Math.PI;  
  65.   }  
  66.   
  67.   private double POW(double a, double b)  
  68.   {  
  69.     return Math.pow(a, b);  
  70.   }  
  71.   
  72.   private double SIN(double value)  
  73.   {  
  74.     return Math.sin(value);  
  75.   }  
  76.   
  77.   private double COS(double value)  
  78.   {  
  79.     return Math.cos(value);  
  80.   }  
  81.   
  82.   private double TAN(double value)  
  83.   {  
  84.     return Math.tan(value);  
  85.   }  
  86.   
  87.   private class LatLon2UTM  
  88.   {  
  89.     public String convertLatLonToUTM(double latitude, double longitude)  
  90.     {  
  91.       validate(latitude, longitude);  
  92.       String UTM = "";  
  93.   
  94.       setVariables(latitude, longitude);  
  95.   
  96.       String longZone = getLongZone(longitude);  
  97.       LatZones latZones = new LatZones();  
  98.       String latZone = latZones.getLatZone(latitude);  
  99.   
  100.       double _easting = getEasting();  
  101.       double _northing = getNorthing(latitude);  
  102.   
  103.       UTM = longZone + " " + latZone + " " + ((int) _easting) + " "  
  104.           + ((int) _northing);  
  105.       // UTM = longZone + " " + latZone + " " + decimalFormat.format(_easting) +  
  106.       // " "+ decimalFormat.format(_northing);  
  107.   
  108.       return UTM;  
  109.   
  110.     }  
  111.   
  112.     protected void setVariables(double latitude, double longitude)  
  113.     {  
  114.       latitude = degreeToRadian(latitude);  
  115.       rho = equatorialRadius * (1 - e * e)  
  116.           / POW(1 - POW(e * SIN(latitude), 2), 3 / 2.0);  
  117.   
  118.       nu = equatorialRadius / POW(1 - POW(e * SIN(latitude), 2), (1 / 2.0));  
  119.   
  120.       double var1;  
  121.       if (longitude < 0.0)  
  122.       {  
  123.         var1 = ((int) ((180 + longitude) / 6.0)) + 1;  
  124.       }  
  125.       else  
  126.       {  
  127.         var1 = ((int) (longitude / 6)) + 31;  
  128.       }  
  129.       double var2 = (6 * var1) - 183;  
  130.       double var3 = longitude - var2;  
  131.       p = var3 * 3600 / 10000;  
  132.   
  133.       S = A0 * latitude - B0 * SIN(2 * latitude) + C0 * SIN(4 * latitude) - D0  
  134.           * SIN(6 * latitude) + E0 * SIN(8 * latitude);  
  135.   
  136.       K1 = S * k0;  
  137.       K2 = nu * SIN(latitude) * COS(latitude) * POW(sin1, 2) * k0 * (100000000)  
  138.           / 2;  
  139.       K3 = ((POW(sin1, 4) * nu * SIN(latitude) * Math.pow(COS(latitude), 3)) / 24)  
  140.           * (5 - POW(TAN(latitude), 2) + 9 * e1sq * POW(COS(latitude), 2) + 4  
  141.               * POW(e1sq, 2) * POW(COS(latitude), 4))  
  142.           * k0  
  143.           * (10000000000000000L);  
  144.   
  145.       K4 = nu * COS(latitude) * sin1 * k0 * 10000;  
  146.   
  147.       K5 = POW(sin1 * COS(latitude), 3) * (nu / 6)  
  148.           * (1 - POW(TAN(latitude), 2) + e1sq * POW(COS(latitude), 2)) * k0  
  149.           * 1000000000000L;  
  150.   
  151.       A6 = (POW(p * sin1, 6) * nu * SIN(latitude) * POW(COS(latitude), 5) / 720)  
  152.           * (61 - 58 * POW(TAN(latitude), 2) + POW(TAN(latitude), 4) + 270  
  153.               * e1sq * POW(COS(latitude), 2) - 330 * e1sq  
  154.               * POW(SIN(latitude), 2)) * k0 * (1E+24);  
  155.   
  156.     }  
  157.   
  158.     protected String getLongZone(double longitude)  
  159.     {  
  160.       double longZone = 0;  
  161.       if (longitude < 0.0)  
  162.       {  
  163.         longZone = ((180.0 + longitude) / 6) + 1;  
  164.       }  
  165.       else  
  166.       {  
  167.         longZone = (longitude / 6) + 31;  
  168.       }  
  169.       String val = String.valueOf((int) longZone);  
  170.       if (val.length() == 1)  
  171.       {  
  172.         val = "0" + val;  
  173.       }  
  174.       return val;  
  175.     }  
  176.   
  177.     protected double getNorthing(double latitude)  
  178.     {  
  179.       double northing = K1 + K2 * p * p + K3 * POW(p, 4);  
  180.       if (latitude < 0.0)  
  181.       {  
  182.         northing = 10000000 + northing;  
  183.       }  
  184.       return northing;  
  185.     }  
  186.   
  187.     protected double getEasting()  
  188.     {  
  189.       return 500000 + (K4 * p + K5 * POW(p, 3));  
  190.     }  
  191.   
  192.     // Lat Lon to UTM variables  
  193.   
  194.     // equatorial radius  
  195.     double equatorialRadius = 6378137;  
  196.   
  197.     // polar radius  
  198.     double polarRadius = 6356752.314;  
  199.   
  200.     // flattening  
  201.     double flattening = 0.00335281066474748;// (equatorialRadius-polarRadius)/equatorialRadius;  
  202.   
  203.     // inverse flattening 1/flattening  
  204.     double inverseFlattening = 298.257223563;// 1/flattening;  
  205.   
  206.     // Mean radius  
  207.     double rm = POW(equatorialRadius * polarRadius, 1 / 2.0);  
  208.   
  209.     // scale factor  
  210.     double k0 = 0.9996;  
  211.   
  212.     // eccentricity  
  213.     double e = Math.sqrt(1 - POW(polarRadius / equatorialRadius, 2));  
  214.   
  215.     double e1sq = e * e / (1 - e * e);  
  216.   
  217.     double n = (equatorialRadius - polarRadius)  
  218.         / (equatorialRadius + polarRadius);  
  219.   
  220.     // r curv 1  
  221.     double rho = 6368573.744;  
  222.   
  223.     // r curv 2  
  224.     double nu = 6389236.914;  
  225.   
  226.     // Calculate Meridional Arc Length  
  227.     // Meridional Arc  
  228.     double S = 5103266.421;  
  229.   
  230.     double A0 = 6367449.146;  
  231.   
  232.     double B0 = 16038.42955;  
  233.   
  234.     double C0 = 16.83261333;  
  235.   
  236.     double D0 = 0.021984404;  
  237.   
  238.     double E0 = 0.000312705;  
  239.   
  240.     // Calculation Constants  
  241.     // Delta Long  
  242.     double p = -0.483084;  
  243.   
  244.     double sin1 = 4.84814E-06;  
  245.   
  246.     // Coefficients for UTM Coordinates  
  247.     double K1 = 5101225.115;  
  248.   
  249.     double K2 = 3750.291596;  
  250.   
  251.     double K3 = 1.397608151;  
  252.   
  253.     double K4 = 214839.3105;  
  254.   
  255.     double K5 = -2.995382942;  
  256.   
  257.     double A6 = -1.00541E-07;  
  258.   
  259.   }  
  260.   
  261.   private class LatLon2MGRUTM extends LatLon2UTM  
  262.   {  
  263.     public String convertLatLonToMGRUTM(double latitude, double longitude)  
  264.     {  
  265.       validate(latitude, longitude);  
  266.       String mgrUTM = "";  
  267.   
  268.       setVariables(latitude, longitude);  
  269.   
  270.       String longZone = getLongZone(longitude);  
  271.       LatZones latZones = new LatZones();  
  272.       String latZone = latZones.getLatZone(latitude);  
  273.   
  274.       double _easting = getEasting();  
  275.       double _northing = getNorthing(latitude);  
  276.       Digraphs digraphs = new Digraphs();  
  277.       String digraph1 = digraphs.getDigraph1(Integer.parseInt(longZone),  
  278.           _easting);  
  279.       String digraph2 = digraphs.getDigraph2(Integer.parseInt(longZone),  
  280.           _northing);  
  281.   
  282.       String easting = String.valueOf((int) _easting);  
  283.       if (easting.length() < 5)  
  284.       {  
  285.         easting = "00000" + easting;  
  286.       }  
  287.       easting = easting.substring(easting.length() - 5);  
  288.   
  289.       String northing;  
  290.       northing = String.valueOf((int) _northing);  
  291.       if (northing.length() < 5)  
  292.       {  
  293.         northing = "0000" + northing;  
  294.       }  
  295.       northing = northing.substring(northing.length() - 5);  
  296.   
  297.       mgrUTM = longZone + latZone + digraph1 + digraph2 + easting + northing;  
  298.       return mgrUTM;  
  299.     }  
  300.   }  
  301.   
  302.   private class MGRUTM2LatLon extends UTM2LatLon  
  303.   {  
  304.     public double[] convertMGRUTMToLatLong(String mgrutm)  
  305.     {  
  306.       double[] latlon = { 0.00.0 };  
  307.       // 02CNR0634657742  
  308.       int zone = Integer.parseInt(mgrutm.substring(02));  
  309.       String latZone = mgrutm.substring(23);  
  310.   
  311.       String digraph1 = mgrutm.substring(34);  
  312.       String digraph2 = mgrutm.substring(45);  
  313.       easting = Double.parseDouble(mgrutm.substring(510));  
  314.       northing = Double.parseDouble(mgrutm.substring(1015));  
  315.   
  316.       LatZones lz = new LatZones();  
  317.       double latZoneDegree = lz.getLatZoneDegree(latZone);  
  318.   
  319.       double a1 = latZoneDegree * 40000000 / 360.0;  
  320.       double a2 = 2000000 * Math.floor(a1 / 2000000.0);  
  321.   
  322.       Digraphs digraphs = new Digraphs();  
  323.   
  324.       double digraph2Index = digraphs.getDigraph2Index(digraph2);  
  325.   
  326.       double startindexEquator = 1;  
  327.       if ((1 + zone % 2) == 1)  
  328.       {  
  329.         startindexEquator = 6;  
  330.       }  
  331.   
  332.       double a3 = a2 + (digraph2Index - startindexEquator) * 100000;  
  333.       if (a3 <= 0)  
  334.       {  
  335.         a3 = 10000000 + a3;  
  336.       }  
  337.       northing = a3 + northing;  
  338.   
  339.       zoneCM = -183 + 6 * zone;  
  340.       double digraph1Index = digraphs.getDigraph1Index(digraph1);  
  341.       int a5 = 1 + zone % 3;  
  342.       double[] a6 = { 1608 };  
  343.       double a7 = 100000 * (digraph1Index - a6[a5 - 1]);  
  344.       easting = easting + a7;  
  345.   
  346.       setVariables();  
  347.   
  348.       double latitude = 0;  
  349.       latitude = 180 * (phi1 - fact1 * (fact2 + fact3 + fact4)) / Math.PI;  
  350.   
  351.       if (latZoneDegree < 0)  
  352.       {  
  353.         latitude = 90 - latitude;  
  354.       }  
  355.   
  356.       double d = _a2 * 180 / Math.PI;  
  357.       double longitude = zoneCM - d;  
  358.   
  359.       if (getHemisphere(latZone).equals("S"))  
  360.       {  
  361.         latitude = -latitude;  
  362.       }  
  363.   
  364.       latlon[0] = latitude;  
  365.       latlon[1] = longitude;  
  366.       return latlon;  
  367.     }  
  368.   }  
  369.   
  370.   private class UTM2LatLon  
  371.   {  
  372.     double easting;  
  373.   
  374.     double northing;  
  375.   
  376.     int zone;  
  377.   
  378.     String southernHemisphere = "ACDEFGHJKLM";  
  379.   
  380.     protected String getHemisphere(String latZone)  
  381.     {  
  382.       String hemisphere = "N";  
  383.       if (southernHemisphere.indexOf(latZone) > -1)  
  384.       {  
  385.         hemisphere = "S";  
  386.       }  
  387.       return hemisphere;  
  388.     }  
  389.   
  390.     public double[] convertUTMToLatLong(String UTM)  
  391.     {  
  392.       double[] latlon = { 0.00.0 };  
  393.       String[] utm = UTM.split(" ");  
  394.       zone = Integer.parseInt(utm[0]);  
  395.       String latZone = utm[1];  
  396.       easting = Double.parseDouble(utm[2]);  
  397.       northing = Double.parseDouble(utm[3]);  
  398.       String hemisphere = getHemisphere(latZone);  
  399.       double latitude = 0.0;  
  400.       double longitude = 0.0;  
  401.   
  402.       if (hemisphere.equals("S"))  
  403.       {  
  404.         northing = 10000000 - northing;  
  405.       }  
  406.       setVariables();  
  407.       latitude = 180 * (phi1 - fact1 * (fact2 + fact3 + fact4)) / Math.PI;  
  408.   
  409.       if (zone > 0)  
  410.       {  
  411.         zoneCM = 6 * zone - 183.0;  
  412.       }  
  413.       else  
  414.       {  
  415.         zoneCM = 3.0;  
  416.   
  417.       }  
  418.   
  419.       longitude = zoneCM - _a3;  
  420.       if (hemisphere.equals("S"))  
  421.       {  
  422.         latitude = -latitude;  
  423.       }  
  424.   
  425.       latlon[0] = latitude;  
  426.       latlon[1] = longitude;  
  427.       return latlon;  
  428.   
  429.     }  
  430.   
  431.     protected void setVariables()  
  432.     {  
  433.       arc = northing / k0;  
  434.       mu = arc  
  435.           / (a * (1 - POW(e, 2) / 4.0 - 3 * POW(e, 4) / 64.0 - 5 * POW(e, 6) / 256.0));  
  436.   
  437.       ei = (1 - POW((1 - e * e), (1 / 2.0)))  
  438.           / (1 + POW((1 - e * e), (1 / 2.0)));  
  439.   
  440.       ca = 3 * ei / 2 - 27 * POW(ei, 3) / 32.0;  
  441.   
  442.       cb = 21 * POW(ei, 2) / 16 - 55 * POW(ei, 4) / 32;  
  443.       cc = 151 * POW(ei, 3) / 96;  
  444.       cd = 1097 * POW(ei, 4) / 512;  
  445.       phi1 = mu + ca * SIN(2 * mu) + cb * SIN(4 * mu) + cc * SIN(6 * mu) + cd  
  446.           * SIN(8 * mu);  
  447.   
  448.       n0 = a / POW((1 - POW((e * SIN(phi1)), 2)), (1 / 2.0));  
  449.   
  450.       r0 = a * (1 - e * e) / POW((1 - POW((e * SIN(phi1)), 2)), (3 / 2.0));  
  451.       fact1 = n0 * TAN(phi1) / r0;  
  452.   
  453.       _a1 = 500000 - easting;  
  454.       dd0 = _a1 / (n0 * k0);  
  455.       fact2 = dd0 * dd0 / 2;  
  456.   
  457.       t0 = POW(TAN(phi1), 2);  
  458.       Q0 = e1sq * POW(COS(phi1), 2);  
  459.       fact3 = (5 + 3 * t0 + 10 * Q0 - 4 * Q0 * Q0 - 9 * e1sq) * POW(dd0, 4)  
  460.           / 24;  
  461.   
  462.       fact4 = (61 + 90 * t0 + 298 * Q0 + 45 * t0 * t0 - 252 * e1sq - 3 * Q0  
  463.           * Q0)  
  464.           * POW(dd0, 6) / 720;  
  465.   
  466.       //  
  467.       lof1 = _a1 / (n0 * k0);  
  468.       lof2 = (1 + 2 * t0 + Q0) * POW(dd0, 3) / 6.0;  
  469.       lof3 = (5 - 2 * Q0 + 28 * t0 - 3 * POW(Q0, 2) + 8 * e1sq + 24 * POW(t0, 2))  
  470.           * POW(dd0, 5) / 120;  
  471.       _a2 = (lof1 - lof2 + lof3) / COS(phi1);  
  472.       _a3 = _a2 * 180 / Math.PI;  
  473.   
  474.     }  
  475.   
  476.     double arc;  
  477.   
  478.     double mu;  
  479.   
  480.     double ei;  
  481.   
  482.     double ca;  
  483.   
  484.     double cb;  
  485.   
  486.     double cc;  
  487.   
  488.     double cd;  
  489.   
  490.     double n0;  
  491.   
  492.     double r0;  
  493.   
  494.     double _a1;  
  495.   
  496.     double dd0;  
  497.   
  498.     double t0;  
  499.   
  500.     double Q0;  
  501.   
  502.     double lof1;  
  503.   
  504.     double lof2;  
  505.   
  506.     double lof3;  
  507.   
  508.     double _a2;  
  509.   
  510.     double phi1;  
  511.   
  512.     double fact1;  
  513.   
  514.     double fact2;  
  515.   
  516.     double fact3;  
  517.   
  518.     double fact4;  
  519.   
  520.     double zoneCM;  
  521.   
  522.     double _a3;  
  523.   
  524.     double b = 6356752.314;  
  525.   
  526.     double a = 6378137;  
  527.   
  528.     double e = 0.081819191;  
  529.   
  530.     double e1sq = 0.006739497;  
  531.   
  532.     double k0 = 0.9996;  
  533.   
  534.   }  
  535.   
  536.   private class Digraphs  
  537.   {  
  538.     private Map digraph1 = new Hashtable();  
  539.   
  540.     private Map digraph2 = new Hashtable();  
  541.   
  542.     private String[] digraph1Array = { "A""B""C""D""E""F""G""H",  
  543.         "J""K""L""M""N""P""Q""R""S""T""U""V""W""X",  
  544.         "Y""Z" };  
  545.   
  546.     private String[] digraph2Array = { "V""A""B""C""D""E""F""G",  
  547.         "H""J""K""L""M""N""P""Q""R""S""T""U""V" };  
  548.   
  549.     public Digraphs()  
  550.     {  
  551.       digraph1.put(new Integer(1), "A");  
  552.       digraph1.put(new Integer(2), "B");  
  553.       digraph1.put(new Integer(3), "C");  
  554.       digraph1.put(new Integer(4), "D");  
  555.       digraph1.put(new Integer(5), "E");  
  556.       digraph1.put(new Integer(6), "F");  
  557.       digraph1.put(new Integer(7), "G");  
  558.       digraph1.put(new Integer(8), "H");  
  559.       digraph1.put(new Integer(9), "J");  
  560.       digraph1.put(new Integer(10), "K");  
  561.       digraph1.put(new Integer(11), "L");  
  562.       digraph1.put(new Integer(12), "M");  
  563.       digraph1.put(new Integer(13), "N");  
  564.       digraph1.put(new Integer(14), "P");  
  565.       digraph1.put(new Integer(15), "Q");  
  566.       digraph1.put(new Integer(16), "R");  
  567.       digraph1.put(new Integer(17), "S");  
  568.       digraph1.put(new Integer(18), "T");  
  569.       digraph1.put(new Integer(19), "U");  
  570.       digraph1.put(new Integer(20), "V");  
  571.       digraph1.put(new Integer(21), "W");  
  572.       digraph1.put(new Integer(22), "X");  
  573.       digraph1.put(new Integer(23), "Y");  
  574.       digraph1.put(new Integer(24), "Z");  
  575.   
  576.       digraph2.put(new Integer(0), "V");  
  577.       digraph2.put(new Integer(1), "A");  
  578.       digraph2.put(new Integer(2), "B");  
  579.       digraph2.put(new Integer(3), "C");  
  580.       digraph2.put(new Integer(4), "D");  
  581.       digraph2.put(new Integer(5), "E");  
  582.       digraph2.put(new Integer(6), "F");  
  583.       digraph2.put(new Integer(7), "G");  
  584.       digraph2.put(new Integer(8), "H");  
  585.       digraph2.put(new Integer(9), "J");  
  586.       digraph2.put(new Integer(10), "K");  
  587.       digraph2.put(new Integer(11), "L");  
  588.       digraph2.put(new Integer(12), "M");  
  589.       digraph2.put(new Integer(13), "N");  
  590.       digraph2.put(new Integer(14), "P");  
  591.       digraph2.put(new Integer(15), "Q");  
  592.       digraph2.put(new Integer(16), "R");  
  593.       digraph2.put(new Integer(17), "S");  
  594.       digraph2.put(new Integer(18), "T");  
  595.       digraph2.put(new Integer(19), "U");  
  596.       digraph2.put(new Integer(20), "V");  
  597.   
  598.     }  
  599.   
  600.     public int getDigraph1Index(String letter)  
  601.     {  
  602.       for (int i = 0; i < digraph1Array.length; i++)  
  603.       {  
  604.         if (digraph1Array[i].equals(letter))  
  605.         {  
  606.           return i + 1;  
  607.         }  
  608.       }  
  609.   
  610.       return -1;  
  611.     }  
  612.   
  613.     public int getDigraph2Index(String letter)  
  614.     {  
  615.       for (int i = 0; i < digraph2Array.length; i++)  
  616.       {  
  617.         if (digraph2Array[i].equals(letter))  
  618.         {  
  619.           return i;  
  620.         }  
  621.       }  
  622.   
  623.       return -1;  
  624.     }  
  625.   
  626.     public String getDigraph1(int longZone, double easting)  
  627.     {  
  628.       int a1 = longZone;  
  629.       double a2 = 8 * ((a1 - 1) % 3) + 1;  
  630.   
  631.       double a3 = easting;  
  632.       double a4 = a2 + ((int) (a3 / 100000)) - 1;  
  633.       return (String) digraph1.get(new Integer((int) Math.floor(a4)));  
  634.     }  
  635.   
  636.     public String getDigraph2(int longZone, double northing)  
  637.     {  
  638.       int a1 = longZone;  
  639.       double a2 = 1 + 5 * ((a1 - 1) % 2);  
  640.       double a3 = northing;  
  641.       double a4 = (a2 + ((int) (a3 / 100000)));  
  642.       a4 = (a2 + ((int) (a3 / 100000.0))) % 20;  
  643.       a4 = Math.floor(a4);  
  644.       if (a4 < 0)  
  645.       {  
  646.         a4 = a4 + 19;  
  647.       }  
  648.       return (String) digraph2.get(new Integer((int) Math.floor(a4)));  
  649.   
  650.     }  
  651.   
  652.   }  
  653.   
  654.   private class LatZones  
  655.   {  
  656.     private char[] letters = { 'A''C''D''E''F''G''H''J''K',  
  657.         'L''M''N''P''Q''R''S''T''U''V''W''X''Z' };  
  658.   
  659.     private int[] degrees = { -90, -84, -72, -64, -56, -48, -40, -32, -24, -16,  
  660.         -808162432404856647284 };  
  661.   
  662.     private char[] negLetters = { 'A''C''D''E''F''G''H''J''K',  
  663.         'L''M' };  
  664.   
  665.     private int[] negDegrees = { -90, -84, -72, -64, -56, -48, -40, -32, -24,  
  666.         -16, -8 };  
  667.   
  668.     private char[] posLetters = { 'N''P''Q''R''S''T''U''V''W',  
  669.         'X''Z' };  
  670.   
  671.     private int[] posDegrees = { 08162432404856647284 };  
  672.   
  673.     private int arrayLength = 22;  
  674.   
  675.     public LatZones()  
  676.     {  
  677.     }  
  678.   
  679.     public int getLatZoneDegree(String letter)  
  680.     {  
  681.       char ltr = letter.charAt(0);  
  682.       for (int i = 0; i < arrayLength; i++)  
  683.       {  
  684.         if (letters[i] == ltr)  
  685.         {  
  686.           return degrees[i];  
  687.         }  
  688.       }  
  689.       return -100;  
  690.     }  
  691.   
  692.     public String getLatZone(double latitude)  
  693.     {  
  694.       int latIndex = -2;  
  695.       int lat = (int) latitude;  
  696.   
  697.       if (lat >= 0)  
  698.       {  
  699.         int len = posLetters.length;  
  700.         for (int i = 0; i < len; i++)  
  701.         {  
  702.           if (lat == posDegrees[i])  
  703.           {  
  704.             latIndex = i;  
  705.             break;  
  706.           }  
  707.   
  708.           if (lat > posDegrees[i])  
  709.           {  
  710.             continue;  
  711.           }  
  712.           else  
  713.           {  
  714.             latIndex = i - 1;  
  715.             break;  
  716.           }  
  717.         }  
  718.       }  
  719.       else  
  720.       {  
  721.         int len = negLetters.length;  
  722.         for (int i = 0; i < len; i++)  
  723.         {  
  724.           if (lat == negDegrees[i])  
  725.           {  
  726.             latIndex = i;  
  727.             break;  
  728.           }  
  729.   
  730.           if (lat < negDegrees[i])  
  731.           {  
  732.             latIndex = i - 1;  
  733.             break;  
  734.           }  
  735.           else  
  736.           {  
  737.             continue;  
  738.           }  
  739.   
  740.         }  
  741.   
  742.       }  
  743.   
  744.       if (latIndex == -1)  
  745.       {  
  746.         latIndex = 0;  
  747.       }  
  748.       if (lat >= 0)  
  749.       {  
  750.         if (latIndex == -2)  
  751.         {  
  752.           latIndex = posLetters.length - 1;  
  753.         }  
  754.         return String.valueOf(posLetters[latIndex]);  
  755.       }  
  756.       else  
  757.       {  
  758.         if (latIndex == -2)  
  759.         {  
  760.           latIndex = negLetters.length - 1;  
  761.         }  
  762.         return String.valueOf(negLetters[latIndex]);  
  763.   
  764.       }  
  765.     }  
  766.   
  767.   }  
  768.   
  769. }  


     补充:Excel转换工具GeogTools:http://www.dimensionengine.com/excel/geogtools/
0 0
原创粉丝点击