Skip to content

Commit

Permalink
Deal with depcrecation warnings (fmaussion#245)
Browse files Browse the repository at this point in the history
* Deal with depcrecation warnings

* Ups
  • Loading branch information
fmaussion authored and benatouba committed Jul 9, 2024
1 parent aedba6d commit d4116a3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
13 changes: 8 additions & 5 deletions salem/gis.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

try:
from osgeo import osr
osr.UseExceptions()
has_gdal = True
except ImportError:
has_gdal = False
Expand Down Expand Up @@ -1259,7 +1260,6 @@ def proj_is_same(p1, p2):
"""
if has_gdal:
# this is more robust, but gdal is a pain
osr.UseExceptions()
s1 = osr.SpatialReference()
s1.ImportFromProj4(p1.srs)
s2 = osr.SpatialReference()
Expand All @@ -1275,7 +1275,11 @@ def proj_is_same(p1, p2):
def _transform_internal(p1, p2, x, y, **kwargs):
if hasattr(pyproj, 'Transformer'):
trf = pyproj.Transformer.from_proj(p1, p2, **kwargs)
return trf.transform(x, y)
with warnings.catch_warnings():
# https://github.com/pyproj4/pyproj/issues/1415
warnings.filterwarnings("ignore", category=DeprecationWarning,
message=".*ndim > 0 to a scalar.*")
return trf.transform(x, y)
else:
return pyproj.transform(p1, p2, x, y, **kwargs)

Expand Down Expand Up @@ -1397,9 +1401,9 @@ def transform_geopandas(gdf, from_crs=None, to_crs=wgs84, inplace=False):
to_crs = to_crs.srs
elif isinstance(to_crs, Grid):
to_crs = None
result.crs = to_crs
result.set_crs(to_crs, allow_override=True, inplace=True)
out.geometry = result
out.crs = to_crs
out.set_crs(to_crs, allow_override=True, inplace=True)
out['min_x'] = [g.bounds[0] for g in out.geometry]
out['max_x'] = [g.bounds[2] for g in out.geometry]
out['min_y'] = [g.bounds[1] for g in out.geometry]
Expand Down Expand Up @@ -1441,7 +1445,6 @@ def proj_to_cartopy(proj):
srs = proj.srs
if has_gdal:
# this is more robust, as srs could be anything (espg, etc.)
from osgeo import osr
s1 = osr.SpatialReference()
s1.ImportFromProj4(proj.srs)
if s1.ExportToProj4():
Expand Down
3 changes: 1 addition & 2 deletions salem/tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ def create_dummy_shp(fname):
i_line = shpg.LinearRing([(1.4, 1.4), (1.6, 1.4), (1.6, 1.6), (1.4, 1.6)])
p1 = shpg.Polygon(e_line, [i_line])
p2 = shpg.Polygon([(2.5, 1.3), (3., 1.8), (2.5, 2.3), (2, 1.8)])
df = gpd.GeoDataFrame()
df = gpd.GeoDataFrame(crs='EPSG:4326', geometry=gpd.GeoSeries([p1, p2]))
df['name'] = ['Polygon', 'Line']
df.set_geometry(gpd.GeoSeries([p1, p2]), inplace=True)
of = os.path.join(testdir, fname)
df.to_file(of)
return of
Expand Down

0 comments on commit d4116a3

Please sign in to comment.