metadata.update: Updates metadata table

Description Usage Arguments Value Note Examples

View source: R/metadataUpdate-methods.R

Description

Updates metadata_table of a rangeMapper project after importing ranges with processRanges.

Usage

1
metadata.update(rangeMap, FUN, name, map, overwrite = FALSE, ...)

Arguments

rangeMap

A rangeMap object.

FUN

Function used to aggregate the map values corresponding to each range

name

The name of the new metadata_table field containing the variable computed by FUN

map

Single-band SpatialGridDataFrame object

overwrite

If set to TRUE the the values of the field are replaced

...

extra arguments (e.g. na.rm = TRUE) to be passed to FUN.

Value

NULL.

Note

In order to compute taxa-level metadata which are not dependent on the project's resolution use processRanges with a metadata argument. See rangeTraits for more details.
The method can be extended to work with raster or vector objects (e.g. lines, polygons, points) using overlaying functions in the package raster and rgeos respectively.

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
require(rangeMapper)
require(rgdal)
# data
spdf = readOGR(system.file(package = "rangeMapper",
	"extdata", "wrens", "vector_combined"), "wrens", verbose = FALSE)
rloc = system.file(package = "rangeMapper", "extdata",
	"etopo1", "etopo1_Americas.tif")
r = readGDAL(rloc, output.dim = c(50, 50))
spdf = spTransform(spdf, CRS(proj4string(r)) )

# the project
dbcon = rangeMap.start(file = "wrens.sqlite", overwrite = TRUE,
	dir = tempdir() )
rmap = new("rangeMap", CON = dbcon)
global.bbox.save(con = dbcon, bbox = spdf )
gridSize.save(dbcon, gridSize = 300000)
canvas.save(dbcon)
processRanges(spdf = spdf, con =  dbcon, ID = "sci_name" )

# metadata.update
metadata.update (rmap,
 FUN = function(x, ...) {
 	res = diff(range(x, ...))
 	if( !is.finite(res)) res = 0
 	res
 	},
	name = 'AltitudeRange', map = r, na.rm = TRUE, overwrite = TRUE)
# plot
mr = dbGetQuery(dbcon, 'select * from metadata_ranges')
maxRangeSp = mr[mr$AltitudeRange== max(mr$AltitudeRange), 'bioid']
image(r)
plot(rangeFetch(rmap, maxRangeSp), add = TRUE, border = 4, lwd = 3)
title(main = maxRangeSp)

valcu/rangeMapper documentation built on Feb. 6, 2021, 8:20 p.m.