[R-sig-Geo] Error in validityMethod(object) using SpatialGridDataFrame

Edzer Pebesma edzer.pebesma at uni-muenster.de
Wed Dec 22 16:15:41 CET 2010



On 12/22/2010 04:15 PM, Maxime Pauwels wrote:
> Dear list,
> 
> I try to create an object of class SpatialGridDataFrame-class and got
> the following error I do not understand.
> Error in validityMethod(object) :
>   unequal number of objects in full grid and data slot
> 
> There is the script I use. Does anyone could help me understanding where
> I am wrong?
> 
> Many thanks
> 
> max
> 
> 
> rgrd <- GridTopology(cellcentre.offset=c(-4.5,40), cellsize=c(0.1674757,
> 0.1674757), cells.dim=c(207, 90))
> summary(rgrd)
> #Grid topology:
> #  cellcentre.offset  cellsize cells.dim
> #1              -4.5 0.1674757       207
> #2              40.0 0.1674757        90
> rdata<-SpatialGridDataFrame(rgrd, data=read.table("rdataNssSF.txt",
> header=T), proj4string=CRS("+proj=longlat"))
> #Error in validityMethod(object) :
> #  unequal number of objects in full grid and data slot

Maybe some of the cells have missing values, and in the current setup
the constructor function SpatialGridDataFrame cannot figure out which --
it simply expects 207 x 90 records, in a particular order.

> #
> #
> #However
> data=read.table("rdataNssSF.txt")
> class(data)
> #[1] "data.frame"
> #and
> coordinates(data)=~long+lat
> gridded(data)=TRUE

then add here:

fullgrid(data) = TRUE

> summary(data)
> #Object of class SpatialPixelsDataFrame
> #Coordinates:
> #           min      max
> #long -4.583738 30.08374
> #lat  39.915730 55.08427
> #Is projected: NA
> #proj4string : [NA]
> #Number of points: 15267
> #Grid attributes:
> #     cellcentre.offset  cellsize cells.dim
> #long              -4.5 0.1674757       207
> #lat               40.0 0.1685393        90
> #Data attributes:
> #    Min.  1st Qu.   Median     Mean  3rd Qu.     Max.
> #-0.75140 -0.15700  0.01150  0.03421  0.22100  0.85000
> 
> 
> 

-- 
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