apply_pts_by_poly: Apply functions over points by polygons

Description Usage Arguments Author(s) Examples

View source: R/apply_pts_by_poly.R

Description

This function is a wrapper aroud the 'sptools::points_in_polygon' and applies a function 'f' to the variable 'var' of the 'spatialPointsDataFrame' 'points' object, by the polygons of 'spatialPolygonsDataFrame' 'polygons' object.

Usage

1
apply_pts_by_poly(points, polygons, var, f, ...)

Arguments

points

a 'SpatialPointsDataFrame' object.

polygons

a 'SpatialPolygonsDataFrame' object.

var

the name of the variable of 'points' on which to apply the function 'f'.

f

the function to be applied.

...

arguments to passed in 'sptools::points_in_polygon'

Author(s)

Marc Choisy

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
library(sf)

# SpatialPolygonsDataFrame
vn <- sf::as_Spatial(gadmVN::gadm(level = "province"))
# SpatialPoints
stations <- as(imhen::stations, "Spatial")
names(stations)

# to calculate the mean elevation of the station for each polygon
apply_pts_by_poly(stations, vn, "elevation", mean)

choisy/sptools documentation built on Aug. 22, 2019, 12:57 p.m.