adjacent_ibra: Subset IBRA 7 by points

Description Usage Arguments Value See Also Examples

Description

Subset IBRA 7 to those polygons that contain, or are adjacent to polygons that contain, one or more given points.

Usage

1
2
adjacent_ibra(pts, min_n = 1, include_type = "polygon",
  expand_type = include_type, plot_output = FALSE)

Arguments

pts

A SpatialPoints* object.

min_n

The minimum number of points a subregion must contain in order for it to be included in the returned subset.

include_type

Character. Either 'polygon', 'region' or 'subregion'. This determines the level of aggregation at which occupied IBRA polygons will be considered. For 'polygon', adjacency will be calculated with respect to the polygons that actually contain min_n or more points, whereas for 'subregion' (and 'region'), adjacency will be calculated with respect to all polygons belonging to the IBRA subregions (or regions) that have polygons containing at least min_n points. Default is 'polygon'.

expand_type

Character. Either 'polygon', 'region' or 'subregion'. This determines the level of aggregation at which neighbouring IBRA polygons will be aggregated prior to calculating adjacency. For 'polygon', only the polygons adjacent to those polygons with min_n or more points will be considered neighbours, whereas for whereas for 'subregion' (and 'region'), neighbours will comprise all polygons belonging to the IBRA subregions (or regions) that have polygons adjacent to polygons containing at least min_n points. Default behaviour is for expand_type to be the same as include_type.

plot_output

Logical. Should the resulting polygon subset be plotted? If TRUE, the polygons and points will be plotted. Points that don't overlie an IBRA 7 subregion will be plotted in red.

Value

A SpatialPolygonsDataFrame representing the subset of regions (or subregions, see type) of ibra7_albers within which min_n or more points (pts) fall, and those regions (or subregions) adjacent to these.

See Also

ibra_region

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
library(sp)
xy <- SpatialPoints(data.frame(x=runif(1000, 140, 145), y=runif(1000, -38, -35)))
proj4string(xy) <- '+init=epsg:4283'

#' # Polygons with at least 1 point
adj <- adjacent_ibra(xy, include_type='polygon')
plot(adj, col='gray80', border='transparent')

# Polygons with at least 20 points
adj2 <- adjacent_ibra(xy, include_type='polygon', min_n=20)
plot(adj2, col='gray60', border='transparent', add=TRUE)

# Sub-regions with at least 1 point
adj3 <- adjacent_ibra(xy, include_type='subregion')
plot(adj3, col='gray80', border='transparent')

# Sub-regions with at least 20 points
adj4 <- adjacent_ibra(xy, include_type='subregion', min_n=20)
plot(adj4, col='gray60', border='transparent', add=TRUE)

# Regions with at least 1 point
adj5 <- adjacent_ibra(xy, include_type='region')
plot(adj5, col='gray80', border='transparent')

# Regions with at least 20 points
adj6 <- adjacent_ibra(xy, min_n=20, include_type='region')
plot(adj6, col='gray60', border='transparent', add=TRUE)

# With plot_output=TRUE
adj7 <- adjacent_ibra(xy, plot_output=TRUE)

# Compare include_type and expand_type
apply(expand.grid(c('polygon', 'subregion', 'region'), 
                  c('polygon', 'subregion', 'region')), 1, 
      function(x) {
        adjacent_ibra(xy, include_type=x[1], expand_type=x[2], plot=TRUE)
        title(main=sprintf('include type: %s; expand type: %s', x[1], x[2]))
      })

johnbaums/things documentation built on May 19, 2019, 3:03 p.m.