Skip to content

Commit 585f693

Browse files
committed
Avoids empty geometries for parts of Points
1 parent 66ed8c4 commit 585f693

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/normit/geo/ops.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ def of(self,
6363
return result.intersection(sector)
6464

6565
def part_of(self, geometry: shapely.geometry.base.BaseGeometry):
66+
# points cannot be divided into parts
67+
if isinstance(geometry, shapely.Point | shapely.MultiPoint):
68+
return geometry
69+
# calculate diameter and centroid
6670
d = shapely.minimum_bounding_radius(geometry) * 2
6771
c = geometry.centroid
6872
# create point at azimuth 0 (North) and rotate (negative = clockwise)

test/test_geo_ops.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ def test_inner_regions(georeader: GeoJsonDirReader):
3131
assert NorthEast.part_of(india).intersection(gorakhpur).area > 0
3232
assert SouthWest.part_of(india).intersection(gorakhpur).area == 0
3333

34+
# SouthWest part of a point is the point
35+
kintbury = georeader.read(21517801)
36+
assert SouthWest.part_of(kintbury) == kintbury
37+
3438

3539
def test_outer_regions(georeader: GeoJsonDirReader):
3640
az = georeader.read(162018)

0 commit comments

Comments
 (0)