Learn R Programming

geometr (version 0.1.1)

setTable: Set the attribute table(s) of a spatial object.

Description

Set the attribute table(s) of a spatial object.

Usage

# S4 method for ANY
setTable(x)

# S4 method for geom setTable(x, table = NULL, slot = "feature")

# S4 method for Spatial setTable(x, table = NULL)

# S4 method for sf setTable(x, table = NULL)

# S4 method for sfc setTable(x, table = NULL)

# S4 method for ppp setTable(x, table = NULL)

# S4 method for RasterLayer setTable(x, table = NULL)

Arguments

x

the object to which to assign an attribute table.

table

[data.frame(.)] the attribute table.

slot

[character(1)] the slot (of geom) for which to set the attribute table, either "point", "feature" or "group".

Value

The object x with an updated attribute table.

Details

If table does not have columns in common with x, the new columns are simply bound to the original attribute table (if possible). If there are common columns, they are joined.

See Also

Other setters: setCRS, setHistory, setWindow

Examples

Run this code
# NOT RUN {
# set table of a geom
# individual attributes per point/line/polygon feature
getTable(gtGeoms$point)
newAttr <- setTable(x = gtGeoms$point,
                    slot = "point",
                    table = data.frame(attr = letters[c(1:12)]))
getTable(x = newAttr, slot = "point")

newAttr2 <- setTable(x = newAttr,
                     slot = "feature",
                     table = data.frame(gid = c(1:3), attr = letters[1:3]))
getTable(x = newAttr2, slot = "feature")
newAttr2

# set table of an Spatial object
spObj <- gtSP$SpatialPolygonsDataFrame

# ... with common columns
myAttributes <- data.frame(a = c(2, 1), attr = letters[1:2])
setTable(x = spObj, table = myAttributes)

# ... without common columns
setTable(x = spObj, table = myAttributes[2])

# set table of an sf
sfObj <- gtSF$polygon

# ... with common columns
myAttributes <- data.frame(a = c(2, 1), attr = letters[1:2])
setTable(x = sfObj, table = myAttributes)

# ... without common columns
setTable(x = sfObj, table = myAttributes[2])

# set table to an sfc (no join possible) and transform it to sf thereby
sfcObj = gtSF$polygon$geometry
setTable(x = sfcObj, table = myAttributes)

table <- data.frame(attr = LETTERS[1:15],
                    colour = topo.colors(15))
setTable(gtPPP, table = table)
# }

Run the code above in your browser using DataLab