[R-sig-Geo] writeOGR() to shapefile and dates/times classes

Roger Bivand Roger.Bivand at nhh.no
Mon Jun 25 09:35:36 CEST 2012


On Sun, 24 Jun 2012, Agustin Lobo wrote:

> Roger,
>
> Roger,
> What you say makes a lot of sense, I make the objects conform to the
> accepted classes,
> although perhaps you could include chron as well, which is one of the
> 3 recommended by
> Gabor
> http://cran.r-project.org/doc/Rnews/Rnews_2004-1.pdf

Sorry, only base data-time classes can be considered, because otherwise 
the package would become dependent on chron. The work-around looks OK.

Roger

>
> I've put the rda here:
> http://dl.dropbox.com/u/3180464/Bert20120621footp.rda
>
> The classes are:
>> class( Bert20120621footp at data$DateMCA)
> [1] "Date"
>> class( Bert20120621footp at data$TimeMCA)
> [1] "times"
>> class( Bert20120621footp at data$DateGPS)
> [1] "Date"
>> class( Bert20120621footp at data$TimeGPS)
> [1] "times"
>>
>
> What I  do to circumvent the problem:
> a <- Bert20120621footp
> a at data$DateMCA <- as.character(a at data$DateMCA)
> a at data$TimeMCA <- as.character(a at data$TimeMCA)
> a at data$DateGPS <- as.character(a at data$DateGPS)
> a at data$TimeGPS <- as.character(a at data$TimeGPS)
> writeOGR(a,dsn="Bert20120621footp",layer="Bert20120621footp",driver="ESRI
> Shapefile",check_exists=TRUE,overwrite_layer=TRUE)
> rm(a)
>
> Thanks,
> Agus
>
>> sessionInfo()
> R version 2.15.0 (2012-03-30)
> Platform: i686-pc-linux-gnu (32-bit)
>
> locale:
> [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
> LC_TIME=en_US.UTF-8
> [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8
> LC_MESSAGES=en_US.UTF-8
> [7] LC_PAPER=C                 LC_NAME=C
> LC_ADDRESS=C
> [10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8
> LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] raster_1.9-92 sp_0.9-99
>
> loaded via a namespace (and not attached):
> [1] grid_2.15.0     lattice_0.19-30 tools_2.15.0
>
>
>
>
> 2012/6/24 Roger Bivand <Roger.Bivand at nhh.no>:
>> On Sun, 24 Jun 2012, Agustin Lobo wrote:
>>
>>> writeOGR() issues an error if the Spatial Points/Polygon Dataframe
>>> has any variables of classes dates or times. While I understand that
>>> this is rather a problem of using a bad format (shapefile) that does not
>>> accept
>>> these kind of variables, I suggest
>>> the developer could consider that the necessary conversion to character
>>> were done automatically by writeOGR() and just issue a warning message
>>> instead of an error.
>>
>>
>> Please provide a reproducible example, and sessionInfo() output.
>>
>> The function already converts the standard date and time classes POSIXct,
>> POSIXlt, Date and POSIXt to character. If the user chooses a non-base
>> date-time representation, arguably the user should then convert to a base
>> class first, otherwise rgdal would depend on zoo, xts, lubridate or
>> whatever.
>>
>> Roger
>>
>>>
>>> Thanks!
>>>
>>> Agus
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo at r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>> --
>> Roger Bivand
>> Department of Economics, NHH Norwegian School of Economics,
>> Helleveien 30, N-5045 Bergen, Norway.
>> voice: +47 55 95 93 55; fax +47 55 95 95 43
>> e-mail: Roger.Bivand at nhh.no
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list