constructs an sf of MULTIPOLYGON objects
sf_multipolygon(
obj = NULL,
x = NULL,
y = NULL,
z = NULL,
m = NULL,
multipolygon_id = NULL,
polygon_id = NULL,
linestring_id = NULL,
close = TRUE,
keep = FALSE,
list_columns = NULL
)
sorted matrix or data.frame
x geometry column
y geometry column
z geometry column
m geometry column
column of ids for multipolygons
column of ids for polygons
column of ids for lines (within polygons)
logical indicating whether polygons should be closed. If TRUE
,
all polygons will be checked and force closed if possible
logical indicating if the non-geometry and non-id columns should be kept. if TRUE you must supply the geometry and id columns, and only the first row of each geometry is kept. See Keeping Properties.
vector of column names to turn into a list.
sf
object of MULTIPOLYGON geometries
sfheaders functions do not perform any validity checks on the geometries. Nor do they set Coordinate Reference Systems, EPSG, PROJ4 or precision attributes.
The data.frame and matrices you send into the sfheader functions must be ordered.
Setting keep = TRUE
will retain any columns not specified as a
coordinate (x, y, z, m) or an id (e.g., linestring_id, polygon_id) of the input obj
.
You can use list_columns
to specify which of the properties will be turned into
a list, thus keeping all the values in the column. For columns not specified in list_columns
,
only the first row of the column is kept
The sf_*
functions assume the input obj
is a long data.frame / matrix,
where any properties are repeated down the table for the same geometry.
m <- matrix(c(0,0,0,0,1,0,0,1,1,0,0,1,0,0,0), ncol = 3, byrow = TRUE )
sf_multipolygon( m )
#> id geometry
#> 1 1 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0
df <- data.frame(
id = c(1,1,1,1,1)
, x = c(0,0,1,1,0)
, y = c(0,1,1,0,0)
)
sf_multipolygon( df, x = "x", y = "y" )
#> id geometry
#> 1 1 0, 0, 1, 1, 0, 0, 1, 1, 0, 0
df <- data.frame(
id = c(1,1,1,1,1,2,2,2,2,2)
, x = c(0,0,1,1,0,1,1,2,2,1)
, y = c(0,1,1,0,0,1,2,2,1,1)
)
sf_multipolygon( df, multipolygon_id = "id", polygon_id = "id", linestring_id = "id")
#> id geometry
#> 1 1 0, 0, 1, 1, 0, 0, 1, 1, 0, 0
#> 2 2 1, 1, 2, 2, 1, 1, 2, 2, 1, 1
df <- data.frame(
id1 = c(1,1,1,1,1,1,1,1,1,1)
, id2 = c(1,1,1,1,1,2,2,2,2,2)
, x = c(0,0,1,1,0,1,1,2,2,1)
, y = c(0,1,1,0,0,1,2,2,1,1)
)
sf_multipolygon( df, multipolygon_id = "id1", polygon_id = "id2")
#> id1 geometry
#> 1 1 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1
df <- data.frame(
id1 = c(1,1,1,1,1,1,1,1,1,1,2,2,2,2,2)
, id2 = c(1,1,1,1,1,2,2,2,2,2,1,1,1,1,1)
, x = c(0,0,1,1,0,1,1,2,2,1,3,3,4,4,3)
, y = c(0,1,1,0,0,1,2,2,1,1,3,4,4,3,3)
)
sf_multipolygon( df, multipolygon_id = "id1", polygon_id = "id2")
#> id1 geometry
#> 1 1 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1
#> 2 2 3, 3, 4, 4, 3, 3, 4, 4, 3, 3
df <- data.frame(
id1 = c(1,1,1,1,1,2,2,2,2,2)
, id2 = c(1,1,1,1,1,1,1,1,1,1)
, x = c(0,0,1,1,0,1,1,2,2,1)
, y = c(0,1,1,0,0,1,2,2,1,1)
)
sf_multipolygon( df, multipolygon_id = "id1", polygon_id = "id2" )
#> id1 geometry
#> 1 1 0, 0, 1, 1, 0, 0, 1, 1, 0, 0
#> 2 2 1, 1, 2, 2, 1, 1, 2, 2, 1, 1
sf_multipolygon( df, polygon_id = "id1", linestring_id = "id2" )
#> id geometry
#> 1 1 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1
sf_multipolygon( df, x = "x", y = "y", polygon_id = "id1")
#> id geometry
#> 1 1 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1
sf_multipolygon( df, x = "x", y = "y", polygon_id = "id1", linestring_id = "id2")
#> id geometry
#> 1 1 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1
sf_multipolygon( df, x = "x", y = "y", linestring_id = "id1")
#> id geometry
#> 1 1 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1
sf_multipolygon( df, x = "x", y = "y", linestring_id = "id2")
#> id geometry
#> 1 1 0, 0, 1, 1, 0, 1, 1, 2, 2, 1, 0, 0, 1, 1, 0, 0, 1, 2, 2, 1, 1, 0
df <- data.frame(
id1 = c('a','a','a','a','a','b','b','b','b','b')
, id2 = c(1,1,1,1,1,1,1,1,1,1)
, x = c(0,0,1,1,0,1,1,2,2,1)
, y = c(0,1,1,0,0,1,2,2,1,1)
)
sf_multipolygon( df, x = "x", y = "y", polygon_id = "id1")
#> id geometry
#> 1 1 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1