Assuming the curve/polyline data isn’t too messy, a simpler approach might be to make boundary surfaces (which essentially handles the grouping for you):
180419_BoundarySurfaces.gh (14.4 KB)
This probably won’t scale too well (i.e. will be slow), but should be fairly predictable/stable.