From cd1cd64dd74a9f25145e4e7954f6ebb8d2e937dd Mon Sep 17 00:00:00 2001 From: Rohan Weeden Date: Wed, 24 Dec 2025 15:07:43 -0500 Subject: [PATCH 1/4] Rename inner functions to `*_transform` --- geo_extensions/transformations/cartesian.py | 8 ++++---- geo_extensions/transformations/general.py | 4 ++-- geo_extensions/transformations/geodetic.py | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/geo_extensions/transformations/cartesian.py b/geo_extensions/transformations/cartesian.py index 29c24ca..47c5fb6 100644 --- a/geo_extensions/transformations/cartesian.py +++ b/geo_extensions/transformations/cartesian.py @@ -32,7 +32,7 @@ def simplify_polygon(tolerance: float, preserve_topology: bool = True) -> Transf :returns: a callable transformation using the passed parameters """ - def simplify(polygon: Polygon) -> TransformationResult: + def simplify_polygon_transform(polygon: Polygon) -> TransformationResult: """Perform a shapely simplify operation on the polygon.""" # NOTE(reweeden): I have been unable to produce a situation where a # polygon is simplified to a geometry other than Polygon. @@ -44,7 +44,7 @@ def simplify(polygon: Polygon) -> TransformationResult: ), ) - return simplify + return simplify_polygon_transform def split_polygon_on_antimeridian_ccw(polygon: Polygon) -> TransformationResult: @@ -87,7 +87,7 @@ def split_polygon_on_antimeridian_fixed_size( :returns: a callable transformation using the passed parameters """ - def split(polygon: Polygon) -> TransformationResult: + def split_polygon_transform(polygon: Polygon) -> TransformationResult: if not polygon_crosses_antimeridian_fixed_size(polygon, min_lon_extent): yield polygon return @@ -98,7 +98,7 @@ def split(polygon: Polygon) -> TransformationResult: for polygon in new_polygons: yield _shift_polygon_back(polygon) - return split + return split_polygon_transform def _shift_polygon(polygon: Polygon) -> Polygon: diff --git a/geo_extensions/transformations/general.py b/geo_extensions/transformations/general.py index 9197542..bef378e 100644 --- a/geo_extensions/transformations/general.py +++ b/geo_extensions/transformations/general.py @@ -33,7 +33,7 @@ def round_points(ndigits: SupportsIndex) -> Transformation: :returns: a callable transformation using the passed parameters """ - def round_points_(polygon: Polygon) -> TransformationResult: + def round_points_transform(polygon: Polygon) -> TransformationResult: """Round the polygon's points.""" yield Polygon( shell=(_round_coord(coord, ndigits) for coord in polygon.exterior.coords), @@ -44,7 +44,7 @@ def round_points_(polygon: Polygon) -> TransformationResult: ], ) - return round_points_ + return round_points_transform def _round_coord( diff --git a/geo_extensions/transformations/geodetic.py b/geo_extensions/transformations/geodetic.py index 131dc1c..9d6d24f 100644 --- a/geo_extensions/transformations/geodetic.py +++ b/geo_extensions/transformations/geodetic.py @@ -42,7 +42,7 @@ def densify_polygon(tolerance_meters: float) -> Transformation: if tolerance_meters <= 0: raise ValueError("'tolerance_meters' must be greater than 0") - def densify(polygon: Polygon) -> TransformationResult: + def densify_polygon_transform(polygon: Polygon) -> TransformationResult: """Densify the polygon by adding additional points along the great circle arcs between the existing points. """ @@ -55,7 +55,7 @@ def densify(polygon: Polygon) -> TransformationResult: ], ) - return densify + return densify_polygon_transform def _densify_ring( From dc269ad3081c70c8bb6b72f423169af632609485 Mon Sep 17 00:00:00 2001 From: Rohan Weeden Date: Wed, 24 Dec 2025 15:48:02 -0500 Subject: [PATCH 2/4] Improve docstrings and make them consistent --- geo_extensions/transformations/cartesian.py | 5 ++++- geo_extensions/transformations/general.py | 13 +++++++++++-- geo_extensions/transformations/geodetic.py | 3 --- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/geo_extensions/transformations/cartesian.py b/geo_extensions/transformations/cartesian.py index 47c5fb6..2aee1b2 100644 --- a/geo_extensions/transformations/cartesian.py +++ b/geo_extensions/transformations/cartesian.py @@ -29,11 +29,14 @@ def simplify_polygon(tolerance: float, preserve_topology: bool = True) -> Transformation: """CARTESIAN: Create a transformation that calls polygon.simplify. + :param tolerance: coordinates of the simplified geometry will be no more + than the tolerance distance from the original + :param preserve_topology: unless the topology preserving option is used, the + algorithm may produce self-intersecting or otherwise invalid geometries :returns: a callable transformation using the passed parameters """ def simplify_polygon_transform(polygon: Polygon) -> TransformationResult: - """Perform a shapely simplify operation on the polygon.""" # NOTE(reweeden): I have been unable to produce a situation where a # polygon is simplified to a geometry other than Polygon. yield cast( diff --git a/geo_extensions/transformations/general.py b/geo_extensions/transformations/general.py index bef378e..39293e1 100644 --- a/geo_extensions/transformations/general.py +++ b/geo_extensions/transformations/general.py @@ -10,12 +10,20 @@ def reverse_polygon(polygon: Polygon) -> TransformationResult: - """Perform a shapely reverse operation on the polygon.""" + """Perform a shapely reverse operation on the polygon. + + :param polygon: the input polygon + :return: a generator yielding the transformed polygon + """ yield polygon.reverse() def drop_z_coordinate(polygon: Polygon) -> TransformationResult: - """Drop the third element from each coordinate in the polygon.""" + """Drop the third element from each coordinate in the polygon. + + :param polygon: the input polygon + :return: a generator yielding the transformed polygon + """ yield Polygon( shell=((x, y) for x, y, *_ in polygon.exterior.coords), holes=[ @@ -30,6 +38,7 @@ def round_points(ndigits: SupportsIndex) -> Transformation: """Create a transformation that rounds polygon points to a given number of digits. + :param ndigits: number of digits to round to :returns: a callable transformation using the passed parameters """ diff --git a/geo_extensions/transformations/geodetic.py b/geo_extensions/transformations/geodetic.py index 9d6d24f..a308f3b 100644 --- a/geo_extensions/transformations/geodetic.py +++ b/geo_extensions/transformations/geodetic.py @@ -43,9 +43,6 @@ def densify_polygon(tolerance_meters: float) -> Transformation: raise ValueError("'tolerance_meters' must be greater than 0") def densify_polygon_transform(polygon: Polygon) -> TransformationResult: - """Densify the polygon by adding additional points along the great - circle arcs between the existing points. - """ yield Polygon( shell=_densify_ring(polygon.exterior.coords, tolerance_meters), holes=[ From 2276aace930835d6c5bc337d6f129ba5cf93a2fe Mon Sep 17 00:00:00 2001 From: Rohan Weeden Date: Wed, 24 Dec 2025 15:48:19 -0500 Subject: [PATCH 3/4] Fix spelling issues --- geo_extensions/transformations/cartesian.py | 2 +- tests/conftest.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/geo_extensions/transformations/cartesian.py b/geo_extensions/transformations/cartesian.py index 2aee1b2..b3bf4c5 100644 --- a/geo_extensions/transformations/cartesian.py +++ b/geo_extensions/transformations/cartesian.py @@ -155,7 +155,7 @@ def _split_polygon( def _ignore_polygon(polygon: Polygon) -> bool: min_lon, _, max_lon, _ = polygon.bounds # We want to ignore any tiny slivers of polygons that might barely cross - # the antimeridian. For CMR, the polygons don't need to be that precice + # the antimeridian. For CMR, the polygons don't need to be that precise # and we're rounding to 179.999 anyway. So realistically we don't want any # polygons that are contained within the +/-0.001 degrees around the # antimeridian. Due to possible floating point errors in the distance diff --git a/tests/conftest.py b/tests/conftest.py index 7a8ac4b..ea9d1e9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -11,7 +11,7 @@ def data_path(): @pytest.fixture def rectangle(): - """A rectanglular polygon""" + """A rectangular polygon""" polygon = Polygon( [ (160.0, 60.0), @@ -29,7 +29,7 @@ def rectangle(): @pytest.fixture def centered_rectangle(): - """A rectanglular polygon centered at 0, 0""" + """A rectangular polygon centered at 0, 0""" polygon = Polygon( [ (-30.0, 10.0), @@ -47,7 +47,7 @@ def centered_rectangle(): @pytest.fixture def antimeridian_centered_rectangle(): - """A rectanglular polygon centered over the antimeridian""" + """A rectangular polygon centered over the antimeridian""" polygon = Polygon( [ (150.0, 10.0), @@ -66,7 +66,7 @@ def antimeridian_centered_rectangle(): @pytest.fixture def multi_crossing_polygon(): r"""A polygon that looks something like this, crossing back and forth - accross the IDL multiple times: + across the IDL multiple times: -------- | / | \ From 403c214616b40cd5c4f65a60cf082fcbdc246e27 Mon Sep 17 00:00:00 2001 From: Rohan Weeden Date: Wed, 24 Dec 2025 15:48:29 -0500 Subject: [PATCH 4/4] Remove unused unpack statement --- tests/strategies.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/strategies.py b/tests/strategies.py index 06b053e..8e803c4 100644 --- a/tests/strategies.py +++ b/tests/strategies.py @@ -5,7 +5,6 @@ def assume_valid_polygon(polygon): - (minx, _, maxx, _) = polygon.bounds assume(polygon.area > 0.01) simplified = shapely.remove_repeated_points(polygon.simplify(0)) assume(len(simplified.exterior.coords) > 4)