Spatial 1 Exercise 1 Answers ## Exercise 1 ## 1.1 Get the min and max coordinates of the boundary of ptshp. bbox <- ptshp@bbox bbox[1,] ## 1.2 Display points where elevation (ELEVM) are >= 3000 in dark green. plot(ptshp[ptshp$ELEVM >= 3000,], col= "dark green") ## 1.3 Add points where elevation (ELEVM) are < 3000 in yellow. plot(ptshp[ptshp$ELEVM < 3000,], col="yellow", add=TRUE) ## 1.4 Overlay the point with the maximum elevation (ELEVM) in red. plot(ptshp[ptshp$ELEVM == max(ptshp$ELEVM),], col="red", add=TRUE) 2 Exercise 2 Answers ## Exercise 2 ## 2.1 Get projection of nfspoly. projection(nfspoly) ## 2.2 Display the area or interest boundary (bndpoly) with no color plot(bndpoly, border="black", lwd=2) ## 2.3 Add the wilderness boundary (wildpoly) in green with no outline. plot(wildpoly, add=TRUE, col="green", border="green") ## 2.4 Get total sum of area of nfspoly. sum(sapply(slotsPolygons, function(x)slot(x, "area"))) 3 Exercise 3 Answers ## Exercise 3 ## 3.1 Get the minimum value of elev minValue(elev) ## 3.2 Display elev raster with heat colors and 10 classes plot(elev, col=heat.colors(n=10)) ## 3.3 Generate slope (in degrees) slp <- terrain(elev, opt=c('slope'), unit='degrees') ## 3.4 Classify the slope raster from 3.3 into 4 classes slpcl <- cut(slp, breaks=4) plot(slpcl) ## 3.5 Display the classified slope raster with unique colors. Use colors() to select color choices. Exclude axes labels. cols <- c("whitesmoke", "skyblue", "slateblue", "dark blue") plot(slpcl, col=cols, breaks=c(0:4)) 4 Temporary Files Functions in raster package create temporary files if the values of an output RasterLayer cannot be stored in memory (RAM). This can happen when no filename is provided to a function an in functions where you cannot provide a filename. Temporary files are automatically removed at the start of each session. During session: showTmpFiles() removeTmpFiles() C:\Program Files\R\R-3.0.0\etc\Rprofile.site # Added options(scipen=6) options(rasterTmpDir='c:/Temp/') rasterOptions() rasterOptions(chunksize = 1e+04, maxmemory = 1e+06) 5