From 5412b394f90a6b31de2ed73b200c0ee761bd78b7 Mon Sep 17 00:00:00 2001 From: Christian Ledermann Date: Tue, 3 Dec 2024 21:11:14 +0000 Subject: [PATCH] Add max_leaves parameter to geometry_collections function to determine recursion depth --- pygeoif/hypothesis/strategies.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pygeoif/hypothesis/strategies.py b/pygeoif/hypothesis/strategies.py index 1432670..1a9dc1b 100644 --- a/pygeoif/hypothesis/strategies.py +++ b/pygeoif/hypothesis/strategies.py @@ -548,6 +548,7 @@ def geometry_collections( # noqa: PLR0913 max_points: int = 20, min_interiors: int = 0, max_interiors: int = 5, + max_leaves: int = 3, srs: Optional[Srs] = None, has_z: Optional[bool] = None, ) -> GeometryCollection: @@ -557,17 +558,20 @@ def geometry_collections( # noqa: PLR0913 Args: ---- draw (st.DrawFn): The Hypothesis draw function. - min_geoms (int, optional): The minimum number of geometries in the collection. - max_geoms (int, optional): The maximum number of geometries in the collection. - max_points (int, optional): The maximum number of points in each geometry. - min_interiors (int, optional): The minimum number of interiors in each polygon. - max_interiors (int, optional): The maximum number of interiors in each polygon. + min_geoms (int): The minimum number of geometries in the collection. + max_geoms (int): The maximum number of geometries in the collection. + max_points (int): The maximum number of points in each geometry. + min_interiors (int): The minimum number of interiors in each polygon. + max_interiors (int): The maximum number of interiors in each polygon. srs (Optional[Srs], optional): The spatial reference system of the geometries. has_z (Optional[bool], optional): Whether the geometries have Z coordinates. + max_leaves (int): The maximum recursion depth of the collection. Returns: ------- - GeometryCollection: A randomly generated GeometryCollection object. + GeometryCollection: A randomly generated GeometryCollection object, that may + contain any of the following geometries: Point, LineString, LinearRing, + Polygon, MultiPoint, MultiLineString, MultiPolygon, GeometryCollection. """ if has_z is None: @@ -612,7 +616,7 @@ def geometry_collections( # noqa: PLR0913 has_z=has_z, ), lambda children: children, - max_leaves=3, + max_leaves=max_leaves, ), ), min_size=min_geoms,