extract.data: Spatial Join of Points with Raster Grids

Description Usage Arguments Details Value Author(s) Examples

View source: R/extract.data.R

Description

extract.data extracts data from raster object of class 'asc' (this and the adehabitat package), 'RasterLayer' (raster package) or 'SpatialGridDataFrame' (sp package) at specified locations. This represents a faster version of 'join.asc' of the adehabitat package that assumes all locations are within the map extents.

Note: there is no interpolation done here. The values reported are simply the values of the raster cell the point falls into.

Usage

1
2
## S3 method for class 'data'
extract(pts, x)

Arguments

pts

a two-column data frame or matrix with the x and y coordinates of the locations of interest.

x

a raster matrix of class 'asc' (this and the adehabitat package), 'RasterLayer' (raster package) or 'SpatialGridDataFrame' (sp package)

Details

Implements a faster version of 'join.asc' from the adehabitat package.

NOTE: this assumes all locations are within the extent of the raster map. Values outside the extent will be given a value of NA.

Value

Returns a vector equal in length to the number of locations in pnts.

Author(s)

Jeremy VanDerWal jjvanderwal@gmail.com

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#create a simple object of class 'asc'
tasc = as.asc(matrix(1:50,nr=50,nc=50)); print(tasc)

#define some point locations
points = data.frame(x=runif(25,1,50),y=runif(25,1,50))

#extract the data
points$values = extract.data(points,tasc)

#show the data
print(points)

Example output

Raster map of class "asc":
Cell size:  1 
Number of rows:  50 
Number of columns:  50 
Type:  numeric 
           x         y values
1  17.577270 43.607695     18
2  38.397740 21.570766     38
3  34.901726 31.151893     35
4   7.827464 49.588158      8
5  14.833785  8.135991     15
6  49.381905 44.046691     49
7  30.969354 30.179998     31
8  22.771834  9.519121     23
9  12.093689 25.788792     12
10 43.512760  2.229396     44
11 36.386139 30.834548     36
12 37.302083 48.081069     37
13 49.507061  1.008654     50
14 20.440731 12.825671     20
15 35.064175 11.185134     35
16 40.188876  2.414229     40
17 28.413216 14.868992     28
18  9.300695  2.834519      9
19 26.818326 17.828408     27
20 30.992883 10.095838     31
21 46.421966 21.573599     46
22 26.468006 31.503011     26
23 26.364067 19.496927     26
24 14.926951  1.656080     15
25 29.116219 22.177342     29

SDMTools documentation built on Jan. 11, 2020, 9:23 a.m.