Skip to content

Commit 3565943

Browse files
authored
Allow point comparison (#149)
1 parent 870cedb commit 3565943

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

spatialpandas/geometry/_algorithms/intersection.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -511,18 +511,12 @@ def polygons_intersect_bounds(
511511
if y1 < y0:
512512
y0, y1, = y1, y0
513513

514-
if x0 == x1 or y0 == y1:
515-
# Zero width/height rect does not intersect with anything
516-
return
517-
518514
for i in range(n):
519515
_perform_polygon_intersect_bounds(
520516
i, x0, y0, x1, y1, flat_values,
521517
start_offsets0, stop_offsets0, offsets1, result
522518
)
523519

524-
return result
525-
526520

527521
@ngjit
528522
def multipolygons_intersect_bounds(
@@ -561,10 +555,6 @@ def multipolygons_intersect_bounds(
561555
if y1 < y0:
562556
y0, y1, = y1, y0
563557

564-
if x0 == x1 or y0 == y1:
565-
# Zero width/height rect does not intersect with anything
566-
return
567-
568558
# Populate results
569559
for i in range(n):
570560
polygon_offsets = offsets1[start_offsets0[i]:stop_offsets0[i] + 1]

spatialpandas/tests/geometry/test_cx.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ def test_polygon_cx_selection(gp_polygon, rect):
9999
assert all(expected == result)
100100

101101

102+
@pytest.mark.slow
103+
def test_polygon_cx_selection_point():
104+
import geopandas as gpd
105+
from shapely.geometry import shape
106+
107+
geometry = {"type": "Polygon", "coordinates": [[[0, 50], [20, 50], [50, 20], [50, 0]]]}
108+
gp_multipolygon = gpd.GeoSeries([shape(geometry)])
109+
xslice, yslice = slice(None, 0, None), slice(50, None, None)
110+
expected = PolygonArray.from_geopandas(gp_multipolygon.cx[xslice, yslice])
111+
result = PolygonArray.from_geopandas(gp_multipolygon).cx[xslice, yslice]
112+
assert all(expected == result)
113+
102114
@pytest.mark.slow
103115
@given(
104116
st_multipolygon_array(min_size=1, geoseries=True),
@@ -122,6 +134,18 @@ def test_multipolygon_cx_selection(gp_multipolygon, rect):
122134
assert all(expected == result)
123135

124136

137+
@pytest.mark.slow
138+
def test_multipolygon_cx_selection_point():
139+
import geopandas as gpd
140+
from shapely.geometry import shape
141+
142+
geometry = {"type": "MultiPolygon", "coordinates": [[[[0, 50], [20, 50], [50, 20], [50, 0]]]]}
143+
gp_multipolygon = gpd.GeoSeries([shape(geometry)])
144+
xslice, yslice = slice(None, 0, None), slice(50, None, None)
145+
expected = MultiPolygonArray.from_geopandas(gp_multipolygon.cx[xslice, yslice])
146+
result = MultiPolygonArray.from_geopandas(gp_multipolygon).cx[xslice, yslice]
147+
assert all(expected == result)
148+
125149
@given(st_multipoint_array(min_size=1, geoseries=True), st_bounds(orient=True))
126150
@hyp_settings
127151
def test_multipoint_cx_series_selection(gp_multipoint, rect):

0 commit comments

Comments
 (0)