Skip to content

Commit 1e2563b

Browse files
authored
Use largest multipolygon ring to set label points (#18)
1 parent bdf9d7c commit 1e2563b

2 files changed

Lines changed: 82 additions & 8 deletions

File tree

tasks/make_boundaries/exploration/labels.ipynb

Lines changed: 74 additions & 6 deletions
Large diffs are not rendered by default.

tasks/make_boundaries/src/usecases/make_admin_labels.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@
1414
label_subs: Dict[str, geometry.Point] = {}
1515

1616

17-
def get_label_point(x: geometry.Polygon):
17+
def get_label_point(x: geometry.Polygon | geometry.MultiPolygon):
1818
xfact = 0.7
19+
geom = (
20+
max(x.geoms, key=lambda x: x.area)
21+
if isinstance(x, geometry.MultiPolygon)
22+
else x
23+
)
24+
1925
return affinity.scale(
20-
ops.polylabel(affinity.scale(x, xfact=xfact, yfact=1), 0.1),
26+
ops.polylabel(affinity.scale(geom, xfact=xfact, yfact=1), 0.1),
2127
xfact=1 / xfact,
2228
yfact=1,
2329
)

0 commit comments

Comments
 (0)