extract_spatial: define an area on a spatial plot and extract selected polygon...

View source: R/extract_spatial.R

extract_spatialR Documentation

define an area on a spatial plot and extract selected polygon or point features

Description

This function utilizes 'sp::over' to select features that overlay on an input polygon. As no method is defined for SpatialLines, only Polygons and Points may be selected.

Usage

extract_spatial(in_spatial, over_poly = NULL, plot_result = FALSE)

Arguments

in_spatial

The sp object from which to extract features

over_poly

A polygon that specifies the features to extract. used in non-interactive mode. NOT YET IMPLEMENTED

plot_result

Boolean to plot the resulting features and selection poly.

Examples

## Not run: 
 x <- c(0.5, 0.5, 1.2, 1.5)
 y <- c(1.5, 0.5, 0.5, 0.5)
 xy <- cbind(x,y)
 dimnames(xy)[[1]] <- c('a', 'b', 'c', 'd')
 pts <- SpatialPoints(xy)
 xpol <- c(0,1,1,0,0)
 ypol <- c(0,0,1,1,0)
 pol <- SpatialPolygons(list(
 Polygons(list(Polygon(cbind(xpol-1.05,ypol))), ID='x1'),
 Polygons(list(Polygon(cbind(xpol,ypol))), ID='x2'),
 Polygons(list(Polygon(cbind(xpol,ypol-1.05))), ID='x3'),
 Polygons(list(Polygon(cbind(xpol+1.05,ypol))), ID='x4'),
 Polygons(list(Polygon(cbind(xpol+.4, ypol+.1))), ID='x5')
 ))
 extract_spatial(pts,T)
 extract_spatial(pol,T)
 
## End(Not run)

jhollist/miscPackage documentation built on March 3, 2024, 9:23 p.m.