pyproj FutureWarning: '+init=<authority>:<code>' 语法已弃用
pyproj FutureWarning: '+init=<authority>:<code>' syntax is deprecated
Open Street Map (pyproj). How to solve syntax issue?
有一个类似的问题,那里的答案对我没有帮助。
我使用助手 class 已经有几百次了,我的控制台充满了警告:
/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]))
这是我目前对修复的猜测:
#e4326=Proj(init='epsg:4326')
e4326=CRS('EPSG:4326')
#e3857=Proj(init='epsg:3857')
e3857=CRS('EPSG:3857')
投影助手class
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]))
为了继续使用旧语法(为转换器提供 (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)
Open Street Map (pyproj). How to solve syntax issue? 有一个类似的问题,那里的答案对我没有帮助。
我使用助手 class 已经有几百次了,我的控制台充满了警告:
/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]))
这是我目前对修复的猜测:
#e4326=Proj(init='epsg:4326')
e4326=CRS('EPSG:4326')
#e3857=Proj(init='epsg:3857')
e3857=CRS('EPSG:3857')
投影助手class
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]))
为了继续使用旧语法(为转换器提供 (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)