[R-sig-Geo] Extend spacetime ST

chris english englishchristophera at gmail.com
Sun Jun 7 10:31:35 CEST 2015


Edzer,

Upon implementing your suggested:

> 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"

I had to do more reading unless all I was going to say was "Wow".

> 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"

> extends("watch_circ", fullInfo = TRUE)
$ST
An object of class "SClassExtension"
Slot "subClass":
[1] "watch_circ"

Slot "superClass":
[1] "ST"

Slot "package":
[1] ".GlobalEnv"

Slot "coerce":
function (from, strict = TRUE)
{
    class(from) <- "ST"
    from
}

Slot "test":
function (object)
TRUE
<bytecode: 0x19516f58>
<environment: namespace:methods>

Slot "replace":
function (from, to, value)
{
    for (what in c("sp", "time", "ID", "endTime")) slot(from,
        what) <- slot(value, what)
    from
}

Slot "simple":
[1] TRUE

Slot "by":
character(0)

Slot "dataPart":
[1] FALSE

Slot "distance":
[1] 1


$watch_circ
[1] TRUE

>
Is there a way to control the slots =c(ID, "character") order as to
prepending or postpending.
ie. (sp, time, endTime, ID) vs (ID, sp, time, endTime), or is the behavior
of subclassing the
superclass necessarily going to prepend the subclass slot(s) to the
superclass slots. It just seems on
a vernacular level that the order (sp, time, endTime, ID) is more ST-like
and signals the extending.

contains = does just what I need, or more properly want, is powerful, and
probably should be used
with caution by the magician's apprentice.

contains also leads me back to my prior 'wish list' of epochal endTimes.
Even the constraint language
of ST construction:

if (any(is.na(endTime)))
        stop("NA endTime values not allowed")

suggests toying with the concept of multiple (user defined) endTimes, or it
would merely say "NA endTime value not allowed", singular as to value, full
stop.  And with contains in mind and Pebesma (2008) "Customizing spatial
data
classes and methods" I start to see a way, ala Michael Sumner to
potentially using epochal endTimes
to extract all valid (or invalid for that matter) condition 2 quadrant 3
paths for normals and subjects to
evaluate as a TracksCollection.  Well, we'll see.

Thanks very much,

Chris




On Sat, Jun 6, 2015 at 9:47 AM, Edzer Pebesma <edzer.pebesma at uni-muenster.de
> wrote:

> 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
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list