mapexample.R

darren — Apr 22, 2013, 9:49 PM

##### Produces a map of one of our study areas in Amapa, Brazil
##### simple example of R code and packages for making maps
# Plots a geotiff raster of the altitude 
# (SRTM - http://www.cgiar-csi.org/data/srtm-90m-digital-elevation-database-v4-1)
# and adds locations of samples from the PPBio plot 
# (http://ppbio.museu-goeldi.br/?q=pt-br/flona-do-amap%C3%A1)
# points and lines are shapefiles  
# shapefiles made from data collected by members of LECoV 
# (http://amazonian-vertebrates.wikispaces.com/LECoV+Personnel)
# All coordinates WGS84 (decimal degrees, lat lon), epsg = 4326
# Raster and shapefile data available from: 
# https://docs.google.com/file/d/0B2vCYMFb01F6SnFIakxHSzBfMms/edit?usp=sharing

#### Step 1 Import FLONA raster geotiff SRTM 90m GDEM 
myrv<-file.choose()#select "srtm_flona.tif"
library(raster) 
Loading required package: sp
raster 2.1-0 (28-December-2012)
rv<-raster(myrv)
rgdal: version: 0.8-5, (SVN revision 449) Geospatial Data Abstraction
Library extensions to R successfully loaded Loaded GDAL runtime: GDAL
1.9.2, released 2012/10/08 Path to GDAL shared files:
C:/Users/darren/R/R-2.15.3/myRlib/rgdal/gdal GDAL does not use iconv for
recoding strings. Loaded PROJ.4 runtime: Rel. 4.7.1, 23 September 2009,
[PJ_VERSION: 470] Path to PROJ.4 shared files:
C:/Users/darren/R/R-2.15.3/myRlib/rgdal/proj
names(rv) <- c('ALT.DEM')
### look at what is in the raster
rv # resolution, extent etc
class       : RasterLayer 
dimensions  : 78, 77, 6006  (nrow, ncol, ncell)
resolution  : 0.0008333, 0.0008333  (x, y)
extent      : -51.67, -51.6, 0.9562, 1.021  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source : C:\Users\darren\Documents\EcologyAndConservation2011\ms Ducke2013\DataSets\GIS_FLONAAmapa\raster\srtm_flona.tif 
names       : ALT.DEM 
values      : 68.81, 177.1  (min, max)
summary(rv) # summary of altitude values
        ALT.DEM
Min.      68.81
1st Qu.  105.28
Median   114.19
3rd Qu.  124.27
Max.     177.14
NA's       0.00
plot(rv) # to have a look at the imported raster

plot of chunk unnamed-chunk-1


##### STEP 2 Import points corresponding to the plot and sample locations
### ppbio samples, 30 locations "FLONAPPBiopoints.shp"
vpoint<-file.choose()
vppbio<-shapefile(vpoint)

### river points , locations of where rivers intersect trails
### "FLONARiverPoints.shp"
vriv<-file.choose() 
vpriv<-shapefile(vriv)

### plot points along trails at 100m interval: "ppbiogridpointsflona.shp"
myvgp<-file.choose() #grid
vpg<-shapefile(myvgp) 

# surrounding polygon, line around the sample plot: "PPbioGridPolyFlona.shp"
myvp<-file.choose()
vppoly<-shapefile(myvp) 

#STEP 3 Plot all 
windows(width=6,height=6)  # use quartz() on mac not "windows"
plot(rv,main="PPBio FLONA")
points(coordinates(vpg),pch=3,cex=0.15)
plot(vppoly,add=TRUE)
points(coordinates(vpriv),pch=22,col="grey",bg="blue",cex=1.4)
points(coordinates(vppbio),pch=24,col="grey",bg="black",cex=1.2)

plot of chunk unnamed-chunk-1