Last active
August 29, 2015 14:26
-
-
Save pepijn-devries/6bd7276fe7d41b155a2b to your computer and use it in GitHub Desktop.
ContourLines to SpatialPolygons
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#create a slightly larger matrix and fill with relatively small values (60): | |
volcano2 <- matrix(60, nrow(volcano) + 2, ncol(volcano) + 2) | |
#copy the original matrix into the center of the new matrix: | |
volcano2[-nrow(volcano2),][,-ncol(volcano2)][-1,][,-1] <- volcano | |
#repeat the previous conversion steps and plot: | |
poly_volcano <- raster(volcano2) | |
poly_volcano <- rasterToContour(poly_volcano, levels = breaks) | |
poly_volcano <- SpatialLines2PolySet(poly_volcano) | |
poly_volcano <- PolySet2SpatialPolygons(poly_volcano) | |
png("volcano02.png", 200, 200) | |
par(oma = c(0,0,0,0), mar = c(0,0,0,0)) | |
plot(poly_volcano, col = terrain.colors(length(poly_volcano))) | |
dev.off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment