pyproj FutureWarning: '+init=<authority>:<code>' 语法已弃用



打开街道地图(pyproj(。如何解决语法问题?有一个类似的问题,那里的答案对我没有帮助。

我已经使用了几百次下面的助手类,我的控制台上充斥着警告:

/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyproj/crs/crs.py:53: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6
return _prepare_from_string(" ".join(pjargs))

https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-订单变更-in-proj-6

当我尝试使用来遵循提示时

return transform(Proj('epsg:4326'), Proj('epsg:3857'), lon,lat)

在原始代码工作的情况下,我得到了一些(inf,inf(结果。避免语法错误但得到相同结果的正确方法是什么

  • https://gis.stackexchange.com/questions/164043/how-to-create-a-projection-from-a-crs-string-using-pyproj

显示了旧语法,但没有显示兼容新语句的代码示例。

https://github.com/pyproj4/pyproj/issues/224状态:

*What is the preferred way of loading EPSG CRSes now?
use "EPSG:XXXX" in source_crs or target_crs arguments of proj_create_crs_to_crs() when creating a transformation, or as argument of proj_create() to instanciate a CRS object*

作为一个代码示例,这意味着什么

从pyproj导入Proj,转换

class Projection:
@staticmethod
def wgsToXy(lon,lat):
return transform(Proj(init='epsg:4326'), Proj(init='epsg:3857'), lon,lat)
@staticmethod
def pointToXy(point):
xy=point.split(",")
return Projection.wgsToXy(float(xy[0]),float(xy[1]))

为了继续使用旧语法(为转换器(Lon,Lat)对供电(,您可以在创建转换器对象时使用always_xy=True参数:

from pyproj import Transformer
transformer = Transformer.from_crs(4326, 3857, always_xy=True)
points = [
(6.783333, 51.233333),  # Dusseldorf
(-122.416389, 37.7775)  # San Francisco
]
for pt in transformer.itransform(points):
print(pt)

输出

(755117.1754412088, 6662671.876828446)
(-13627330.088231295, 4548041.532457043)

这是我目前对修复的猜测:

#e4326=Proj(init='epsg:4326')
e4326=CRS('EPSG:4326')
#e3857=Proj(init='epsg:3857')
e3857=CRS('EPSG:3857')

投影辅助类

from pyproj import Proj, CRS,transform
class Projection:
'''
helper to project lat/lon values to map
'''
#e4326=Proj(init='epsg:4326')
e4326=CRS('EPSG:4326')
#e3857=Proj(init='epsg:3857')
e3857=CRS('EPSG:3857')
@staticmethod
def wgsToXy(lon,lat):
t1=transform(Projection.e4326,Projection.e3857, lon,lat)
#t2=transform(Proj('epsg:4326'), Proj('epsg:3857'), lon,lat)
return t1
@staticmethod
def pointToXy(point):
xy=point.split(",")
return Projection.wgsToXy(float(xy[0]),float(xy[1]))

最新更新