From 8da79a344e69be93d4e4a4af643aebec0038d2e8 Mon Sep 17 00:00:00 2001 From: "Alan D. Snow" Date: Thu, 11 Dec 2025 15:08:37 -0600 Subject: [PATCH] CLN:warp: Deprecate antimeridian_cutting & antimeridian_offset in transform_geom (#3474) --- rasterio/_warp.pyx | 7 +++++-- rasterio/warp.py | 44 +++++++++++++++++++++----------------------- tests/test_warp.py | 35 ++++++++++++++++++++--------------- 3 files changed, 46 insertions(+), 40 deletions(-) diff --git a/rasterio/_warp.pyx b/rasterio/_warp.pyx index 8fb21ba8..78b2f439 100644 --- a/rasterio/_warp.pyx +++ b/rasterio/_warp.pyx @@ -88,8 +88,11 @@ cdef object _transform_single_geom( def _transform_geom( - src_crs, dst_crs, geom, antimeridian_cutting, antimeridian_offset, - int precision): + src_crs, + dst_crs, + geom, + int precision, +): """Return a transformed geometry.""" cdef char **options = NULL cdef OGRCoordinateTransformationH transform = NULL diff --git a/rasterio/warp.py b/rasterio/warp.py index 9728ad7c..f7c36850 100644 --- a/rasterio/warp.py +++ b/rasterio/warp.py @@ -1,6 +1,7 @@ """Raster warping and reprojection.""" from math import ceil, floor +import warnings from affine import Affine import numpy as np @@ -10,8 +11,8 @@ import rasterio from rasterio._base import _transform from rasterio.crs import CRS from rasterio.enums import Resampling -from rasterio.env import ensure_env, require_gdal_version -from rasterio.errors import TransformError, RPCError +from rasterio.env import ensure_env +from rasterio.errors import TransformError, RPCError, RasterioDeprecationWarning from rasterio.transform import array_bounds from rasterio._warp import ( _calculate_default_transform, @@ -61,17 +62,14 @@ def transform(src_crs, dst_crs, xs, ys, zs=None): @ensure_env -@require_gdal_version('2.1', param='antimeridian_cutting', values=[False], - is_max_version=True, - reason="Antimeridian cutting is always enabled on " - "GDAL >= 2.2") def transform_geom( - src_crs, - dst_crs, - geom, - antimeridian_cutting=True, - antimeridian_offset=10.0, - precision=-1): + src_crs, + dst_crs, + geom, + antimeridian_cutting=None, + antimeridian_offset=None, + precision=-1, +): """Transform geometry from source coordinate reference system into target. Parameters @@ -82,14 +80,10 @@ def transform_geom( dst_crs: CRS or dict Target coordinate reference system. geom: GeoJSON like dict object or iterable of GeoJSON like objects. - antimeridian_cutting: bool, optional - If True, cut geometries at the antimeridian, otherwise geometries - will not be cut (default). If False and GDAL is 2.2.0 or newer - an exception is raised. Antimeridian cutting is always on as of - GDAL 2.2.0 but this could produce an unexpected geometry. + antimeridian_cutting: bool + DEPRECATED: Always enabled since GDAL 2.2. antimeridian_offset: float - Offset from the antimeridian in degrees (default: 10) within which - any geometries will be split. + DEPRECATED: No longer has any effect since GDAL 2.2. precision: float If >= 0, geometry coordinates will be rounded to this number of decimal places after the transform operation, otherwise original coordinate @@ -100,14 +94,18 @@ def transform_geom( out: GeoJSON like dict object or list of GeoJSON like objects. Transformed geometry(s) in GeoJSON dict format """ - + if antimeridian_cutting is not None or antimeridian_offset is not None: + warnings.warn( + "The antimeridian_cutting and antimeridian_offset parameters are " + "deprecated and no longer have any effect.", + RasterioDeprecationWarning, + ) return _transform_geom( src_crs, dst_crs, geom, - antimeridian_cutting, - antimeridian_offset, - precision) + precision, + ) def transform_bounds( diff --git a/tests/test_warp.py b/tests/test_warp.py index 3bc5007b..f02cfe5e 100644 --- a/tests/test_warp.py +++ b/tests/test_warp.py @@ -17,7 +17,7 @@ from rasterio.crs import CRS from rasterio.enums import Resampling from rasterio.errors import ( CRSError, - GDALVersionError, + RasterioDeprecationWarning, TransformError, RPCError, WarpOperationError, @@ -1185,34 +1185,38 @@ def polygon_3373(): def test_transform_geom_polygon_cutting(polygon_3373): geom = polygon_3373 - result = transform_geom("EPSG:3373", "EPSG:4326", geom, antimeridian_cutting=True) + with pytest.warns(RasterioDeprecationWarning): + result = transform_geom("EPSG:3373", "EPSG:4326", geom, antimeridian_cutting=True) assert result["type"] == "MultiPolygon" assert len(result["coordinates"]) == 2 def test_transform_geom_polygon_offset(polygon_3373): geom = polygon_3373 - result = transform_geom( - "EPSG:3373", "EPSG:4326", geom, antimeridian_cutting=True, antimeridian_offset=0 - ) + with pytest.warns(RasterioDeprecationWarning): + result = transform_geom( + "EPSG:3373", "EPSG:4326", geom, antimeridian_cutting=True, antimeridian_offset=0 + ) assert result["type"] == "MultiPolygon" assert len(result["coordinates"]) == 2 def test_transform_geom_polygon_precision(polygon_3373): geom = polygon_3373 - result = transform_geom( - "EPSG:3373", "EPSG:4326", geom, precision=1, antimeridian_cutting=True - ) + with pytest.warns(RasterioDeprecationWarning): + result = transform_geom( + "EPSG:3373", "EPSG:4326", geom, precision=1, antimeridian_cutting=True + ) assert all(round(x, 1) == x for x in flatten_coords(result["coordinates"])) def test_transform_geom_linestring_precision(polygon_3373): ring = polygon_3373["coordinates"][0] geom = {"type": "LineString", "coordinates": ring} - result = transform_geom( - "EPSG:3373", "EPSG:4326", geom, precision=1, antimeridian_cutting=True - ) + with pytest.warns(RasterioDeprecationWarning): + result = transform_geom( + "EPSG:3373", "EPSG:4326", geom, precision=1, antimeridian_cutting=True + ) assert all(round(x, 1) == x for x in flatten_coords(result["coordinates"])) @@ -1226,9 +1230,10 @@ def test_transform_geom_linestring_precision_iso(polygon_3373): def test_transform_geom_linearring_precision(polygon_3373): ring = polygon_3373["coordinates"][0] geom = {"type": "LinearRing", "coordinates": ring} - result = transform_geom( - "EPSG:3373", "EPSG:4326", geom, precision=1, antimeridian_cutting=True - ) + with pytest.warns(RasterioDeprecationWarning): + result = transform_geom( + "EPSG:3373", "EPSG:4326", geom, precision=1, antimeridian_cutting=True + ) assert all(round(x, 1) == x for x in flatten_coords(result["coordinates"])) @@ -1881,7 +1886,7 @@ def test_transform_geom_gdal22(): unexpected geometries, so an exception is raised. """ geom = {"type": "Point", "coordinates": [0, 0]} - with pytest.raises(GDALVersionError): + with pytest.warns(RasterioDeprecationWarning): transform_geom("EPSG:4326", "EPSG:3857", geom, antimeridian_cutting=False)