Create simple feature from a numeric vector, matrix or list
st_point(x = c(NA_real_, NA_real_), dim = "XYZ") st_multipoint(x = matrix(numeric(0), 0, 2), dim = "XYZ") st_linestring(x = matrix(numeric(0), 0, 2), dim = "XYZ") st_polygon(x = list(), dim = if (length(x)) "XYZ" else "XY") st_multilinestring(x = list(), dim = if (length(x)) "XYZ" else "XY") st_multipolygon(x = list(), dim = if (length(x)) "XYZ" else "XY") st_geometrycollection(x = list(), dims = "XY") # S3 method for sfg print(x, ..., width = 0) # S3 method for sfg head(x, n = 10L, ...) # S3 method for sfg format(x, ..., width = 30) # S3 method for sfg c(..., recursive = FALSE, flatten = TRUE) # S3 method for sfg as.matrix(x, ...)
x | for |
---|---|
dim | character, indicating dimensions: "XY", "XYZ", "XYM", or "XYZM"; only really needed for three-dimensional points (which can be either XYZ or XYM) or empty geometries; see details |
dims | character; specify dimensionality in case of an empty (NULL) geometrycollection, in which case |
... | objects to be pasted together into a single simple feature |
width | integer; number of characters to be printed (max 30; 0 means print everything) |
n | integer; number of elements to be selected |
recursive | logical; ignored |
flatten | logical; if TRUE, try to simplify results; if FALSE, return geometrycollection containing all objects |
object of the same nature as x
, but with appropriate class attribute set
as.matrix returns the set of points that form a geometry as a single matrix, where each point is a row; use unlist(x, recursive = FALSE)
to get sets of matrices.
"XYZ" refers to coordinates where the third dimension represents altitude, "XYM" refers to three-dimensional coordinates where the third dimension refers to something else ("M" for measure); checking of the sanity of x
may be only partial.
When flatten=TRUE
, this method may merge points into a multipoint structure, and may not preserve order, and hence cannot be reverted. When given fish, it returns fish soup.
#>class(p1)#> [1] "XY" "POINT" "sfg"st_bbox(p1)#> xmin ymin xmax ymax #> 1 2 1 2#>class(p2)#> [1] "XYZ" "POINT" "sfg"#>#>#>(mp3 = st_multipoint(pts, "XYM"))#>#>#>#>(ls3 = st_linestring(pts, "XYM"))#>#>outer = matrix(c(0,0,10,0,10,10,0,10,0,0),ncol=2, byrow=TRUE) hole1 = matrix(c(1,1,1,2,2,2,2,1,1,1),ncol=2, byrow=TRUE) hole2 = matrix(c(5,5,5,6,6,6,6,5,5,5),ncol=2, byrow=TRUE) pts = list(outer, hole1, hole2) (ml1 = st_multilinestring(pts))#>#>(ml3 = st_multilinestring(pts3, "XYM"))#>#>outer = matrix(c(0,0,10,0,10,10,0,10,0,0),ncol=2, byrow=TRUE) hole1 = matrix(c(1,1,1,2,2,2,2,1,1,1),ncol=2, byrow=TRUE) hole2 = matrix(c(5,5,5,6,6,6,6,5,5,5),ncol=2, byrow=TRUE) pts = list(outer, hole1, hole2) (pl1 = st_polygon(pts))#>#>(pl3 = st_polygon(pts3, "XYM"))#>#>pol1 = list(outer, hole1, hole2) pol2 = list(outer + 12, hole1 + 12) pol3 = list(outer + 24) mp = list(pol1,pol2,pol3) (mp1 = st_multipolygon(mp))#>#>(mp3 = st_multipolygon(pts3, "XYM"))#>#>#>st_geometrycollection() # empty geometry#>#>#>#>#>#>#>#>#>c(st_geometrycollection(list(st_point(1:2), st_linestring(matrix(1:6,3)))), st_geometrycollection(list(st_multilinestring(list(matrix(11:16,3))))))#>c(st_geometrycollection(list(st_point(1:2), st_linestring(matrix(1:6,3)))), st_multilinestring(list(matrix(11:16,3))), st_point(5:6), st_geometrycollection(list(st_point(10:11))))#>