lat/lon to utm to lat/lon is extremely flawed, how come?

前端 未结 4 1642
野的像风
野的像风 2020-12-05 20:47

I\'ve tried the following, input: lat/lon data then I\'ll calculate a box around it by, let\'s say 50 m, so +/- 50 m on easting/northing value.

Now I reconvert it t

相关标签:
4条回答
  • 2020-12-05 20:59

    I have no problem with pyproj, try the following code

    from pyproj import Proj
    
    Lat = 52.063098675
    Lon = -114.132980348 #Calgary
    
    ZoneNo = "11" #Manually input, or calcuated from Lat Lon
    myProj = Proj("+proj=utm +zone="+ZoneNo+",\
    +north +ellps=WGS84 +datum=WGS84 +units=m +no_defs") #north for north hemisphere
    UTMx, UTMy = myProj(Lon, Lat)
    
    ########################################
    
    #UTM ==> Lat Lon:
    ZoneNo = "11" #Manually input or from other sources
    myProj = Proj("+proj=utm +zone="+\
    ZoneNo+", +north +ellps=WGS84 +datum=WGS84 +units=m +no_defs")
    Lon2, Lat2 = myProj(UTMx, UTMy,inverse=True)
    
    print Lat2
    print Lon2
    
    0 讨论(0)
  • 2020-12-05 21:08

    I've created a small UTM conversion library for Python last week and uploaded it to the Python Package Index: http://pypi.python.org/pypi/utm

    I have compared it to using pyproj and it is faster and more accurate. Given your sample data, this is the result:

    >>> import utm
    
    >>> u = utm.from_latlon(47.9941214, 7.8509671)
    >>> print u
    (414278, 5316285, 32, 'T')
    
    >>> print utm.to_latlon(*u)
    (47.994157948891505, 7.850963967574302)
    

    UPDATE: Richards answer below describes the real solution for this issue.

    0 讨论(0)
  • 2020-12-05 21:14

    Your issue with pyProj sounds just like the one described here:

    http://code.google.com/p/pyproj/issues/detail?id=3

    which is resolved:

    solved! in epsg file there must be

    <2392> +proj=tmerc +lat_0=0 +lon_0=24 +k=1.000000 +x_0=2500000 +y_0=0 +ellps=intl +towgs84=-90.7,-106.1,-119.2,4.09,0.218,-1.05,1.37 +units=m +no_defs no_defs <>

    note the towgs84 parameter!

    Check that thread out if you want to continue to use pyproj.

    Also, does the test() function of the module work? Have you tried any of the scripts that come with it in the test directory?

    0 讨论(0)
  • 2020-12-05 21:21

    The error is in your code.

    First off, the PyProj issue listed in one of the other answers is real. You should check your epsg file and make sure it includes the line

    <2392> +proj=tmerc +lat_0=0 +lon_0=24 +k=1.000000 +x_0=2500000 +y_0=0 +ellps=intl +towgs84=-90.7,-106.1,-119.2,4.09,0.218,-1.05,1.37 +units=m +no_defs no_defs <>
    

    Note the towgs84 parameter.

    Your problem with PyProj stems from mis-using the projection command.

    If we take 47.9941214N, 7.8509671E and convert to UTM we get Zone 32, 414278 Easting, 5316286 Northing.

    You perform the following PyProj operations:

    p = pyproj.Proj(proj='utm', zone=32, ellps='WGS84')
    >>> x,y = p(47.9941214, 7.8509671)
    >>> print x,y
    5159550.36822 1114087.43925
    >>> print p(x,y,inverse=True)
    (47.971558538495991, 7.8546573140162605)
    

    But, if we consult the PyProj documentation, we see the following:

    Calling a Proj class instance with the arguments lon, lat will convert lon/lat (in degrees) to x/y native map projection coordinates (in meters).

    Let's try running the OP's PyProj operations again, but switch the order of the lon/lat arguments:

    p = pyproj.Proj(proj='utm', zone=32, ellps='WGS84')
    >>> x,y = p(7.8509671, 47.9941214)
    >>> print x,y
    414278.16731 5316285.59492
    >>> print p(x,y,inverse=True)
    (7.850967099999812, 47.994121399999784)
    

    The operation inverts itself (pretty much) perfectly!

    To answer the first part of your question, if you look in http://robotics.ai.uiuc.edu/~hyoon24/LatLongUTMconversion.py at the definition of UTMtoLL, you find the following:

    UTMtoLL(ReferenceEllipsoid, northing, easting, zone)
    

    Yet you use UTMtoLL(23, leftUTM, topUTM, zone) where leftUTM is an Easting and topUTM is a Northing.

    Therefore, in the case of both your first script and PyProj, you've used the wrong order of arguments.

    It's a good reminder to always double- (or triple-) check your work before suggesting that someone else's is wrong. That said, Python's documentation is not the greatest and PyProj's documentation in this instance is cryptic at best. A nice web-based explanation of this command and accompanied by examples of its usage would have probably prevented angst on your part.

    0 讨论(0)
提交回复
热议问题