as.geosamples {GSIF} | R Documentation |
Converts an object of class "SoilProfileCollection"
or "SpatialPointsDataFrame"
to an object of class "geosamples"
with all measurements broken into individual records. Geosamples are standardized spatially and temporally referenced samples from the Earth's surface.
## S4 method for signature 'SoilProfileCollection' as.geosamples(obj, registry = as.character(NA), sample.area = 1, mxd = 2, TimeSpan.begin, TimeSpan.end) ## S4 method for signature 'SpatialPointsDataFrame' as.geosamples(obj, registry = as.character(NA), sample.area = 1, mxd = 2, TimeSpan.begin, TimeSpan.end)
obj |
object of class |
... |
optional arguments |
registry |
URI specifying the metadata registry (web-service that carries all metadata connected to the certain method ID and/or sample ID) |
sample.area |
standard sample area in square meters (assumed to be 1 by 1 m) |
mxd |
maximum depth of interest in meters |
TimeSpan.begin |
vector of class |
TimeSpan.end |
vector of class |
Returns an object of type "geosamples"
. Many columns required by the "geosamples"
class might be not available and will result in NA
values. To ensure compatibility, when building an object of type "SoilProfilesCollection"
, use some standard naming convention to attach attributes to each measurement (horizons and sites slots in the "SoilProfileCollection-class"
):
"locationError"
can be used to attach location errors in meters to each spatial location
"sampleArea"
can be used to attach spatial support to each measurement (usually 1 by 1 meter)
"measurementError"
can be used to attach specific measurement errors to each measurement in both site and horizons table
"IGSN"
can be used to attach the unique identifier (International Geo Sample Number) to each specific observation (corresponds to the "observationid"
column)
Tomislav Hengl and Hannes I. Reuter
geosamples-class
, as.data.frame
, aqp::SoilProfileCollection
library(aqp) library(plyr) library(rgdal) library(sp) # sample profile from Nigeria: lon = 3.90; lat = 7.50; time = as.POSIXct("1978", format="%Y") id = "ISRIC:NG0017"; TAXNFAO8 = "LXp" top = c(0, 18, 36, 65, 87, 127) bottom = c(18, 36, 65, 87, 127, 181) ORCDRC = c(18.4, 4.4, 3.6, 3.6, 3.2, 1.2) methodid = c("TAXNFAO8", "ORCDRC") description = c("FAO 1988 classification system group", "Method of Walkley-Black (Org. matter = Org. C x 1.72)") units = c("FAO 1988 classes", "permille") detectionLimit = c(as.character(NA), "0.1") # prepare a SoilProfileCollection: prof1 <- join(data.frame(id, top, bottom, ORCDRC), data.frame(id, lon, lat, time, TAXNFAO8), type='inner') depths(prof1) <- id ~ top + bottom site(prof1) <- ~ lon + lat + time + TAXNFAO8 coordinates(prof1) <- ~ lon + lat + time proj4string(prof1) <- CRS("+proj=longlat +datum=WGS84") # add measurement errors: attr(prof1@horizons$ORCDRC, "measurementError") <- c(1.5, 0.5, 0.5, 0.5, 0.5, 0.5) attr(prof1@sp@coords, "locationError") <- 1500 # add the metadata: prof1@metadata <- data.frame(methodid, description, units, detectionLimit) # convert to geosamples: x <- as.geosamples(prof1) x # print only the sampled values of ORCDRC: ORCDRC <- subset(x, "ORCDRC") ORCDRC[,c("sampleid", "altitude", "observedValue")] # convert object of type SpatialPointsDataFrame: data(meuse) # prepare columns: names(meuse)[which(names(meuse)=="x")] = "longitude" names(meuse)[which(names(meuse)=="y")] = "latitude" meuse$altitude = -.15 meuse$time = unclass(as.POSIXct("1992-01-01")) coordinates(meuse) <- ~ longitude + latitude + altitude + time proj4string(meuse) <- CRS("+init=epsg:28992") library(plotKML) hm <- reproject(meuse[,c("zinc", "copper")]) hm.geo <- as.geosamples(hm) hm.geo