2014-12-06 60 views
0

我正在尝试创建这个http://www.ibm.com/developerworks/library/j-coordconvert/-军事网格参考系统的可视网格。我有纬度/经度UTM同时也MGRS ......其中Ar无法循环播放对象

17牛逼330649 4689666

17TLG3064989666

但是从MGRS当进入北纬我得到如下: [[email protected]

public class CoordinateConversion { 
    public static void main(String args[]) { 

     CoordinateConversion test = new CoordinateConversion(); 
     CoordinateConversion test2 = new CoordinateConversion(); 
     test.latLon2UTM(35.58, 82.56); 
     System.out.println(test.latLon2UTM(42.340837, -83.055821)); 
     System.out.println(); 
     test2.latLon2UTM(35.58, 82.56); 
     System.out.println(test2.latLon2MGRUTM(42.340837, -83.055821)); 

     CoordinateConversion test3 = new CoordinateConversion(); 
     test3.latLon2UTM(35.58, 82.56); 
     //System.out.print(test3.mgrutm2LatLong(42.340837, -83.055821)); 
     //System.out.println(test3.mgrutm2LatLong("02CNR0634657742")); 


     MGRUTM2LatLon mg = new MGRUTM2LatLon(); 
     //mg.convertMGRUTMToLatLong("02CNR0634657742"); 
     String MGRUTM = "17TLG3064989666"; 
     System.out.println(mg.convertMGRUTMToLatLong(MGRUTM)); 
     //for loop to be developed 

    } 

    public double[] utm2LatLon(String UTM) { 
     UTM2LatLon c = new UTM2LatLon(); 
     return c.convertUTMToLatLong(UTM); 
    } 

    public double[] mgrutm2LatLon(String MGRUTM) { 
     MGRUTM2LatLon c = new MGRUTM2LatLon(); 
     return c.convertMGRUTMToLatLong(MGRUTM); 
    } 
} 

,并从这个类:

public double[] convertMGRUTMToLatLong(String mgrutm) { 
    double[] latlon = {0.0, 0.0}; 
    // 02CNR0634657742 
    int zone = Integer.parseInt(mgrutm.substring(0, 2)); 
    String latZone = mgrutm.substring(2, 3); 

    String digraph1 = mgrutm.substring(3, 4); 
    String digraph2 = mgrutm.substring(4, 5); 
    easting = Double.parseDouble(mgrutm.substring(5, 10)); 
    northing = Double.parseDouble(mgrutm.substring(10, 15)); 

    LatZones lz = new LatZones(); 
    double latZoneDegree = lz.getLatZoneDegree(latZone); 

    double a1 = latZoneDegree * 40000000/360.0; 
    double a2 = 2000000 * Math.floor(a1/2000000.0); 

    Digraphs digraphs = new Digraphs(); 

    double digraph2Index = digraphs.getDigraph2Index(digraph2); 

    double startindexEquator = 1; 
    if ((1 + zone % 2) == 1) { 
     startindexEquator = 6; 
    } 

    double a3 = a2 + (digraph2Index - startindexEquator) * 100000; 
    if (a3 <= 0) { 
     a3 = 10000000 + a3; 
    } 
    northing = a3 + northing; 

    zoneCM = -183 + 6 * zone; 
    double digraph1Index = digraphs.getDigraph1Index(digraph1); 
    int a5 = 1 + zone % 3; 
    double[] a6 = {16, 0, 8}; 
    double a7 = 100000 * (digraph1Index - a6[a5 - 1]); 
    easting = easting + a7; 

    setVariables(); 

    double latitude = 0; 
    latitude = 180 * (phi1 - fact1 * (fact2 + fact3 + fact4))/Math.PI; 

    if (latZoneDegree < 0) { 
     latitude = 90 - latitude; 
    } 

    double d = _a2 * 180/Math.PI; 
    double longitude = zoneCM - d; 

    if (getHemisphere(latZone).equals("S")) { 
     latitude = -latitude; 
    } 

    latlon[0] = latitude; 
    latlon[1] = longitude; 
    return latlon; 
} 

我试图不进入一个大型图书馆,在那里我将不得不学习可能非常耗时的事情。

所以我想循环,所以我去东(东)和北(北),不能超过我有一点 - 纬度/经度的点。

希望我已经清楚地问过我的问题,没有太多说明。

任何帮助将不胜感激。

谢谢, -Terry

+0

重写正在尝试打印的类中的'toString()'。 – csmckelvey 2014-12-06 18:30:08

回答

0

在convertMGRUTMToLatLong(String s)方法中,返回一个数组latlon(即一个对象)。 它返回它可能是你不想要的哈希码。 您想要打印数组值。所以在你的主要方法中,你可以在下面替换;

System.out.println(mg.convertMGRUTMToLatLong(MGRUTM)); 

double[] a = mg.convertMGRUTMToLatLong(MGRUTM) ; 
System.out.println(a[0]+" " + a[1]); 

希望帮助!

+1

这样做nanosoft ...谢谢。这个链接http://stackoverflow.com/help/privileges/vote-up说我应该可以投票了。我没有看到箭头。我的声望是15.想要这样做,但不知道如何。 – 2014-12-06 19:15:17

+0

找到了投票的箭头。 – 2014-12-06 19:24:09

+0

很高兴知道它的工作原理:) – nanosoft 2014-12-07 16:10:15

1

convertMGRUTMToLatLong()你的结果是double秒的阵列,并且通过默认,阵列被转换为字符串在Java中一个相当不可读格式。这就是[[email protected]的来源。试试System.out.println(Arrays.toString(mg.convertMGRUTMToLatLong(MGRUTM)));,你会得到一个更可读的输出。

+0

迈克尔,从纳米软件上面的答案工作,但为了将来的参考,只要你的回应,我是从字面上读“阵列”。因为我得到“阵列无法解决”。可能会想出来,但还没有。 – 2014-12-06 21:25:53

+0

像大多数其他类一样,在使用它之前需要导入'Arrays'类 - 在程序的顶部添加'import java.util.Arrays;'。 – 2014-12-07 15:44:04