Learn R Programming

rangeMapper (version 0.2-0)

rangeMap.save: Save, retrieve and export maps.

Description

Apply a chosen SQL or Rfunction at each grid cell, allowing for complex subsetting at both ID (e.g. species) and pixel (e..g assemblage) levels.

Usage

rangeMap.save(CON, tableName, FUN, biotab, biotrait, subset, path , overwrite, ...)

Arguments

CON
An sqlite connection pointing to a valid rangeMapper project.
tableName
Name of the table (quoted) to be added to the sqlite database. The prefix MAP will be appended to tableName prior to saving.
FUN
the function to be applied to each pixel. If FUN is missing then species richness (species count) is computed.
biotab
character string identifying the BIO table to use.
biotrait
character string identifying the ID of the BIO table. see bio.save
subset
A named list. See details
path
Path to the raster file(quoted) to be imported to the existing project. raster package is required at this step.
overwrite
If TRUE then the table is removed
...
When FUN is an Rfunction, ...denotes any extra arguments to be passed to it.

Value

Details

The subset argument accepts a named list. Names refers to BIO, MAP and metadata_rages table names while the strings in the list are character strings containing the SQL WHERE clause. The subset can point to either one table type (e.g. list(MAP_species_richness = "species_richness > 500") ) or can point to several table types (e.g. list(BIO_lifeHistory = "clutch_size > 4", MAP_meanAltitude = "meanAltitude < 1000", metadata_ranges = "Area < 1000") ) Any valid SQL expression can be used to build up a subset. See http://www.sqlite.org/lang_expr.html

References

Valcu, M., Dale, J. and Kempenaers, B. (2012) rangeMapper: A platform for the study of macroecology of life history traits. 21(9). (DOI: 10.1111/j.1466-8238.2011.00739.x)

See Also

link{[RSQLite.extfuns-package] {RSQLite.extfuns}} for a list of additional SQL aggregate functions. metadataUpdate.

Examples

Run this code
require(rangeMapper)
dbcon = rangeMap.start(file = "test.sqlite", overwrite = TRUE, dir = tempdir() )

# Breeding range vector files location
f = system.file(package = "rangeMapper", "extdata", "wrens", "vector_combined")

# Save the global bounding box, 
global.bbox.save(con = dbcon, bbox = f, 
	p4s = CRS("+proj=cea +lon_0=0 +lat_ts=30 +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs") ) 

# upload grid size using the proposed default
gridSize.save(dbcon, gridSize = 100000)  # cell size ~ 100km

#  save canvas 
canvas.save(dbcon) 
summary(canvas.fetch(dbcon) )

# Upload BIO tables
data(wrens)
bio.save(con = dbcon, loc = wrens,  ID = "sci_name")

# Process species ranges
r = readOGR(f, "wrens", verbose = FALSE)

processRanges(spdf = r, con =  dbcon, ID = "sci_name" )


#Using sqlite aggregate functions
rangeMap.save(dbcon, FUN = "median" , biotab = "wrens", 
			biotrait = "body_size", tableName = "body_size")

# Fetch maps

summary(rangeMap.fetch(dbcon) )

# more examples at: http://rangemapper.r-forge.r-project.org

Run the code above in your browser using DataLab