SpatialGridDataFrame-class {sp} | R Documentation

## Class "SpatialGridDataFrame"

### Description

Class for spatial attributes that have spatial locations on a (full) regular grid.

### Objects from the Class

Objects can be created by calls of the form `as(x, "SpatialGridDataFrame")`, where `x` is of class SpatialPixelsDataFrame-class, or by importing through rgdal. Ordered full grids are stored instead or unordered non-NA cells;

### Slots

`points`:
  see SpatialPoints; points slot which is not actually filled with all coordinates (only with min/max)
`grid`:
  see GridTopology-class; grid parameters
`grid.index`:
  see SpatialPixels-class; this slot is of zero length for this class, as the grid is full
`bbox`:
  Object of class `"matrix"`; bounding box
`proj4string`:
  Object of class `"CRS"`; projection
`data`:
  Object of class AttributeList-class, containing attribute data

### Extends

Class `"SpatialGrid"`, directly. Class `"Spatial"`, by class `"SpatialGrid"`.

### Methods

coordinates
  `signature(x = "SpatialGridDataFrame")`: retrieves (and calculates!) coordinates
[
  `signature(x = "SpatialGridDataFrame")`: selects rows, columns, and attributes; returns an object of class `SpatialGridDataFrame`
[[
  `signature(x = "SpatialGridDataFrame")`: retrieves an attribute, dropping everything else (topology)
[[<-
  `signature(x = "SpatialGridDataFrame")`: assigns or replaces an attribute
as.matrix
  `signature(x = "SpatialGridDataFrame")`: coerce to matrix
cbind
  `signature(...)`: if arguments have identical topology, combine their attribute values

### Note

### Author(s)

Edzer J. Pebesma, e.pebesma@geo.uu.nl

### References

### See Also

`SpatialGrid-class`, which does not contain the attribute data, and `SpatialPixelsDataFrame-class which holds possibly incomplete grids`

### Examples

    data(meuse.grid) # only the non-missing valued cells
    coordinates(meuse.grid) = c("x", "y") # promote to SpatialPointsDataFrame
    gridded(meuse.grid) <- TRUE # promote to SpatialPixelsDataFrame
    x = as(meuse.grid, "SpatialGridDataFrame") # creates the full grid
    x[["idist"]] = 1 - x[["dist"]] # assigns new attribute
    image(x["idist"]) # note the single [ for attribute selection

    # toy example:
    df = data.frame(z = c(1:6,NA,8,9),
        xc = c(1,1,1,2,2,2,3,3,3),
        yc = c(rep(c(0, 1.5, 3),3)))
    coordinates(df) = ~xc+yc
    gridded(df) = TRUE
    df = as(df, "SpatialGridDataFrame") # to full grid
    image(df["z"])
    # draw labels to verify:
    cc = coordinates(df)
    z=df[["z"]]
    zc=as.character(z)
    zc[is.na(zc)]="NA"
    text(cc[,1],cc[,2],zc)

    # the following is weird, but illustrates the concept of row/col selection:
    fullgrid(meuse.grid) = TRUE
    image(meuse.grid)
    image(meuse.grid[20:70, 10:70, "dist"], add = TRUE, col = bpy.colors())

[Package sp version 0.7-12 Index]