Converting projected coordinates to lat/lon using Python?

  • I assume this is a basic question but I can't seem to find or recognize the solution.

    This site returns

    Point:
    X: -11705274.6374
    Y: 4826473.6922
    

    when you searching with the first key value of 000090 as an example. I guess this is a spatial reference and I kinda get what that is.

    I am looking for instructions or examples of how to convert this to Latitude and longitude using Python.

  • The simplest way to transform coordinates in Python is pyproj, i.e. the Python interface to PROJ.4 library. In fact:

    from pyproj import Proj, transform
    
    inProj = Proj(init='epsg:3857')
    outProj = Proj(init='epsg:4326')
    x1,y1 = -11705274.6374,4826473.6922
    x2,y2 = transform(inProj,outProj,x1,y1)
    print x2,y2
    

    returns -105.150271116 39.7278572773


    EDIT based on Marc's comment:

    pyproj 2.4 gives a FutureWarning about deprecated Proj initialization with the init= syntax. The updated syntax is identical but without the init=. Like this:

    inProj = Proj('epsg:3857')
    outProj = Proj('epsg:4326')
    

    Yep. Pyproj all the way.

    It works for me

    pyproj 2.4 gives a FutureWarning about deprecated Proj() initialization with the `init=` syntax. The updated syntax is identical but without the `init=`. Like this: `inProj = Proj('epsg:3857')` and `outProj = Proj('epsg:4326')`

    I removed the `'init='` based on the edit, but my output of `transform(inProj,outProj,x1,y1)` gave me `(latitude, longitude)` instead of `(longitude, latitude)`. Anybody knows why ?

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM