id_pts: Identify points coordinates inside each cell of a grid.

Description Usage Arguments Details Value Author(s) References Examples

View source: R/id_pts.R

Description

This function takes a SpatialPointsDataFrame object and compares each point with the boundaries of each cell in a grid (SpatialPolygonsDataFrame from the grd_build function.

Usage

1
id_pts(grd, pts, contain = c("simple", "properly"))

Arguments

grd

A SpatialPolygonsDataFrame object from the grd_build function.

pts

A SpatialPointsDataFrame object.

contain

Character (simple or properly). By default simple, it implies a simple contention evaluation (see gContains)). properly suggests a properly contention evaluation (see gContainsProperly)).

Details

id_pts() extract the number of observations per cell for each factor. It uses parallel programing to reduce the computation time. This function depends on parallel, doParallel and foreach packages. By defaul the number of cores for parallel computing is two, but it is posible to extend the number of cores by modify the body of the funtion at line cores <- 2

Value

An object of class SpatialPolygonsDataFrame. The data slot contains a data.frame with a column "id" and m columns. The m columns represent the sample intensity in each cell of the grid for each factor.

Author(s)

Enrique Del Callejo Canal (edelcallejoc@gmail.com), based on implemented algortihms in web platform SPECIES (see References).

References

http://species.conabio.gob.mx/

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
library(sp)
library(rgeos)
library(rgdal)
library(raster)

# Loading data
data(Mex0)
data(mammals)

# Generating de grid from Mex0 data
Mex0.grd<-grd_build(Mex0)

# Identification points of mammals
system.time(x.mat<-id_pts(grd = Mex0.grd, pts = mammals))

# Loading extra libraries for ggplot2
library(plyr)
library(ggplot2)
library(mapproj)

Mex0.grd_for <- fortify(Mex0.grd)
Mex0.grd_df <- plyr::join(Mex0.grd_for,
 data.frame(id = rownames(x.mat@freqmatrix ), x.mat@freqmatrix, stringsAsFactors = FALSE), by="id")

ggplot(data = Mex0.grd_df, aes(x = long, y = lat, group = group, fill = Alouatta_palliata)) +
    geom_polygon(colour = "gray") +
    scale_fill_gradient(low = "white", high = "red") +
    coord_quickmap()

edelcallejoc/rspecies documentation built on May 27, 2019, 7:25 a.m.