R Code: Mapped and Attributed Data Random Area and Point (MADRAP) Generator
Citation
Harrison, T.J., Sattler, S.R., Strassman, A.C. 2020. Mapped and Attributed Data Random Area and Point (MADRAP) Generator. U.S. Geological Survey code release. https://doi.org/10.5066/P9WMRQVY
Summary
## Description Generate random points and sample areas from polygons in a shapefile with sampling constraints for each map class. Can be used to generate sample areas for accuracy assessment in cartography. ## Pre-requisites Software [R](https://cran.r-project.org/bin/windows/base/old/3.5.3/), [RStudio](https://rstudio.com), and [Rtools](https://cran.r-project.org/bin/windows/Rtools/). ## Installation Install MADRAP as a package using Rtools. Download the repository and unzip `madrap-master.zip`. Open RStudio and... Click File > Open Project > madrap-master/madrap/MADRAP.Rproj > Open Click the build tab in the top right then click "Install and Restart". You may run into installation issues if you do not have permission to modify [...]
Summary
## Description
Generate random points and sample areas from polygons in a shapefile with sampling constraints for each map class. Can be used to generate sample areas for accuracy assessment in cartography.
## Pre-requisites
Software [R](https://cran.r-project.org/bin/windows/base/old/3.5.3/), [RStudio](https://rstudio.com), and [Rtools](https://cran.r-project.org/bin/windows/Rtools/).
## Installation
Install MADRAP as a package using Rtools. Download the repository and unzip `madrap-master.zip`. Open RStudio and...
Click File > Open Project > madrap-master/madrap/MADRAP.Rproj > Open
Click the build tab in the top right then click "Install and Restart".
You may run into installation issues if you do not have permission to modify the R packages directory. You can find your package directory by running
```
.libPaths()
```
An error that may occur if you do not have permission to modify your packages is
```
ERROR: dependencies ... are not available for package 'MADRAP'
```
First try installing the dependencies yourself in case the installation tools failed. If the package installations fail then you likely need to installing the dependencies at a folder where you do have modification accesss. You can set your package installation location using the `libPaths` function.
## Documentation
The documentation is found in the folder `MADRAP/man`. Each document is in `Rd` format so it can be read by tools like RStudio.
## How it works
The MADRAP `getGISSamples` function starts by creating buffers of the polygons found in `shapes_dir_or_obj`. The buffers are specified in the `backup_buffers_list` for each desired buffer distance (distance from the edge of the polygon) specified in the constraints table. `getGISSamples` randomly selects a polygon by the `object_selector_name` field (defaultly named Map_Class). Then a random point is chosen within that polygon. The function then tries to build a point buffer (sample area) around the sample point. If the desired area around the point is found, within the `sample_area_granularity_threshold`, then the sample point and sample area are recorded. Each sample area taken is removed from the buffered polygons to prevent duplicating samples. View the documentation to get more details on the other parameters available for configuring the sampling.
## Load the needed libraries (if installed as a package)
```
library(MADRAP)
```
### Here is an example of a constraints table
Map Class | Buffer Distance | Sample Area | Points per Map Class
--- | --- | --- | ---
FBMG | a | 500 | 1
FSBL | b | 500| 1
CBRN | a | 500 | 1
FSMH | a | 500 | 1
FFCS | b | 500 | 1
**Map Class:** sampling field ID in shapefile.
**Buffer Distance:** the buffer class used to generate the buffer list for sampling from the given map class.
**Sample Area:** the sample area desired.
**Points per Map Class:** The number of points to sample for the given map class.
## Load the sample data
```
data("Shapes")
data("Constraints")
```
## Get the sample polygons from the `shapes` shapefile