Sampling Background Points for SDMs
While taking Dr. Rob Anderson's excellent Zoogeography course through CUNY's Graduate Center, I created distribution models for the Common Myna. The Myna has a widespread distribution, and my goal was to sample background points from accessible environments in order to create a model in MaxEnt. With guidance from the Dr. Anderson's lab members, I developed a way to sample background points from user-defined buffers around each locality. This method aims to avoid overestimating a species' dispersal abilities that plague some background sampling methods for widespread species such as sampling from a minimum convex polygon. Here is a PDF of the steps I outline here:
1. To start, you should have a data.frame that includes all localities for your focal species. Then, convert that data.frame of occurrences to a spatial points data.frame:
# convert list of occurrences to a spatial points data.frame occurrences_spdf <- SpatialPointsDataFrame(coords = occurrences.data.frame, data = occurrences.data.frame, proj4string = CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")) #check to ensure points and projection are correct plot(occurrences_spdf)
2. Open QGIS, a free open-source GIS software. In my experience, when using large occurrence datasets, the R function that would perform the following operations in R (gBuffer) is slow. The same process in QGIS takes seconds.
3. Import a single environmental raster and your spatial points data.frame of occurrences in QGIS.
4. Open the buffer dialogue box (VECTOR >> GEOPROCESSING TOOLS >> BUFFER(S). The settings pictured here will make 5 degree buffers around each point in your spatial points data.frame. Click "dissolve buffer results" to convert buffers into one continuous layer.
5. With all layers combined, you should have your climate rater, layer of occurrences, and your vector of buffers around each point.
4. Now, you can either crop your one environmental layer here, or do the rest of the cropping in R. I cropped one raster in QGIS to make sure everything went as planned, though this process in R would be quick. To crop in QGIS:
a. Open clipper dialogue box.
b. Set your climate raster as input, browse to where you would like output shape file, and then select clipping mode as mask and pick your newly created buffer layer
# Then, you can read the buffered vector into R, and crop all environmental layers to this new layer. buffered_region <- readGDAL("data/buffer_layer.tif")