Yeah, I tried passing the tracing algorithm a map with a one pixel buffer around it with the pixels set to -99999. It works for most contours, producing nice connected shapes on the borders. But for a few contours, it kind of goes the wrong way...so I end up with a big contour that sort of goes in and out at the edges and makes a single contour when there should be five or six...don't quite understand why since the map is normalised between zero and one before this step.

Not quite sure I follow the bit about "contour at five will be outside contour at ten which will be...". A contour at height 5 will not necessarily contain a given contour at height 10, will it? Although it might, it's not guaranteed, and I need a guaranteed parent-child relationship between all contours....at the moment I'm running point in polygon tests, so I test all contours to see what contours are inside them. Then I run a test to see if a contour contains child contours that are also children of the children of that contour, and repeat until there is a structured hierarchy. It actually works, even if my explanation sucks, except for those contours I mentioned earlier that aren't being separated properly...