I have a list of polygons, inside this list, some of the polygons are overlapping, or touches other polygons.
My task is to merge all the polygons that are overlapped or touched with each other. I have a union
method that does this.
What is the most efficient way to do this? What I can think of currently is to loop though the polygon list, check against the merged list to see whether this polygon is somehow belonging already to one of the polygons in the merged list, if yes, union them, if no, add this polygon to the end of the merged list.
Repeat the above steps again for a few times to make sure that all polygons are properly combined.
This approach seems very inelegant; is there a better way to do this?