pythonpyproj

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


I am using Jupyter notebook and I have written the following code:

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

// The output is as follows

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)

I can't figure out what changes are required to stop the "DeprecationWarning" message being displayed.


Solution

  • Use this to ignore the warnings:

    import warnings
    warnings.filterwarnings('ignore')