代码之家  ›  专栏  ›  技术社区  ›  M. Usman Khan

地理坐标(长、纬度)至米(x、y)

  •  2
  • M. Usman Khan  · 技术社区  · 8 年前

    我的工作坐标系如下所示:

    enter image description here

    x和y以米为单位。我只对正x,y感兴趣。我想将(x,y)转换为(lat,lon),反之亦然。

    我认为这很简单,我认为下面的解决方案没有问题。但我没有得到非常正确的结果。

    我的解决方案:

    如下图所示,我将纬度和经度视为两个圆的角度:

    enter image description here

    1.(x,y)至(lat,lon)

    我应用了弧长公式( here ),如下所示,在两个上;x和y enter image description here enter image description here

    因此,我的职能是:

    private static double calculateLat(float x) {
        int earthRadius = 6371000;
        return REF_LOC.getLatitude() + x*360/(2*PI*earthRadius);
    }
    
    private static double calculateLong(float y) {
        int earthRadius = 6371000;
        return REF_LOC.getLongitude() + y*360/(2*PI*earthRadius);
    }
    

    REF\u LOC是(x,y)为(0,0)的参考地理位置。它可以是地球上的任何一点。

    2.(纬度,经度)至(x,y)

    为此,我仅使用以下方法:

    int calculateX(double longitude){
            Location.distanceBetween(REF_LOC.getLatitude(), REF_LOC.getLongitude(),
                    REF_LOC.getLatitude(), lonDeg, results);
            return results[0];
    }
    
    int calculateY(double latitude){
            Location.distanceBetween(REF_LOC.getLatitude(), REF_LOC.getLongitude(),
                    latDeg, REF_LOC.getLongitude(), results);
            return results[0];
    }
    

    但我得到的结果不一致。首先,我使用解决方案1并将一些值(x,y)转换为(lat,long)。但是,当我使用解决方案2将相同的(lat,long)返回到(x,y)时,我得到了x中约2米的差值和y中约10米的差值。有人能帮我确定问题吗?

    1 回复  |  直到 8 年前
        1
  •  1
  •   user2711811 user2711811    8 年前

    提到我对球面与椭圆计算的评论,另一种看待球面与椭圆距离的距离计算差异的方法是使用两个可用的实用程序:

    // For REF_LOC = (70, 20)
    
    // Compute a lat/lng due east of a REF_LOC and compute distance using both
    // available methods.
    
    LatLng P = SphericalUtil.computeOffsetOrigin(REF_LOC, 20000, 90.0);
    
    // And then compute a distance 
    d = SphericalUtil.computeDistanceBetween(REF_LOC, P);
    Location.distanceBetween(REF_LOC.latitude, REF_LOC.longitude, P.latitude, P.longitude, results);
    
    // d = 20000.000000000036
    // results[0] = 20081.818
    
    
    // and for a REF_LOC = (0, 20)
    // d = 20000.000000000127
    // results[0] = 20022.377
    

    另一个有趣的是SphericalUtil。computeOffsetOrigin()产生错误 纬度从赤道到极点的增加使其不对称。然而,由此产生的距离基本上是精确的。

    我建议使用SphericalUtil。computeOffsetOrigin计算X/Y断裂 正如您所做的那样,将其转换为纬度和经度偏移。

    最后演示SphericalUtil解决方案:

    // Start with some arbitrary x/y relative to REF_LOC
    double Rx = 125.0;
    double Ry = 73.0;
    
    // Compute a lat/lon from REF_LOC to the point
    LatLng Rll = new LatLng(SphericalUtil.computeOffsetOrigin(REF_LOC, Ry, 180).latitude,
                SphericalUtil.computeOffsetOrigin(REF_LOC, Rx, 270).longitude);
    
    // And recompute the x/y components of the lat/lon
    
    double Rxx = SphericalUtil.computeDistanceBetween(REF_LOC, new LatLng(REF_LOC.latitude, Rll.longitude));
    double Ryy = SphericalUtil.computeDistanceBetween(REF_LOC, new LatLng(Rll.latitude, REF_LOC.longitude));
    

    导致:

    Rx/Ry   = (125.0, 73.0)
    Rxx/Ryy = (125.00000004545973, 73.00000000137051)
    

    我认为这是可以接受的错误。

    所以分离的问题是-x/y真正代表什么?

    有关更多信息,请参考这两个实用程序的源代码:

    Location

    SphericalUtil