[R-sig-Geo] Apply() function on 3rd dimension of SpatialGridDataFrame

Nathalie Morin Nathalie.M.Morin at usherbrooke.ca
Thu Dec 20 19:56:22 CET 2012


Dear Edzer,

1) as.array()
/"Would an as.array(clip) method for
SpatialGridDataFrame help you further?"/

Yes, as I mentionned in my initial post :
/"The only solution I found is to convert back to standard non spatial 3D
array."/
(in order to make the apply() function work on my 3rd dimension or z layer)

I still encounter a problem though :

D.tls.SPGDF <- SpatialGridDataFrame(D.tls.SPG, D.tls.DF)

buffer <- readOGR("donnees/limites", layer="bure_106_buffer")
buffer.proj <- spTransform(buffer, CRS("+init=epsg:27561"))
g <- geometry(buffer.proj)

fullgrid(D.tls.SPGDF) = FALSE
clip <- D.tls.SPGDF[g,,drop=TRUE] 
fullgrid(clip) = TRUE

A <- as.array(clip$d)
DA <- apply(A, 3, mean, na.rm=T)
=> gives an error message related to a missing value where TRUE / FALSE is
required
"Erreur dans if (d2 == 0L) { : valeur manquante là où TRUE / FALSE est
requis"

I suspect this could be related to the fullgrid() ?
Any hint ?

2) /Or is it something else you need,
e.g. clipping a SpatialGridDataFrame with more than 2 dimensions? /

This is another story ! For the moment, I do not need a convex hull because
I do not want to truncate the height information on the z axis. But this is
an interesting question. I should probably open a separate post for that.










--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Apply-function-on-3rd-dimension-of-SpatialGridDataFrame-tp7582023p7582036.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list