skills/tabular/strtree-spatial-index-collision/SKILL.md
Use Shapely STRtree spatial index for O(n log n) polygon overlap detection instead of brute-force O(n^2) pairwise checks
npx skillsauth add wenmin-wu/ds-skills tabular-strtree-spatial-index-collisionInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Checking all pairs of polygons for overlap is O(n^2). Shapely's STRtree builds an R-tree spatial index, so query(polygon) returns only nearby candidates whose bounding boxes intersect. This reduces collision detection to O(n log n) in practice, enabling real-time overlap validation for packing, placement, and geospatial problems with hundreds of polygons.
from shapely.strtree import STRtree
from shapely.geometry import Polygon
def has_any_overlap(polygons):
if len(polygons) <= 1:
return False
tree = STRtree(polygons)
for i, poly in enumerate(polygons):
candidates = tree.query(poly)
for idx in candidates:
if idx == i:
continue
if poly.intersects(polygons[idx]) and not poly.touches(polygons[idx]):
return True
return False
def find_overlapping_pairs(polygons):
tree = STRtree(polygons)
pairs = []
for i, poly in enumerate(polygons):
for idx in tree.query(poly):
if idx > i and poly.intersects(polygons[idx]) \
and not poly.touches(polygons[idx]):
pairs.append((i, idx))
return pairs
STRtree from all polygons (one-time O(n log n) cost)query returns indices of candidates with overlapping bounding boxesintersects only on candidates (not all n polygons)intersects (overlap) from touches (shared boundary only)not touchesDecimal to avoid float artifactsdata-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF