fgassert / split_donuts

GIS utility to split complex multipolygons into simple polygons (closed rings without holes or multiple parts)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GIS utility to split complex multipolygons into simple polygons (closed rings without holes or multiple parts)

Dependencies

Use

1. join_donuts.py Cut donuts by joining interior holes to the exterior via closest points (reccomended)

Usage: join_donuts.py <in_shp> <out_shp>

-or-

2. split_donuts.py Split donuts horizontally across holes

Usage: split_donuts.py <in_shp> <out_shp>

Algorithm

join_donuts.py works as follows

  1. For each feature in a collection
  2. If it is a multipolygon split it into separate polygons
  3. For each polygon, check if it has any interior rings (holes)
  4. For each interior ring, find the closest point in the exterior ring to the centroid of the interior ring
  5. Then find the closest point in the interior ring to the point we just found
  6. Join the two rings together such that an edge now links the closest point in the exterior to the closest point in the interior, and treat this as the new exterior ring.
  7. Repeat steps 4-6 for the remaining interior rings with the new exterior ring
  8. Return the resulting polygons

split_donuts.py works as follows

  1. For each feature in a collection
  2. If it is a multipolygon split it into separate polygons
  3. For each polygon, check if it has any interior rings (holes)
  4. Pick a point in the hole. Return the left half and right half of the polygon.
  5. For each resulting polygon recursively check for holes
  6. Return the resulting polygons

Tests

tests.py

e.g. multip.shp is split as follows: multip.shp join_donuts.py multip.shp outjoin.shp outjoin.shp split_donuts.py multip.shp out.shp out.shp

About

GIS utility to split complex multipolygons into simple polygons (closed rings without holes or multiple parts)


Languages

Language:Python 100.0%