Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize lasso selection by applying box-select first #5061

Merged
merged 1 commit into from
Aug 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions holoviews/element/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,29 @@ def spatial_select_columnar(xvals, yvals, geometry):
except Exception:
xvals = np.asarray(xvals)
yvals = np.asarray(yvals)
x0, x1 = geometry[:, 0].min(), geometry[:, 0].max()
y0, y1 = geometry[:, 1].min(), geometry[:, 1].max()
mask = (xvals>=x0) & (xvals<=x1) & (yvals>=y0) & (yvals<=y1)
masked_xvals = xvals[mask]
masked_yvals = yvals[mask]
try:
from spatialpandas.geometry import Polygon, PointArray
points = PointArray((xvals.astype('float'), yvals.astype('float')))
points = PointArray((masked_xvals.astype('float'), masked_yvals.astype('float')))
poly = Polygon([np.concatenate([geometry, geometry[:1]]).flatten()])
return points.intersects(poly)
geom_mask = points.intersects(poly)
except Exception:
pass
try:
from shapely.geometry import Point, Polygon
points = (Point(x, y) for x, y in zip(xvals, yvals))
points = (Point(x, y) for x, y in zip(masked_xvals, masked_yvals))
poly = Polygon(geometry)
return np.array([poly.contains(p) for p in points])
geom_mask = np.array([poly.contains(p) for p in points])
except ImportError:
raise ImportError("Lasso selection on tabular data requires "
"either spatialpandas or shapely to be available.")
mask[np.where(mask)[0]] = geom_mask
return mask


def spatial_select(xvals, yvals, geometry):
if xvals.ndim > 1:
Expand Down