[R-sig-Geo] spplot of SpatialGridDateFrame (sparsely populated with data) fails

Edzer Pebesma edzer.pebesma at uni-muenster.de
Wed Apr 16 16:20:45 CEST 2014


After some off-list communication, this pointed to several bugs in sp,
which have now been corrected (patch committed to r-forge).

On 03/27/2014 12:59 PM, rolandh at uni-muenster.de wrote:
> Hello R-users!
> 
> I want to plot SpatialGridDataFrames with spplot() and I get some strange /
> unexpected / irregular results in some special cases:
> 
> For testing and illustration issues I have created 4 SpatialGridDataFrames by
> aggregation from the same SpatialPointDataFrame (attribute)  (which is
> populated with a lot of NA values). When I check the data, I see that there is
> just one grid cell that is populated with data in the SpatialGridDataFrames.
> 
> If I try to plot these four SpatialGridDataFrames with spplot(), just one of
> the spplots finishes successfully.
> The others throw an error...
> 
> 
> Overview of the creation of the SpatialGridDataFrames and the errors /
> returns:
> 
> a) spGridDF_builtByMeanAsAggFct
> Packages used: raster, sp.
> I built a raster layer and aggregated the data by using the method rasterize()
> and the aggregation function "mean".
> Then I used as(... , "SpatialGridDataFrame"). When I try to plot with spplot()
> I get:
> Error in validObject(.Object) :
>   invalid class “SpatialPoints” object: invalid object for slot "coords" in
>   class "SpatialPoints": got class "numeric", should be or extend class
>   "matrix"
> I get the same error when I use "median" or "sd" as aggregation function.
> 
> b) spGridDF_builtByMinAsAggFct
> Here I did the same as above (!) but I just used "min" (!) as aggregation
> function and spplot() finishes successfully! The plot contains one grid cell.
> That is fine and it is what I expected. I also get a plot when I use "max" as
> aggregation function.
> I do not understand the relationship of the selected aggregation function and
> the spplot result (error, success).
> 
> c) spGridDF_builtByPkgSP_minAsAggFct
> Packages used: sp
> After the creation of the grid I aggregated the data using the method
> aggregate() with "min" as aggregation function.
> When I try to plot with spplot() I get:
> Error in seq.default(zrng[1], zrng[2], length.out = cuts + 2) :
>   'from' cannot be NA, NaN or infinite
> Zusätzlich: Warnmeldungen: (warnings)
> 1: In asMethod(object) :
>   complete map seems to be NA's -- no selection was made
> 2: In min(x) : kein nicht-fehlendes Argument für min; gebe Inf zurück
> 3: In max(x) : kein nicht-fehlendes Argument für max; gebe -Inf zurück
> 
> d) spGridDF_builtByPkgSP_withoutNA_minAsAggFct
> In this case I did the same as above [case c)], but I removed the NA values in
> the SpatialPointDataFrame with subset(spdf_wgs,
> complete.cases(spdf_wgs[[attribute]])) before I used the aggregate() method.
> When I try to plot with spplot() I get (again):
> Error in validObject(.Object) :
>   invalid class “SpatialPoints” object: invalid object for slot "coords" in
>   class "SpatialPoints": got class "numeric", should be or extend class
>   "matrix"
> 
> 
> If you want to check the data, you may get an .RData file containing the 4
> SpatialGridDataFrames and the SpatialPointDataFrame on:
> https://github.com/LarsGH/Geosoftware2GroupC/tree/master/R/spplot_problem.RData
> 
> 
> What may be the problem causing spplot to fail?
> 
> And, even more important, how may I avoid that problem?
> 
> 
> I would be very happy if someone could please help me.
> 
> Thank you very much in advance!
> 
> Greetings!
> 
> Roland
> 
> 
> ###
>> sessionInfo()
> 
> R version 3.0.3 (2014-03-06)
> Platform: i686-pc-linux-gnu (32-bit)
> 
> locale:
>  [1] LC_CTYPE=de_DE.UTF-8       LC_NUMERIC=C               LC_TIME=de_DE.UTF-8
>  LC_COLLATE=de_DE.UTF-8
>  [5] LC_MONETARY=de_DE.UTF-8    LC_MESSAGES=de_DE.UTF-8
>  LC_PAPER=de_DE.UTF-8       LC_NAME=C
>  [9] LC_ADDRESS=C               LC_TELEPHONE=C
>  LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C
> 
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
> 
> other attached packages:
>  [1] colorRamps_2.3      plyr_1.8            Cairo_1.5-5
>  latticeExtra_0.6-26 RColorBrewer_1.0-5
>  [6] ggmap_2.3           ggplot2_0.9.3.1     raster_2.2-12
>  lattice_0.20-27     RCurl_1.95-4.1
> [11] bitops_1.0-6        maptools_0.8-27     rgdal_0.8-14        sp_1.0-14
> futile.logger_1.3.7
> [16] rjson_0.2.13
> 
> loaded via a namespace (and not attached):
>  [1] colorspace_1.2-4     dichromat_2.0-0      digest_0.6.4
>  foreign_0.8-59       futile.options_1.0.0
>  [6] grid_3.0.3           gtable_0.1.2         labeling_0.2
>  lambda.r_1.1.6       mapproj_1.2-2
> [11] maps_2.3-6           MASS_7.3-30          munsell_0.4.2        png_0.1-7
> proto_0.3-10
> [16] reshape2_1.2.2       RgoogleMaps_1.2.0.5  RJSONIO_1.0-3
> scales_0.2.3         stringr_0.6.2
> [21] tools_3.0.3
> ###
> 
> ###
>> library(help=sp)
> 
>                 Information on package ‘sp’
> 
> Description:
> 
> Package:            sp
> Version:            1.0-14
> Date:               2013-10-15
> Title:              classes and methods for spatial data
> Authors at R:          c(person("Edzer", "Pebesma", role = c("aut", "cre"), email
> =
>                     "edzer.pebesma at uni-muenster.de"), person("Roger",
>                     "Bivand", role = "aut", email =
>                     "Roger.Bivand at nhh.no"), person("Barry", "Rowlingson", role
>                     = "ctb"),
>                     person("Virgilio", "Gomez-Rubio", role = "ctb"))
> Depends:            R (>= 2.14.0)
> Imports:            methods, graphics, utils, lattice, grid
> Suggests:           RColorBrewer, rgdal (>= 0.8-7), rgeos (>= 0.2-20), gstat
> Description:        A package that provides classes and methods for spatial
> data. The classes
>                     document where the spatial location information resides,
>                     for 2D or 3D data.
>                     Utility functions are provided, e.g. for plotting data as
>                     maps, spatial
>                     selection, as well as methods for retrieving coordinates,
>                     for subsetting, print,
>                     summary, etc.
> License:            GPL (>= 2)
> URL:                https://r-forge.r-project.org/projects/rspatial/
>                     http://rspatial.r-forge.r-project.org/
> Collate:            AAA.R Class-CRS.R CRS-methods.R Class-Spatial.R
> Spatial-methods.R projected.R
>                     Class-SpatialPoints.R SpatialPoints-methods.R
>                     Class-SpatialPointsDataFrame.R
>                     SpatialPointsDataFrame-methods.R Class-GridTopology.R
>                     Class-SpatialGrid.R
>                     Class-SpatialGridDataFrame.R Class-SpatialLines.R
>                     SpatialLines-methods.R
>                     Class-SpatialLinesDataFrame.R
>                     SpatialLinesDataFrame-methods.R
>                     Class-SpatialPolygons.R Class-SpatialPolygonsDataFrame.R
>                     SpatialPolygons-methods.R
>                     SpatialPolygonsDataFrame-methods.R
>                     GridTopology-methods.R SpatialGrid-methods.R
>                     SpatialGridDataFrame-methods.R
>                     SpatialPolygons-internals.R point.in.polygon.R
>                     SpatialPolygons-displayMethods.R
>                     zerodist.R image.R stack.R bpy.colors.R bubble.R mapasp.R
>                     select.spatial.R
>                     gridded.R asciigrid.R spplot.R over.R overlay.R spsample.R
>                     recenter.R dms.R
>                     gridlines.R spdists.R rbind.R flipSGDF.R chfids.R
>                     loadmeuse.R compassRose.R
>                     surfaceArea.R spOptions.R subset.R disaggregate.R
>                     sp_spat1.R merge.R
> Packaged:           2013-10-23 11:03:37 UTC; edzer
> Author:             Edzer Pebesma [aut, cre], Roger Bivand [aut], Barry
> Rowlingson [ctb], Virgilio
>                     Gomez-Rubio [ctb]
> Maintainer:         Edzer Pebesma <edzer.pebesma at uni-muenster.de>
> NeedsCompilation:   yes
> Repository:         CRAN
> Date/Publication:   2013-10-24 09:38:03
> Built:              R 3.0.2; i686-pc-linux-gnu; 2013-12-11 13:36:45 UTC; unix
> ###
> 
> _______________________________________________
> 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
Heisenbergstraße 2, 48149 Münster, Germany. Phone: +49 251
83 33081 http://ifgi.uni-muenster.de GPG key ID 0xAC227795



More information about the R-sig-Geo mailing list