Skip to content

contours of a SpatialPixelsDataFrame?

2 messages · Horacio Samaniego, Roger Bivand

#
On Wed, 27 Sep 2006, Horacio Samaniego wrote:

            
No, because it creates the input list of x, y, z used by image() and 
contour - the z component is the matrix.
It's not hard (from the example for image.SpatialGridDataFrame):

data(meuse.grid)
coordinates(meuse.grid) = c("x", "y")
gridded(meuse.grid) = TRUE
class(meuse.grid) # is a "SpatialPixelsDataFrame"
xyz <- as.image.SpatialGridDataFrame(meuse.grid["dist"]) # choose the 
                                          # variable you need
image(meuse.grid["dist"], axes=TRUE)
contour(xyz, add=TRUE)

(if you just do contour() on the matrix, the coordinates and aspect get 
blown away) and if you want the contours as a SpatialLinesDataFrame:

SLDF <- contourLines2SLDF(contourLines(xyz))
image(meuse.grid["dist"], axes=TRUE)
plot(SLDF, add=TRUE)

Roger