POSIX* objects and writeOGR()
Thanks! I see that creating a temporary SPDF with that variable casted as character is the only way to run writeOGR(). Would it be possible adding an option i.e. POSIXtoCHAR=T to writeOGR() so that such a conversion is automated? Agus
Michael Sumner wrote:
POSIXlt stores the date-times as a list of vectors decomposed into the
(still numeric) component parts ("sec", "min", "hour", "mday", "mon",
"year", "wday", "yday", "isdst") so that cannot be stored as a single
column in the data frame - you would need 9 columns.
Compare these to see the underlying structure:
tm <- Sys.time()
## POSIXct
unclass(tm)
## POSIXlt
unclass(as.POSIXlt(tm))
You can just cast to character, directly or with format - see
?strptime for the full set of format tokens available. For example:
as.character(tm)
##[1] "2009-12-31 07:28:01"
format(tm, "%Y/%b/%a %H:%M:%S")
##[1] "2009/Dec/Thu 07:28:01"
Hope that helps.
Regards, Mike.
On Thu, Dec 31, 2009 at 7:15 AM, Agustin Lobo <alobolistas at gmail.com> wrote:
This might be a bit off-topic. I have to export as shape an Sp.Poly.DF in which one of the variables records date and time as POSIXtc. As writeOGR() complains about the POSIXct variable, I'm trying to convert to POSIXlt, which I think that will be accepted (another alternative would be coverting to an string char, but prefer to keep the SPDF object with a correct class definition for that variable). Let's call patata the table of the SPDF.
class(patata$Tima)
[1] "POSIXt" "POSIXct"
patata$Tima[1]
[1] "2009-09-26 09:57:24 CEST"
as.POSIXlt(patata$Tima[1])
[1] "2009-09-26 09:57:24 CEST"
class(as.POSIXlt(patata$Tima[1]))
[1] "POSIXt" "POSIXlt" So I was happy, but:
patata$Tima <- as.POSIXlt(patata$Tima)
Error in `$<-.data.frame`(`*tmp*`, "Tima", value = list(sec = c(24, 33, : replacement has 9 rows, data has 44 Calls: $<- -> $<-.data.frame Is there any way I can put the POSIXlt object in the table (patata) of the SPDF object? Thanks! Agus
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo