[R-sig-Geo] trouble coercing SpatialPixelsDataFrame into SpatialGridDataFrame?

ElenaC E.Couce.07 at bristol.ac.uk
Wed Oct 20 12:56:15 CEST 2010


Dear all,

I'm having trouble doing what I thought would be a very simple conversion. I
have a SpatialPixelsDataFrame variable which has a single data attribute, a
logical variable:

> summary(data_pixels)
Object of class SpatialPixelsDataFrame
Coordinates:
           min max
coords.x1 -180 180
coords.x2  -60  60
Is projected: NA
proj4string : [NA]
Number of points: 3972
Grid attributes:
          cellcentre.offset cellsize cells.dim
coords.x1            -179.5        1       360
coords.x2             -59.5        1       120
Data attributes:
   Mode   FALSE    TRUE    NA's
logical    3733     239       0 


When I try to convert it to SpatialGridDataFrame, for some reason I lose all
the grid cells which were TRUE:

> data_grid <- as(data_pixels,'SpatialGridDataFrame')
> summary(data_grid)
Object of class SpatialGridDataFrame
Coordinates:
           min max
coords.x1 -180 180
coords.x2  -60  60
Is projected: NA
proj4string : [NA]
Number of points: 2
Grid attributes:
          cellcentre.offset cellsize cells.dim
coords.x1            -179.5        1       360
coords.x2             -59.5        1       120
Data attributes:
   Mode   FALSE    NA's
logical    3733   39467 


Sorry if this is really obvious, but I don't understand why this is
happening. What I wanted to do was keep both the FALSE and TRUE data and
fill in all the rest of the grid cells with NAs. Any hint would be greatly
appreciated!

Regards,
Elena
-- 
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/trouble-coercing-SpatialPixelsDataFrame-into-SpatialGridDataFrame-tp5654305p5654305.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list