Deal with spatial information.

get_coordinates(object)

set_coordinates(object) <- value

# S4 method for GenericMatrix
get_coordinates(object)

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

## Arguments

object An object from which to get or set element(s). 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 0  9 8
#> B 6  1 9
#> C 2  8 7
#> D 0  6 6
#> E 9  0 4
#> F 8  6 4
#> G 0  4 8
#> H 7  9 0
#> I 3  3 5
#> J 1 10 2
## 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  4  5  4
#> B NA NA NA
#> C  3 10  0
#> D NA NA NA
#> E  9  4  4
#> F NA NA NA
#> G  9  3 10
#> H NA NA NA
#> I 10  5  1
#> 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 2  1 NA
#> B 1  6 NA
#> C 9  3 NA
#> D 4  6 NA
#> E 6  2 NA
#> F 0  2 NA
#> G 5 10 NA
#> H 9  8 NA
#> I 0  2 NA
#> J 6  7 NA
## Unset geographic coordinates
set_coordinates(A) <- NULL
get_coordinates(A)#> [1] X Y Z
#> <0 rows> (or 0-length row.names)