[R-sig-Geo] extract point values from contour lines

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Wed Sep 4 12:12:09 CEST 2013


On Wed, Sep 4, 2013 at 10:09 AM, pierluigi de rosa
<pierluigi.derosa at gmail.com> wrote:
> Hi all
> nobody have an Idea about my question?
> thanks again

 If you can lower the bar to helping people answer your question, you
will get more answers!

For example, giving some test data and code to generate it, and some
idea of what you expect to get out. We don't care too much about your
specifics (ie the 1:10000 and 1:25000 contours).

 What format is your contour data? Is it the output from the
'contourLines' function? Or is it a SpatialLinesDataFrame with a
height attribute? Or something else?

A good question would be something like:

"""
I have contour data in the same form as from contourLines, for example:

    x <- 10*1:nrow(volcano)
     y <- 10*1:ncol(volcano)
     image(x,y,volcano)
     lines = contourLines(x, y, volcano)

and I want to be able to get the height at any point in the area from
the contour line data (yes, I could just sample the underlying grid
but I don't have that data, I only have the contours).

"""

One approach might be to consider the points of the contour line as
samples from the underlying data and do a smoothing such as kriging or
inverse distance weighting, but I suspect that having a lot of samples
with the same height at a range of distances is going to mess up the
variogram somewhat...

If all your contour lines are complete rings then you can do
point-in-polygon tests to see which rings the point is inside and
hence know its height is between that and the next ring, and then
maybe interpolate linearly by distance to ring, but there's some edge
cases when a point is inside a summit ring when you only know it is
bigger than X and less than X+10 (if 10 is your contour interval).

Searching for 'interpolation from contour lines' might be useful.

Barry



More information about the R-sig-Geo mailing list