[R-sig-Geo] Apply() function on 3rd dimension of SpatialGridDataFrame
Edzer Pebesma
edzer.pebesma at uni-muenster.de
Thu Dec 20 22:12:01 CET 2012
On 12/20/2012 07:56 PM, Nathalie Morin wrote:
> 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() ?
No, you should inspect A, check dim(A) and find out that it is a
one-dimensional array;
apply(array(1:3), 3, mean)
triggers the same error.
as.array(clip) will only work if you add the appropriate as.array
method, e.g.
as.array.SpatialGridDataFrame = function(x,...) {
d = gridparameters(x)$cells.dim
if (ncol(x at data) > 1)
d = c(d, ncol(x at data))
array(do.call(c, x at data), dim = d)
}
then, as.array(clip) will return a 3 or 4 dimensional array (4 if clip
has more than one attribute).
Note that this function produces an array for which y decreases with
increasing index, all other dimensions increase with increasing index.
I will add this method to sp.
>
> 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.
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de
http://www.52north.org/geostatistics e.pebesma at wwu.de
More information about the R-sig-Geo
mailing list