【问题标题】:pyproj FutureWarning: '+init=<authority>:<code>' syntax is deprecatedpyproj FutureWarning: '+init=<authority>:<code>' 语法已弃用
【发布时间】:2020-04-10 01:38:32
【问题描述】:

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]))

【问题讨论】:

    标签: python pyproj


    【解决方案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)
    

    【讨论】:

      【解决方案2】:

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

          #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]))
      

      【讨论】:

      • 使用 always_xy;引用 pyproj docs: The axis order may be swapped if the source and destination CRS’s are defined as having the first coordinate component point in a northerly direction (See PROJ FAQ on axis order). You can check the axis order with the pyproj.crs.CRS class. If you prefer to keep your axis order as always x,y, you can use the always_xy option when creating the pyproj.transformer.Transformer.
      • @Ionut Ticus - 这对我来说是希腊语。我对语法弃用解决方法很感兴趣
      猜你喜欢
      • 1970-01-01
      • 2022-01-20
      • 1970-01-01
      • 2017-05-02
      • 2021-11-02
      • 2021-06-24
      • 2014-04-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多