Basics.Rmd
The following analysis requires several packages to be loaded:
library(tidyverse)
library(raster)
library(polyCheck)
library(rgeos)
Within the package, there are a few datasets which are included to represent the dataset which is being validated. These do not represent actual areas surveyed, but were randomly selected for the purpose of explaining and validating the model. The three datasets are as follows:
# Load filepath from repository
dataPath <- system.file("extdata", package = "polyCheck")
# Settlement types
settlements <- shapefile(file.path(dataPath, "settlement_points.shp"))
# Survey Points
survey_points <- shapefile(file.path(dataPath, "survey_points_sample.shp"))
# We must mimic how the FID is generated
survey_points$FID <- 0:(nrow(survey_points)-1)
# load the ORNL data
ornl <- shapefile(file.path(dataPath, "ornl.shp"))
A selection of polygons are provided within the extdata/polygons
subdirectory of the package. These are the objects which we are wishing to validate within the model. Note, these do not represent survey areas and have been designed to highlight the functionality of the package. We can use the function list_polygons
to list the file paths for polygons. This will by default search within subdirectories in the directory specified, but we can override this by specifying recursive = FALSE
.
polygons <- list_polygons(dataPath, "polygons")
basename(polygons)
#> [1] "000_js_polygon.shp" "001_js_polygon.shp" "002_mh_polygon.shp"
#> [4] "003_mh_polygon.shp" "004_dc_polygon.shp" "005_dc_polygon.shp"
#> [7] "006_ss_polygon.shp" "007_ss_polygon.shp"
To check whether any of the delineated polygons conflict, we can merge the polygons into a single shapefile using the merge_delineated_polygons
function:
polygons_all <- merge_delineated_polygons(polygons)
#> Loading Polygons
#> Merging Polygons
#> Complete
polygons_all
#> class : SpatialPolygonsDataFrame
#> features : 8
#> extent : 7.670478, 7.745, 11.07066, 11.13065 (xmin, xmax, ymin, ymax)
#> coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
#> variables : 1
#> names : ID
#> min values : 0
#> max values : 7
To diagnose polygons, we can use the assess_polygons
function as shown below:
diagnostics <-
assess_polygons(polygons[1],
survey_points,
settlement_points,
ornl,
polygons_all,
progress = FALSE)
The full set of parameters is displayed below:
Parameter | Value |
---|---|
filename | 000_js_polygon.shp |
num_features | 1 |
Id | 1 |
Pt_ids | 0 |
image_ID | NA |
dig_date | 10-OCT-2018 |
SRC_DATE2 | 31-DEC-2015 |
digitiser | js |
id | 0 |
crs_match | TRUE |
no_points | 542 |
dist_from_survey | 2135 |
prop_settlement_type | 0 |
ornl_overlap | FALSE |
self_intersect_id | No Intersection |
self_intersect_prop | NA |
no_sides | 7 |
shp_area | 31568 |
shp_area_hect | 3.16 |
Polsby_popper | 0.72 |
perimeter | 743 |
The function is designed to work with either a single polygon or a list of polygons. If provided multiple values, the function will return a data.table If we provide it the full set above:
diagnostics <-
assess_polygons(polygons,
survey_points,
settlement_points,
ornl,
polygons_all)
The results are presented below: