Description Usage Arguments Details Value Note See Also Examples
View source: R/MapSave-methods.R
Apply a chosen SQL
or function at each grid cell, allowing for
complex subsetting at both ID (e.g. species) and pixel (e.g. assemblage)
levels.
1 2 | rangeMap.save(CON, tableName, FUN, biotab, biotrait, subset = list(),
path, overwrite = FALSE, ...)
|
CON |
an sqlite connection pointing to a valid |
tableName |
name of the table (quoted) to be added to the sqlite database.
the prefix ‘MAP’ will be appended to |
FUN |
the function to be applied to each pixel. If |
biotab |
character string identifying the ‘BIO’ table to use. |
biotrait |
character string identifying the ID of the ‘BIO’
table. see |
subset |
a named |
path |
path to the raster file(quoted) to be imported to the existing
project. |
overwrite |
if |
... |
when |
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
When using cl
parameter you must load the given packages used in
FUN
by loading the packages inside the function, using '::' or initializing the
cluster before calling rangeMap.save (e.g. clusterEvalQ(cl=cl, library(caper))
)).
TRUE
when the MAP was created successfully.
SQL
aggregate functions are more efficient then their R
counterparts. For simple aggregate functions like mean, median, sd, count
it is advisable to use SQL
functions rather then R functions.
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 34 35 36 37 38 | require(rangeMapper)
require(rgdal)
breding_ranges = readOGR(system.file(package = "rangeMapper",
"extdata", "wrens", "vector_combined"), "wrens", verbose = FALSE)[1:50, ]
breding_ranges = spTransform(breding_ranges,
CRS("+proj=cea +lon_0=0 +lat_ts=30 +x_0=0 +y_0=0
+ellps=WGS84 +units=m +no_defs") )
data(wrens)
d = subset(wrens, select = c('sci_name', 'body_size', 'body_mass', 'clutch_size') )
con = ramp("wrens.sqlite", gridSize = 500000, spdf = breding_ranges, biotab = d,
ID = "sci_name", metadata = rangeTraits(),
FUN = "median", overwrite = TRUE)
lmSlope = function(formula, data) {
fm = try(lm(formula, data = data), silent = TRUE)
if (inherits(fm, "try-error"))
res = NA else res = coef(fm)[2]
as.numeric(res)
}
# Subsetting by Species and Assembladge
rangeMap.save(con, FUN = lmSlope, biotab = "biotab", biotrait = "body_mass",
tableName = "slope_bodyMass_clutchSize", formula = log(body_mass) ~ clutch_size,
list(MAP_species_richness = "species_richness >= 5",
BIO_biotab = "body_size > 15"
), overwrite = TRUE)
## Not run:
# Import raster maps to the current project
r = system.file(package = "rangeMapper", "extdata", "etopo1", "etopo1_Americas.tif")
rangeMap.save(con, path = r, tableName = "meanAltitude", FUN = mean, overwrite = TRUE)
m = rangeMap.fetch(con, spatial = FALSE)
plot(m)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.