DeprecationWarning:此函数已弃用。请参阅:https://pyproj4.github.io/pyproj/stable/gotchas.html#upgrading-to-pyproj-2-from-pyproj-1

DeprecationWarning: This function is deprecated. See: https://pyproj4.github.io/pyproj/stable/gotchas.html#upgrading-to-pyproj-2-from-pyproj-1

我正在使用 Jupyter notebook 并编写了以下代码:

#!pip install shapely
import shapely.geometry

#!pip install pyproj
import pyproj
from pyproj import Transformer

import math

def lonlat_to_xy(lon, lat):
    proj_latlon = pyproj.Proj(proj='latlong',datum='WGS84')
    proj_xy = pyproj.Proj(proj="utm", zone=33, datum='WGS84')
    xy = pyproj.transform(proj_latlon, proj_xy, lon, lat)
    return xy[0], xy[1]

def xy_to_lonlat(x, y):
    proj_latlon = pyproj.Proj(proj='latlong',datum='WGS84')
    proj_xy = pyproj.Proj(proj="utm", zone=33, datum='WGS84')
    lonlat = pyproj.transform(proj_xy, proj_latlon, x, y)
    return lonlat[0], lonlat[1]

def calc_xy_distance(x1, y1, x2, y2):
    dx = x2 - x1
    dy = y2 - y1
    return math.sqrt(dx*dx + dy*dy)

print('Coordinate transformation check')
print('-------------------------------')
print('Melboourne center longitude={}, latitude={}'.format(loc.longitude, loc.latitude))
x, y = lonlat_to_xy(loc.longitude, loc.latitude)
print('Melboourne center UTM X={}, Y={}'.format(x, y))
lo, la = xy_to_lonlat(x, y)
print('Melboourne center longitude={}, latitude={}'.format(lo, la))

//输出结果如下

Coordinate transformation check
-------------------------------
Melboourne center longitude=144.9631608, latitude=-37.8142176
Melboourne center UTM X=4980281.116219562, Y=-14408028.424977692
Melboourne center longitude=144.96316080000003, latitude=-37.814217600000006
<ipython-input-3-e6ddd172b39b>:13: DeprecationWarning: This function is deprecated. See: https://pyproj4.github.io/pyproj/stable/gotchas.html#upgrading-to-pyproj-2-from-pyproj-1
  xy = pyproj.transform(proj_latlon, proj_xy, lon, lat)
<ipython-input-3-e6ddd172b39b>:19: DeprecationWarning: This function is deprecated. See: https://pyproj4.github.io/pyproj/stable/gotchas.html#upgrading-to-pyproj-2-from-pyproj-1
  lonlat = pyproj.transform(proj_xy, proj_latlon, x, y)

我不知道需要进行哪些更改才能停止显示“DeprecationWarning”消息。

使用它来忽略警告:

import warnings
warnings.filterwarnings('ignore')