Learn R Programming

sf (version 0.3-4)

sf: Create sf object

Description

Create sf, which extends data.frame-like objects with a simple feature list column

Usage

st_sf(..., agr = NA_agr_, row.names,
  stringsAsFactors = default.stringsAsFactors(), crs, precision)

# S3 method for sf [(x, i, j, ..., drop = FALSE, op = st_intersects)

Arguments

...
column elements to be binded into an sf object, one of them being of class sfc
agr
character vector; see details below.
row.names
row.names for the created sf object
stringsAsFactors
logical; logical: should character vectors be converted to factors? The `factory-fresh' default is TRUE, but this can be changed by setting options(stringsAsFactors = FALSE).
crs
coordinate reference system: integer with the epsg code, or character with proj4string
precision
numeric; see st_as_binary
x
object of class sf
i
record selection, see [.data.frame
j
variable selection, see [.data.frame
drop
whether to drop to simpler (e.g. vector) representation, see [.data.frame
op
function; geometrical binary predicate function to apply when i is a simple feature object

Details

agr, attribute-geometry-relationship, specifies for each non-geometry attribute column how it relates to the geometry, and can have one of following values: "constant", "aggregate", "identity". "constant" is used for attributes that are constant throughout the geometry (e.g. land use), "aggregate" where the attribute is an aggregate value over the geometry (e.g. population density or population count), "identity" when the attributes uniquely identifies the geometry of particular "thing", such as a building ID or a city name. The default value, NA_agr_, implies we don't know. "[.sf" will return a data.frame if the geometry column (of class sfc) is dropped, an sfc object if only the geometry column is selected, otherwise the behavior depending on drop is identical to that of [.data.frame.

Examples

Run this code
g = st_sfc(st_point(1:2))
st_sf(a=3,g)
st_sf(g, a=3)
st_sf(a=3, st_sfc(st_point(1:2))) # better to name it!
g = st_sfc(st_point(1:2), st_point(3:4))
s = st_sf(a=3:4, g)
s[1,]
class(s[1,])
s[,1]
class(s[,1])
s[,2]
class(s[,2])
g = st_sf(a=2:3, g)
pol = st_sfc(st_polygon(list(cbind(c(0,3,3,0,0),c(0,0,3,3,0)))))
h = st_sf(r = 5, pol)
g[h,]
h[g,]

Run the code above in your browser using DataLab