[R] extract coordinates from contour lines

(Ted Harding) Ted.Harding at manchester.ac.uk
Sat Nov 28 23:15:12 CET 2009


On 28-Nov-09 21:40:00, Julius Tesoro wrote:
> To everyone,
> Is there a way to extract coordinates or an equation from a
> "straight" contour line? 
> 
> Thanks.
> Cheers
> Julius Tesoro

It's not obvious what you mean by a "straight" contour line!
Do you mean one which is/looks like a straight line?
If so, then if you know where to look for the first and last
points then you are almost there (and the rest is obvious).

However, if you mean a contour "line" (which might mean curve),
then where to look may depend on how it was generated.

If it's simply one which appears on (say) a map, then the
interactive graphics function grid.locator() (in the 'grid'
package) will allow you to ascertain the coordinates of
points on the curve by clicking with the mouse on selected
points. This of course will be approximate, depending on the
resolution of your clicking capabilities.

If it has been generated by appying a contouring function
to a function evaluated at a grid of points, then you may get
what you want if you can reproduce the contouring using the
function contourLines().

The value returned by this is a list of contours. Each contour
consists in turn of a list whose components are:

  level : The contour level.
      x : The x-coordinates of the contour.
      y : The y-coordinates of the contour.

The same contour-level may be represented by different contour
components in the returned value, since it is common in contour
plots to have a contour-level plotted in disjoint parts.

So, for each level, you will have to hunt through the contour
components for all occurrences of that level, and for each
occurrence extract the $x and $y components of that occurrence.

These are generalities. A more specific reply would need more
specific information about what you are really looking for!

Hoping this helps,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 28-Nov-09                                       Time: 22:15:09
------------------------------ XFMail ------------------------------




More information about the R-help mailing list