How to convert pyproj1 to pyproj2 when calculate circle?

51 views Asked by At

I used code as below to calculate circle coordinates for give center point:

from shapely import ops
from shapely.geometry import Point
from pyproj import Proj, transform
from functools import partial

def circleByPoint(lat, lon, km=5):
    proj_wgs84 = Proj('+proj=longlat +datum=WGS84')
    aeqd_proj = '+proj=aeqd +lat_0={lat} +lon_0={lon} +x_0=0 +y_0=0'
    project = partial(transform, 
    Proj(aeqd_proj.format(lat=lat, lon=lon)), proj_wgs84)
    buf = Point(0, 0).buffer(km * 1000)  # distance in metres
    return ops.transform(project, buf).exterior.coords[:]

after I upgraded to pyproj 3.6.0, I got wanrning message

C:\Program Files\python\Lib\site-packages\shapely\ops.py:276: FutureWarning: This function is deprecated. See: https://pyproj4.github.io/pyproj/stable/gotchas.html#upgrading-to-pyproj-2-from-pyproj-1
shell = type(geom.exterior)(zip(*func(*zip(*geom.exterior.coords))))

Then I checked https://pyproj4.github.io/pyproj/stable/gotchas.html#upgrading-to-pyproj-2-from-pyproj-1, there is a example as below:

Old code:

from functools import partial
from pyproj import Proj, transform
proj_4326 = Proj(init="epsg:4326")
proj_3857 = Proj(init="epsg:3857")
transformer = partial(transform, proj_4326, proj_3857)
transformer(12, 12)

New code:

from pyproj import Transformer
transformer = Transformer.from_crs("EPSG:4326", "EPSG:3857")
transformer.transform(12, 12)

But I still don't know how to modify my code, does anyone help me?

1

There are 1 answers

0
mikezang On

I got the answer as below:

from shapely.ops import transform
from shapely.geometry import Point
from pyproj import Transformer, CRS

def circleByPoint(lat, lon, km=5):
    proj_wgs84 = CRS('EPSG:4326')
    proj_aeqd = CRS(f'+proj=aeqd +lat_0={lat} +lon_0={lon} +x_0=0 +y_0=0')
    transformer = Transformer.from_crs(proj_aeqd, proj_wgs84, always_xy=True)
    buf = Point(0, 0).buffer(km * 1000)  # distance in metres
    return transform(transformer.transform, buf).exterior.coords[:]