# Most optimal algorithm for contour correctness?

Am creating an app which correctly calculates contours from a DEM file or any height-map given to it. The correctness of the contour holding the most importance, since a person viewing the contours shouldn't end up taking wrong planning decisions and maybe losing their life by the route they choose after looking at the map.

I have already tried using GDAL 1.7 source code, compiled it and added some features of my own to it for some other objective. Now I want to add-to/modify the source to be able to use the contour generation function of GDAL in C++.

But before proceeding, I wanted to know:
1. If GDAL offers the best free contour generation algorithm available or is there any other library which I can link to my code and feed my DEM map to it and receive contour vector lines (or go thru research papers and implement the contour generation algorithm myself in C++)? If GDAL, then why is it the best?
2. A generated contour will basically be points connected with straight lines. Is it more correct for a contour to be depicted with connected straight lines or will it give a more correct result to use a spline to smoothen out the lines?

I won't be interpolating any contours or the DEM because I've read on this website that interpolation leads to incorrect results.

-
I can not say to much about algorithms for contour generation but in your case I would search for best quality elevation data out there, rather tahn algoritm itself. Algorithm may be only as good as the data you feed in to it. – Tomek Feb 13 '13 at 9:46
I agree. Good advice. But assuming the data constant, which would be the best algorithm/library, is what I'm asking? – Nav Feb 13 '13 at 10:39
The accuracy of contours depends on the nature of the underlying data: there is no universal contouring algorithm that is optimally accurate. You misunderstand the cautions about interpolation: all methods to predict unsampled data must be inaccurate. The question to consider is how inaccurate they might be and the ways in which they can be expected to err. Incidentally, when you draw contours from a DEM you are interpolating, whether or not you choose to call it that. – whuber Feb 13 '13 at 15:45
Thanks. I've been trying to find out which algorithm GDAL uses for creating contours, but couldn't find any hint on that. Anyone here know? Basically my main requirement is that I should be able to use GDAL (or any other contour generation algo) to create reliable contours which are the best in terms of accuracy (when compared with any application that displays contours). I don't want to start using GDAL and then much later realize that it doesn't suit my needs of multicore support, accuracy, smoothening or specifying the height interval between major and minor contours. – Nav Feb 14 '13 at 12:01