# [R-sig-Geo] creating STFDF or ST objects in R

chris english englishchristophera at gmail.com
Mon Jul 13 08:28:59 CEST 2015

```Ajoke:

> delta
function (x)
{
if (any(is.na(x)))
stop("time values cannot be negative")
augment.with.one = function(x) {
ux = unique(x)
l = length(ux)
if (l <= 1)
stop("cannot derive time interval from length 1 or constant
sequence")
lx = length(x)
x = x[c(1:lx, lx)]
stopifnot(x[lx] == ux[l])
x[lx + 1] = x[lx] + (ux[l] - ux[l - 1])
x
}
if (is(x, "xts"))
x = index(x)
ret = augment.with.one(as.POSIXct(x))[-1]
ret
}
<environment: namespace:spacetime>

Judging from your function paraphrasing "x\$datetime <- Timex[i]" and the
subsequent p <- STIDF sounds to me like you're saying "The time is in there
(at x\$datetime), recognize it!"  The test in delta says indeed it was
recognized as time, it's just not as long as you think it is.

I've found building my POSIXct objects outside my spatial df and then
calling STIDF of STFDF lets me first test that I have as many time values
as I should before tossing it in the tangle of STIDF.

HTH,

Chris

On Sun, Jul 12, 2015 at 5:20 PM, Edzer Pebesma <
edzer.pebesma at uni-muenster.de> wrote:

>
>
> On 07/12/2015 10:16 PM, joke atuge via R-sig-Geo wrote:
> > Hello, This is in addition to my earlier message. Here's the sample
> codes oh how I tried to create the STFDF. DLF is a list of variables called
> "FRP"  for each polygon in the DL3 list. Timex is the time list for the
> spatial polygons list.
> > DL7 <- sapply(1:length(DL3), function(i) {
> >   x <- DL3[[i]]
> > x\$FRP <- DLF[[i]]
> >  x\$datetime<-Timex[i]
> >  z<-Timex[i]
> >   p<-STIDF(x,data=x["FRP"],x\$datetime,delta(x\$datetime))
> >   p})
> >
> > The error I get is: Error in augment.with.one(as.POSIXct(x)) :
> >   cannot derive time interval from length 1 or constant sequence
>
> x\$datetime has length 1; the docs of delta() tell you that it requires
> an argument of length 2 or larger. Maybe you can specify endTime to
> STIDF, e.g. as x\$datetime, possibly a constant added to it.
>
> > Kind regards,Ajoke
> >
> >       On Sunday, July 12, 2015 6:08 PM, joke atuge <
> jazzpriestess2000 at yahoo.com> wrote:
> >
> >
> >  Hello,
> >  I am having serious issues creating a space time object with a list of
> spatialpolygonsdataframes and their dates/ time. I keep getting an error
> about the time not changing. How can I get this done please? Here's a
> sample of my data:
> >
> > [[1]]
> > class       : SpatialPolygonsDataFrame
> > features    : 128
> > extent      : -127.44, -67.8964, 1.000039, 31.71804  (xmin, xmax, ymin,
> ymax)
> > coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> > variables   : 1
> > names       : DDD.LFRP
> > min values  :     16.6
> > max values  :    488.5
> >
> > [[2]]
> > class       : SpatialPolygonsDataFrame
> > features    : 126
> > extent      : -129.04, -67.8964, 3.759985, 31.71804  (xmin, xmax, ymin,
> ymax)
> > coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> > variables   : 1
> > names       : DDD.LFRP
> > min values  :       14
> > max values  :    335.2
> > The Time variables look like this:
> > Timex
> >  [1] "2008-12-01 04:00:00 GMT" "2008-12-01 06:30:00 GMT"
> >
> > I have a list of 3,000 and the aim is to structure these spatialpolygons
> > dataframe in such a way that I can have monthly aggregates.
> >  How do I create an STFDF or STIDF, please? I can convert to rasters and
> agregate but they are of varying extents and resolutions for each time.
> > Kind regards,
> > Ajoke
> >
> >
> >
> >       [[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]]

```