Skip to content
Prev 5814 / 29559 Next

contour data

Thank you!  You should remove the term "roughly" as it worked exactly as 
is.  All I needed to do is change the input file name.   The below ran 
perfectly, displaying the DEM and contours on a plot (bottom five lines) 
with output shapefiles of the vectors (the writeOGR command.)

library(rgdal)
dem <- readGDAL("C:\\data\\State2m\\dem1717.asc")
im <- as.image.SpatialGridDataFrame(dem)
cl <- contourLines(im,20)
library(maptools)
SLDF <- ContourLines2SLDF(cl)
writeOGR(SLDF, ".", "dem1717", driver="ESRI Shapefile")
mc <- readOGR(".", "dem1717")
summary(dem)
summary(mc)
image(dem, col=gray.colors(20))
plot(mc, col=terrain.colors(8), add=TRUE)


I used gdal_translate to easily extract my area of interest as an ASCII 
grid file and then ran your script.  Perfect.  I'm now looking at the 
parameters of contour/contourLines to create different levels of 
contours (like 2 foot or 5 meter.)   Thanks again!

- John
Roger Bivand wrote: