diff --git a/geo_extensions/transformations/cartesian.py b/geo_extensions/transformations/cartesian.py index 29c24ca..b3bf4c5 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: Polygon) -> TransformationResult: - """Perform a shapely simplify operation on the polygon.""" + def simplify_polygon_transform(polygon: Polygon) -> TransformationResult: # NOTE(reweeden): I have been unable to produce a situation where a # polygon is simplified to a geometry other than Polygon. yield cast( @@ -44,7 +47,7 @@ def simplify(polygon: Polygon) -> TransformationResult: ), ) - return simplify + return simplify_polygon_transform def split_polygon_on_antimeridian_ccw(polygon: Polygon) -> TransformationResult: @@ -87,7 +90,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 +101,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: @@ -152,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/geo_extensions/transformations/general.py b/geo_extensions/transformations/general.py index 9197542..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,10 +38,11 @@ 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 """ - 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 +53,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..a308f3b 100644 --- a/geo_extensions/transformations/geodetic.py +++ b/geo_extensions/transformations/geodetic.py @@ -42,10 +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: - """Densify the polygon by adding additional points along the great - circle arcs between the existing points. - """ + def densify_polygon_transform(polygon: Polygon) -> TransformationResult: yield Polygon( shell=_densify_ring(polygon.exterior.coords, tolerance_meters), holes=[ @@ -55,7 +52,7 @@ def densify(polygon: Polygon) -> TransformationResult: ], ) - return densify + return densify_polygon_transform def _densify_ring( 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: -------- | / | \ 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)