Learn R Programming

sf (version 0.1-1)

sf: create sf object

Description

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

Usage

st_sf(..., relation_to_geometry = NA_character_, row.names, stringsAsFactors = default.stringsAsFactors())
"["(x, i, j, drop)
p4s(obj)

Arguments

...
column elements to be binded into an sf object, one of them being of class sfc
relation_to_geometry
character vector; see details below.
row.names
row.names for the created sf object
stringsAsFactors
logical; see data.frame
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
obj
object of class sf or sfc

Details

relation_to_geometry specified for each non-geometry column how it relates to the geometry, and can have one of following values: "field", "lattice", "entity". "field" is used for attributes that are constant throughout the geometry (e.g. land use), "lattice" where the attribute is an aggregate value over the geometry (e.g. population density), "entity" when the attributes identifies the geometry of particular "thing", such as a building or a city. The default value, NA_character_, 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.

p4s returns the PROJ.4 string; if an EPSG code is available, it constructs it from this, otherwise, it takes the proj4string attribute, if none of these is available (both are missing-valued), NULL is returned.

Examples

Run this code
g = st_sfc(list(st_point(1:2)))
st_sf(a=3,g)
st_sf(g, a=3)
st_sf(a=3, st_sfc(list(st_point(1:2)))) # better to name it!
g = st_sfc(list(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])

Run the code above in your browser using DataLab