Deal with spatial information.

get_coordinates(object)

set_coordinates(object) <- value

# S4 method for Matrix
get_coordinates(object)

# S4 method for Matrix
set_coordinates(object) <- value

Arguments

object

An object from which to get or set element(s).

value

A possible value for the element(s) of object (see below).

Details

An attempt is made to interpret the argument value in a way suitable for geographic coordinates.

If value is a:

list

containing components "x", "y" and "z", these are used to define coordinates (longitude, latitude and elevation, respectively). If "z" is missing, the vertical coordinates will be ignored (and NA will be generated).

matrix or data.frame with two or more columns

the first is assumed to contain the x values, the second the y and the third the z values. Note that if value has columns named "x", "y" and "z", these columns will be used. If value has only two columns or has columns named "x" and "y" but not "z", the vertical coordinates will be ignored (and NA will be generated).

Note

EXPERIMENTAL: subject to major changes in a future release.

Examples

## Create a count data matrix A <- CountMatrix(data = sample(0:10, 100, TRUE), nrow = 10, ncol = 10, dimnames = list(LETTERS[1:10], NULL)) ## Set geographic coordinates as a matrix B <- matrix(data = sample(0:10, 30, TRUE), nrow = 10, ncol = 3) set_coordinates(A) <- B get_coordinates(A)
#> X Y Z #> A 5 10 2 #> B 9 10 4 #> C 7 1 6 #> D 1 3 4 #> E 1 8 9 #> F 4 10 5 #> G 4 8 6 #> H 9 3 10 #> I 2 3 9 #> J 4 7 9
## Set geographic coordinates as a data.frame B <- data.frame(sample(0:10, 5, TRUE), sample(0:10, 5, TRUE), sample(0:10, 5, TRUE), row.names = LETTERS[seq(1, 10, 2)]) set_coordinates(A) <- B get_coordinates(A)
#> X Y Z #> A 2 8 5 #> B NA NA NA #> C 3 8 5 #> D NA NA NA #> E 10 2 8 #> F NA NA NA #> G 0 3 8 #> H NA NA NA #> I 3 8 3 #> J NA NA NA
## Set geographic coordinates as a list B <- list(X = sample(0:10, 10, TRUE), Y = sample(0:10, 10, TRUE)) set_coordinates(A) <- B get_coordinates(A)
#> X Y Z #> A 7 7 NA #> B 5 9 NA #> C 10 6 NA #> D 7 2 NA #> E 2 3 NA #> F 6 6 NA #> G 9 7 NA #> H 9 10 NA #> I 6 4 NA #> J 5 8 NA
## Unset geographic coordinates set_coordinates(A) <- NULL get_coordinates(A)
#> [1] X Y Z #> <0 rows> (or 0-length row.names)