Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to approximate a vector contour from an elevation raster?

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.

like image 433
erickson Avatar asked Feb 10 '09 18:02

erickson


3 Answers

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.

like image 189
Jay Kominek Avatar answered Oct 27 '22 08:10

Jay Kominek


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.

like image 2
Jason S Avatar answered Oct 27 '22 08:10

Jason S


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:

enter image description here

like image 1
Graham Asher Avatar answered Oct 27 '22 08:10

Graham Asher