I am trying to create iso-area polygons ("donuts") from a set of outlines. This is the process:
- Creating contours.
- Sorts the contours into a tree structure so that all contours held in a particular contour are children of that contour.
- For each path, perform a pegging operation with all its children using Clipperlib.
The resulting polygon and holes are a donut of the iso-region. These iso-areas can be displayed as a contour map or used for other purposes. Please note that if all I wanted to do was display the outlines, I could stop after the initial sort and display the outlines in order so that the inner display is on top. I really need actual areas.
First up - Clipperlib is a fantastic library and I would be very happy to pay good money - thanks Angus!
My problem is that I seem to get some strange results from a difference operation in certain situations - I suspect that this may be a user error on my part, so I will illustrate the problem:

This image shows two polygons: the object is highlighted in red, and the children are filled in blue. I want to subtract children from the topic. Notice the small area next to the mouse pointer. What I expect from this fault is the two outer polygons - small next to the mouse pointer and large. I would expect all the “islands” to be holes in the second, large, polygon.
What I actually get is two outputs (as expected), with children (holes) associated with each:


In the second image, the tiny polygon near the mouse pointer is “external”, and all other filled polygons are “holes” belonging to it. Note that I show the outlines of both solutions in both images - just focus on the filled polygons.
I am doing clipperlib using the red polygon in the first image as an object, and all the children as clips. The clip type is ctDifference (I also tried Xor with the same results - what they should be, considering that all children are within the object). I ask for the return of PolyTree, which has two Childs. I am using the C # library and also tried v6.
At one level, the results that I need are all there - all the “holes” are labeled as such, the problem is that many of these holes come back as children of a tiny outer area in the upper right corner of the image. Am I reading PolyTree incorrectly using ClipperLib incorrectly, or is this result simply incorrect?
In the next note - I noticed that the new ClipperLib (v6) now takes Z values. Now I wonder if there can be a better method than I use to create these iso-areas from a given set of non-standard contour lines?
thanks Matt
EDIT: I loaded the raw data for the polygons in a text file.
here's a link
There is a subject polygon in the file as the first set of vertices, followed by each of these children. Each polygon is represented as X / Y pairs on the same line, with a new line between each polygon.