I have an elevation map stored as a raster. I'd like to fit a smooth "vector" curve to the contours of constant elevation. In my application, the data are actually geographic elevations, but the problem could be generalized to any function of two variables.
I can produce another raster with anti-aliased contour lines, and use that as input to the vector-fitting process, if that helps.
This question is similar, but I'm looking for a free library that I can use in my Java application, or an explanation of the algorithm I (a non-mathematician) can implement myself. Also, in my case, I've already found all of the "edges" I care about—I just need to vectorize them.
Another question touches on mine, but the poster never returned to explain how he implemented the final step, which is the part I'm missing.
You probably want to fit to closed bezier splines (curves).
There is a page with a Java applet that does such fitting. Take a look at their (uncommented, bleh) PSegment.java
If that doesn't do the job well enough, Fitting B-Spline Curves to Point Clouds by Squared Distance Minimization should be overkill for the task.
For more info, Google (Scholar) searches for things like "b-spline fitting" and "closed bezier spline" should help.
MATLAB does this with a contour plot: see the contour
function -- it produces contour line data from a grid of f(x,y) data. I don't know much about the algorithm they use (they do have a page which discusses it) but maybe worth looking at the Octave equivalent.
there's a thesis on contour plotting and a CodeProject page based on the thesis.
I use GDAL. And in my opinion you probably don't want to create Bézier splines, which adds complexity. Short line segments are good enough.
The only problem is that you'd have to create the contours at data preparation time, not in your Java app.
Here's a map with some contours created from USGS height data using GDAL:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With