Extend spacetime ST
Chris, I'd use the following for a class "watch_circ" that extends ST and adds a character ID slot:
setClass("watch_circ", contains = "ST", slots = c(ID = "character"))
showClass("watch_circ")
Class "watch_circ" [in ".GlobalEnv"] Slots: Name: ID sp time endTime Class: character Spatial xts POSIXct Extends: "ST"
On 06/06/2015 07:58 AM, chris english wrote:
Hi, I am attempting to extent spacetime ST to include an ID class for a spacetime watch circle object. I am doing this in order to be able to relatively easily test that I have unique ID(s) across several similar objects for plotting purposes. I can build my watch circle:
setClass("watch_circ",
+ slots = c(sp = "Spatial", time = "xts", ID = "character",
+ endTime = "POSIXct"),
+ validity = function(object) {
+ stopifnot(length(object at sp) >= 1)
+ stopifnot(nrow(object at time) >= 1)
+ stopifnot(is.char(object at ID))
+ stopifnot(nrow(object at time) == length(object at endTime))
+ # do the tzones if not set, if set
+ tz1 = attr(object at time, "tzone")
+ tz2 = attr(object at emdTime, "tzone")
+ tz1.set = (!is.null(tz1) && !nchar(tz1)==0)
+ tz2.set = (!is.null(tz2) && !nchar(tz2)==0)
+ stopifnot(tz1 == tz2)
+ if (tz1.set)
+ stopifnot(tz1 == tz2)
+ if (any(names(object at time) %in% names(object at sp)))
+ stop("name conflict: attribute names in sp and time slot must differ")
+ return(TRUE)
+ }
+ )
getClassDef('watch_circ')
Class "watch_circ" [in ".GlobalEnv"] Slots: Name: sp time ID endTime Class: Spatial xts character POSIXct But not extend ST.
setClass("watch_circ_1", representation = "ST")
getClassDef('watch_circ_1')
Class "watch_circ_1" [in ".GlobalEnv"] Slots: Name: sp time endTime Class: Spatial xts POSIXct Extends: "ST"
?what am I doing wrong here?
This is probably due to my shallow understanding of the difference between slots and representation, and possibly this whole operation is unnecessary if plot checks sp for unique ID(s) among objects. Thanks in advance, Cheers, Chris [[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster, Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081 Journal of Statistical Software: http://www.jstatsoft.org/ Computers & Geosciences: http://elsevier.com/locate/cageo/ Spatial Statistics Society http://www.spatialstatistics.info -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 490 bytes Desc: OpenPGP digital signature URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20150606/7dd02e2e/attachment.bin>