Skip to content

Commit

Permalink
raise for older GEOS
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfleis committed Jan 21, 2024
1 parent b8beba6 commit 16036eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 7 additions & 1 deletion shapely/constructive.py
Expand Up @@ -4,6 +4,7 @@
from shapely._enum import ParamEnum
from shapely.algorithms._oriented_envelope import _oriented_envelope_min_area
from shapely.decorators import multithreading_enabled, requires_geos
from shapely.errors import UnsupportedGEOSVersionError

__all__ = [
"BufferCapStyle",
Expand Down Expand Up @@ -966,7 +967,7 @@ def voronoi_polygons(
ordered : bool or array_like, default False
If set to True, polygons within the GeometryCollection will be ordered
according to the order of the input vertices. Note that this may slow
down the computation.
down the computation. Requires GEOS >= 3.12.0
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Expand All @@ -989,6 +990,11 @@ def voronoi_polygons(
>>> voronoi_polygons(points, ordered=True)
<GEOMETRYCOLLECTION (POLYGON ((0 0, 0 4, 3 4, 3 0, 0 0)), POLYGON ((6 4, 6 0...>
"""
if ordered and lib.geos_version < (3, 12, 0):
raise UnsupportedGEOSVersionError(
"Ordered Voronoi polygons require GEOS >= 3.12.0, "
f"found {lib.geos_version_string}"
)
return lib.voronoi_polygons(
geometry, tolerance, extend_to, only_edges, ordered, **kwargs
)
Expand Down
8 changes: 4 additions & 4 deletions src/ufuncs.c
Expand Up @@ -1979,17 +1979,17 @@ static void voronoi_polygons_func(char** args, const npy_intp* dimensions, const
double in2 = *(double*)ip2;
npy_bool in4 = *(npy_bool*)ip4;
npy_bool in5 = *(npy_bool*)ip5;
int last_arg = 0;
int flag = 0;
if (in4) {
last_arg = 1;
flag = 1;
} else if (in5) {
last_arg = 2;
flag = 2;
}
if ((in1 == NULL) || npy_isnan(in2)) {
/* propagate NULL geometries; in3 = NULL is actually supported */
geom_arr[i] = NULL;
} else {
geom_arr[i] = GEOSVoronoiDiagram_r(ctx, in1, in3, in2, last_arg);
geom_arr[i] = GEOSVoronoiDiagram_r(ctx, in1, in3, in2, flag);
if (geom_arr[i] == NULL) {
errstate = PGERR_GEOS_EXCEPTION;
destroy_geom_arr(ctx, geom_arr, i - 1);
Expand Down

0 comments on commit 16036eb

Please sign in to comment.