stConstruct(spacetime)
stConstruct()所属R语言包:spacetime
create ST* objects from long or wide tables
创建ST *对象的长或宽的表
译者:生物统计家园网 机器人LoveR
描述----------Description----------
create ST* objects from long or wide tables
创建ST *对象的长或宽的表
用法----------Usage----------
stConstruct(x, space, time, SpatialObj = NULL, TimeObj = NULL, crs = CRS(as.character(NA)), interval)
参数----------Arguments----------
参数:x
object of class matrix or data.frame, holding the long, space-wide or time-wide table; see details.
类的对象matrix或data.frame,持有长,空间范围或时间范围内的表,请参阅详细信息。
参数:space
in case x is a long table, character or integer holding the column index in x where the spatial coordinates are (if length(space)==2) or where the ID of the spatial location is (if (length(space)==1). If x is a space-wide table, a list with each (named) list element a set of columns that together form a variable
的情况下x是长表,字符或整数,保持中的列索引x的空间位置的空间坐标(如果长度(空间)== 2)或其中的ID是( (长度(空间)== 1)。x如果是一个空间范围内的表格,列表与每个(命名)的列表元素的一组列,它们一起组成一个变量
参数:time
in case x is a long table, character or integer indicating the column in x with times;
的情况下x是一张长条桌,字符或整数,指示中的列x与时并进的;
参数:SpatialObj
object of class Spatial-class, containing the locations of a time-wide table, or the locations of a long table
类的对象空间类,含有一个时间宽表的位置,或长表的位置
参数:TimeObj
in case of space-wide table, object of class xts, containing the times for each of the columns in a list element of space
在空间范围内的表,对象类XTS,含有在一个列表中的每个列元素space倍箱子
参数:crs
object of class CRS-class; only used when coordinates are in x and no CRS can be taken from SpatialObj
类CRS-类的对象时使用的坐标是在x没有CRS可以从SpatialObj的
参数:interval
logical; specifies whether time should reflect time instance (FALSE) or time intervals (TRUE). If omitted, defaults values depend on the class
逻辑;指定是否应反映时间实例(FALSE)或时间间隔(TRUE)。如果省略该参数,则默认值依赖的类
Details
详细信息----------Details----------
For examples, see below.
有关示例,请参阅下文。
A long table is a data.frame with each row holding a single observation in space-time, and particular columns in this table indicate the space (location or location ID) and time.
一个长表的每一行是一个数据框,一个单一的空间时间的观察,特别是表中的列表示的空间(位置或位置ID)和时间。
A space-wide table is a table in which different columns refer to different locations, and each row reflects a particular observation time.
的空间范围内的表是一个表,在该表中的不同列指到不同的位置,并且每行反映了特定的观察时间。
A time-wide table is a table where different times of a particular characteristic are represented as different colunns; rows in the table represent particular locations or location IDs.
的时间范围内的表是一个特定的特性在不同的时间为不同的colunns表示,表中的行代表特定的地点或位置ID。
值----------Value----------
Depending on the arguments, an object of class STIDF or STFDF.
根据参数的不同,对象的类STIDF或STFDF。
实例----------Examples----------
# example 0: construction of STFDF from long table:[例如:术语表的STFDF从建设:]
library(maps)
states.m = map('state', plot=FALSE, fill=TRUE)
IDs <- sapply(strsplit(states.m$names, ":"), function(x) x[1])
library(maptools)
states = map2SpatialPolygons(states.m, IDs=IDs)
library(plm)
data(Produc)
yrs = 1970:1986
t = as.POSIXct(paste(yrs, "-01-01", sep=""), tz = "GMT")
timeIsInterval(t) = TRUE
# deselect District of Columbia, polygon 8, which is not present in Produc:[取消选择,哥伦比亚特区,多边形,这是不存在的,在生产:]
Produc.st = STFDF(states[-8], t, Produc[(order(Produc[,2], Produc[,1])),])
# example 1: st from long table, with states as Spatial object:[例1:ST长条桌,空间对象的状态:]
# use Date format for time:[使用日期时间格式为:]
Produc$time = as.Date(paste(yrs, "01", "01", sep = "-"))
# take centroids of states:[采取质心的状态:]
xy = coordinates(states[-8])
Produc$x = xy[,1]
Produc$y = xy[,2]
#using stConstruct, use polygon centroids for location:[使用stConstruct,使用多边形的重心位置:]
x = stConstruct(Produc, c("x", "y"), "time", interval = TRUE)
class(x)
stplot(x[,,"unemp"], yrs)
# alternatively, pass states as SpatialObj:[另外,通过状态SpatialObj:]
Produc$state = gsub("TENNESSE", "TENNESSEE", Produc$state)
Produc$State = gsub("_", " ", tolower(Produc$state))
x = stConstruct(Produc, "State", "time", states[-8])
class(x)
all.equal(x, Produc.st, check.attributes = FALSE)
# stConstruct multivariable, time-wide[stConstruct多变量,时间范围内]
library(maptools)
fname = system.file("shapes/sids.shp", package="maptools")[1]
nc = readShapePoly(fname, proj4string=CRS("+proj=longlat +datum=NAD27"))
timesList = list(
BIR=c("BIR74", "BIR79"), # sets of variables that belong together[,属于一组变量]
NWBIR=c("NWBIR74", "NWBIR79"), # only separated by space[只用空格隔开]
SID=c("SID74", "SID79")
)
t = as.Date(c("1974-01-01","1979-01-01"))
nc.st = stConstruct(as(nc, "data.frame"), geometry(nc), timesList,
TimeObj = t, interval = TRUE)
# stConstruct multivariable, space-wide[stConstruct多变量,空间宽]
if (require(gstat)) {
data(wind)
wind.loc$y = as.numeric(char2dms(as.character(wind.loc[["Latitude"]])))
wind.loc$x = as.numeric(char2dms(as.character(wind.loc[["Longitude"]])))
coordinates(wind.loc) = ~x+y
proj4string(wind.loc) = "+proj=longlat +datum=WGS84"
# match station order to names in wide table:[赛站,以宽表中的名称:]
stations = 4:15
wind.loc = wind.loc[match(names(wind[stations]), wind.loc$Code),]
row.names(wind.loc) = wind.loc$Station
# convert to utm zone 29, to be able to do interpolation in[转换到UTM区29,可以做插补]
# proper Euclidian (projected) space:[适当的欧几里德空间(预测):]
# create time variable[创建时间变量]
wind$time = ISOdate(wind$year+1900, wind$month, wind$day, 0)
w = STFDF(wind.loc, wind$time,
data.frame(values = as.vector(t(wind[stations]))))
space = list(values = names(wind)[stations])
wind.st = stConstruct(wind[stations], space, wind$time, SpatialObj = wind.loc, interval = TRUE)
all.equal(w, wind.st)
class(wind.st)
}
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|