Skip to content

Commit 8c4a244

Browse files
authored
resolve #609 (#796)
1 parent 5883ef4 commit 8c4a244

File tree

2 files changed

+14
-31
lines changed

2 files changed

+14
-31
lines changed

libpysal/cg/alpha_shapes.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import numpy as np
1313
import scipy.spatial as spat
14+
import shapely
1415
from scipy import sparse
1516

1617
from ..common import HAS_JIT, jit, requires
@@ -22,13 +23,6 @@
2223
"Numba not imported, so alpha shape construction may be slower than expected."
2324
)
2425

25-
try:
26-
import shapely
27-
28-
HAS_SHAPELY = True
29-
except (ModuleNotFoundError, AssertionError):
30-
HAS_SHAPELY = False
31-
3226

3327
EPS = np.finfo(float).eps
3428

@@ -464,10 +458,7 @@ def _valid_hull(geoms, points):
464458
if geoms.shape[0] != 1:
465459
return False
466460
# if any (xys) points do not intersect the polygon
467-
if HAS_SHAPELY:
468-
return shapely.intersects(geoms[0], points).all()
469-
else:
470-
return all(point.intersects(geoms[0]) for point in points)
461+
return shapely.intersects(geoms[0], points).all()
471462

472463

473464
@requires("geopandas", "shapely")
@@ -564,7 +555,7 @@ def alpha_shape_auto(
564555
triangles = triangulation.simplices[radii_sorted_i][::-1]
565556
radii = radii[radii_sorted_i][::-1]
566557
geoms_prev = _alpha_geoms((1 / radii.max()) - EPS, triangles, radii, xys)
567-
points = shapely.points(xys) if HAS_SHAPELY else [geom.Point(pnt) for pnt in xys]
558+
points = shapely.points(xys)
568559
if verbose:
569560
print("Step set to %i" % step)
570561
for i in range(0, len(radii), step):

libpysal/weights/util.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# ruff: noqa: N802, N803
2+
13
import copy
24
import numbers
35
import os
@@ -6,12 +8,11 @@
68
from warnings import warn
79

810
import numpy as np
9-
10-
# ruff: noqa: N802, N803
1111
import scipy
1212
import scipy.spatial
1313
from scipy import sparse
1414
from scipy.spatial import KDTree
15+
from shapely.geometry.base import BaseGeometry
1516

1617
from ..common import requires
1718
from ..io.fileio import FileIO
@@ -24,12 +25,6 @@
2425
except ImportError:
2526
warn("geopandas not available. Some functionality will be disabled.", stacklevel=2)
2627

27-
try:
28-
from shapely.geometry.base import BaseGeometry
29-
30-
HAS_SHAPELY = True
31-
except ImportError:
32-
HAS_SHAPELY = False
3328

3429
__all__ = [
3530
"lat2W",
@@ -1045,17 +1040,14 @@ def get_points_array(iterable):
10451040
"""
10461041
first_choice, backup = tee(iterable)
10471042
try:
1048-
if HAS_SHAPELY:
1049-
data = np.vstack(
1050-
[
1051-
np.array(shape.centroid.coords)[0]
1052-
if isinstance(shape, BaseGeometry)
1053-
else np.array(shape.centroid)
1054-
for shape in first_choice
1055-
]
1056-
)
1057-
else:
1058-
data = np.vstack([np.array(shape.centroid) for shape in first_choice])
1043+
data = np.vstack(
1044+
[
1045+
np.array(shape.centroid.coords)[0]
1046+
if isinstance(shape, BaseGeometry)
1047+
else np.array(shape.centroid)
1048+
for shape in first_choice
1049+
]
1050+
)
10591051
except AttributeError:
10601052
data = np.vstack(list(backup))
10611053
return data

0 commit comments

Comments
 (0)