coordinates: Sets spatial coordinates to create 'SpatialSpectraDataFrame'...

Description Usage Arguments Value Author(s) See Also Examples

Description

Sets spatial coordinates to create SpatialSpectraDataFrame objects. Adapted from the "coordinates<-" method in the sp package.

Usage

1
coordinates(object) <- value

Arguments

object

A SpectraDataFrame object

value

Spatial coordinates: either a matrix, list, or data frame with numeric data, or column names, column number or a reference: a formula (in the form of e.g. ~x+y), column numbers (e.g. c(1,2)) or column names (e.g. c("x","y")) specifying which columns in object are the spatial coordinates. If the coordinates are part of object, giving the reference does not duplicate them, giving their value does duplicate them in the resulting structure.

Value

A SpatialSpectraDataFrame object

Author(s)

Pierre Roudier pierre.roudier@gmail.com, from code from the sp package.

See Also

spectra

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
# Loading example data
data(australia)
spectra(australia) <- sr_no ~ ... ~ 350:2500

# The australia dataset does not have associated coordinates.
# To fake it is a spatial dataset, we will associate each spectra
# in the collection to a location in the meuse dataset provided
# by the sp package

# Loding the meuse.grid dataset from the sp package
library(sp)
data(meuse.grid)
coordinates(meuse.grid) = ~x+y
proj4string(meuse.grid) <- CRS("+init=epsg:28992")
gridded(meuse.grid) = TRUE

# We randomly generate sampling locations on this grid
coords <- spsample(meuse.grid, n=nrow(australia)*2, type="random")
class(coords)

# We associate these locations to the spectra in the collection
#

# First, we add the coordinates in the data slot data
features(australia, safe=FALSE) <- as.data.frame(coords)[1:nrow(australia), ]
names(australia)

# Then we promote the SpectraDataFrame object to a SpatialDataFrame object
coordinates(australia) <- ~x+y
class(australia)
str(australia)

inspectr documentation built on May 2, 2019, 5:45 p.m.