[R-sig-Geo] times and ID records for sp

Roger Bivand Roger.Bivand at nhh.no
Wed Apr 19 08:23:46 CEST 2006


On Wed, 19 Apr 2006, Michael Sumner wrote:

> Hello, so far it's going well.  I have a class "SpatialPointsTOR" that 
> extends SpatialPoints by adding two slots:
> 
> library(sp)
> setClass("SpatialPointsTOR", representation("SpatialPoints", timeID = 
> "matrix", TORlevels = "character"))
> 
> I suspect it would be better to create a completely separate class and 
> so hide the expanding list of slots inside that ?
> But so far I have print, plot, show, summary, "[" methods for the class 
> that do what I want by indexing the id column
> of timeID to TORlevels, and simply assuming the epoch = 
> ISOdatetime(1970, 1, 1, 0, 0, 0, tz = "GMT") and adding that
> to the time column.  (I'll have to think about cases for POSIXlt, and 
> for Dates).
> 
> Thanks so much for sp!  This is already useful to me, and it will be 
> nice to replace my clunky other classes with the
> real power of sp. Once I've done a little more I'll package it up and 
> provide some examples.
> 
> ########################################################################################
> ########################################################################################
> 
> My new question involves a potential problem if proj4strings are passed 
> in as "NA" rather than as.character(NA):
> 
> pts <- SpatialPoints(matrix(c(159, 143, -43, -42), ncol =2), 
> CRS("+proj=longlat"))
> is.projected(pts)
> library(rgdal)
> pts <- transform(pts, CRS("+proj=lcc +lon_0=160"))
> 
> So far so good, but is.projected seems to just grep for "longlat" and 
> otherwise return TRUE.  Shouldn't this have some
> validation of the CRS to avoid the following?
> pts <- SpatialPoints(matrix(c(159, 143, -43, -42), ncol =2), "NA")   
> is.projected(pts)  #TRUE

I get:

> pts <- SpatialPoints(matrix(c(159, 143, -43, -42), ncol =2), "NA")   
Error in validObject(.Object) : invalid class "SpatialPoints" object: 
invalid object for slot "proj4string" in class "SpatialPoints": got class 
"character", should be or extend class "CRS"

for:

> sessionInfo()
R version 2.2.1, 2005-12-20, i686-pc-linux-gnu 

attached base packages:
[1] "methods"   "stats"     "graphics"  "grDevices" "utils"     "datasets" 
[7] "base"     

other attached packages:
      sp 
"0.8-14" 

but:

> pts <- SpatialPoints(matrix(c(159, 143, -43, -42), ncol =2), CRS("NA"))   
> is.projected(pts)
[1] TRUE

The checking code requires access to the libraries etc, which are in 
rgdal. As of now, these are not aligned, so even when rgdal is attached, 
no checking is done automatically. So:

> library(rgdal)
> .valid.CRSobj(CRS("NA"))
[1] "no arguments in initialization list"
> .valid.CRSobj(CRS("+proj=longlat +ellps=WGS84"))
[1] TRUE

There is about 1.5M to carry around just for PROJ.4. So I guess we'll have 
to work around things by examining the search path, and validate the CRS 
object if rgdal is attached. I think there are issues with pckage 
namespaces too (rgdal doesn't have one, sp does).

Roger

> 
> (I'm not sure how common this would be but I certainly made the error with
> a constructor like this:
> ...
> p4string <- "NA"
> new("SpatialPointsTOR", SpatialPoints(crds, proj4string = 
> CRS(p4string)), ...
> 
> 
> Cheers, Mike.
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, 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