[Rspatial-devel] Fwd: [R-sig-Geo] coercing SpatialGrid to SpatialPoints

Edzer Pebesma edzer.pebesma at uni-muenster.de
Sun Jul 10 13:28:26 CEST 2011


Regarding the message below, simply adding in sp to
SpatialGrid-methods.R the coercion function

setAs("SpatialGrid", "SpatialPoints", function(from)
    as(as(from, "SpatialPixels"), "SpatialPoints")
)

was something we tried earlier (100521) but reverted back (100607), as
it broke the book code (asdar), at chapter 6,
http://www.asdar-book.org/data.php?chapter=5 .

I now committed it again, and out-commented in csdacm.Rnw the following
line:

setIs("SpatialTimeGridDataFrame", "SpatialTimeGrid")

so that this code runs again (committed to cvs, which still runs in
geo.uu.nl). An errata for ch 6 is then needed.

I cannot explain well why this setIs causes problems later on, but it
seems somewhere to remove the @data slot on some automatic but unwanted
coercion. setIs() has caused me more trouble in the past.

After the sp commit, R CMD check failed; some coercion (it turned out, a
proj4string(obj) = sth inside fullgrid<- ) automatically coerced a
SpatialGrid into an object of class Spatial which should NEVER happen! I
"solved" this by changing the "proj4string<-" definition from an S4
function (SetReplacemethod...) to S3, and modified Spatial-methods.R and
NAMESPACE accordingly. Why this came up, and why this solution worked,
is more than the setIs() issue, complete black magic to me.

In case of no comments, I will continue and release the current sp in svn.

Best wishes,


-------- Original Message --------
Subject: [R-sig-Geo] coercing SpatialGrid to SpatialPoints
Date: Fri, 8 Jul 2011 11:18:34 -0700
From: David Holstius <david.holstius at berkeley.edu>
To: r-sig-geo at r-project.org

Hi all,

I'm trying to figure out why coercing a SpatialGrid directly to a
SpatialPoints doesn't result in the same thing as coercing it via an
intermediate SpatialPixels. Here's a minimal example:

  require(sp)
  grd <- SpatialGrid(GridTopology(c(0,0), c(10,10), c(4,4)))
  as(as(grd, "SpatialPixels"), "SpatialPoints")	# result == what I expect
  as(grd, "SpatialPoints")	# result != expected

Is this behavior as expected? Maybe I am doing it wrong?

Many thanks,
David

--
David Holstius
PhD Student in Environmental Health Sciences
UC Berkeley School of Public Health

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


More information about the Rspatial-devel mailing list