python - pyproj future 警告 : '+init=<authority>:<code>' syntax is deprecated

标签 python pyproj

Open Street Map (pyproj). How to solve syntax issue? 有一个类似的问题,那里的答案对我没有帮助。

我在下面使用了数百次辅助类,我的控制台充满了警告:

/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-order-changes-in-proj-6

当我尝试按照提示使用时:

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

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

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

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)

关于python - pyproj future 警告 : '+init=<authority>:<code>' syntax is deprecated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60973894/

相关文章:

python - 更改模型序列化程序中的字段类型而不更改模型

python - 如何从命令行探索 python 文件

python - 相当于 pyGTK 中的 "weight"参数?

python - 在 python 字典中编辑值

python - 运行时错误: b'no arguments in initialization list'

python - 安装错误:Pyproj

python-3.x - 重新投影 Xarray 数据集

python - 如何使用数组中文件名的前两个字母来标记图像?

python - 如何使用 Python 获取 GeoJSON 多边形的面积

matplotlib-basemap - 为什么 cartopy 和 basemap 的反函数计算距离的结果不同?