constructs an sfc of MULTIPOLYGON objects
sfc_multipolygon(
obj = NULL,
x = NULL,
y = NULL,
z = NULL,
m = NULL,
multipolygon_id = NULL,
polygon_id = NULL,
linestring_id = NULL,
close = TRUE
)
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
sfc
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.
m <- matrix(c(0,0,0,0,1,0,0,1,1,0,0,1,0,0,0), ncol = 3, byrow = TRUE )
sfc_multipolygon( m )
#> [[1]]
#> [[1]]
#> [[1]][[1]]
#> [,1] [,2] [,3]
#> [1,] 0 0 0
#> [2,] 0 1 0
#> [3,] 0 1 1
#> [4,] 0 0 1
#> [5,] 0 0 0
#>
#>
#> attr(,"class")
#> [1] "XYZ" "MULTIPOLYGON" "sfg"
#>
#> attr(,"n_empty")
#> [1] 0
#> attr(,"crs")
#> $input
#> [1] NA
#>
#> $wkt
#> [1] NA
#>
#> attr(,"class")
#> [1] "crs"
#> attr(,"class")
#> [1] "sfc_MULTIPOLYGON" "sfc"
#> attr(,"precision")
#> [1] 0
#> attr(,"bbox")
#> xmin ymin xmax ymax
#> 0 0 0 1
#> attr(,"class")
#> [1] "bbox"
#> attr(,"z_range")
#> zmin zmax
#> 0 1
#> attr(,"class")
#> [1] "z_range"
df <- data.frame(
id = c(1,1,1,1,1)
, x = c(0,0,1,1,0)
, y = c(0,1,1,0,0)
)
sfc_multipolygon( df, x = "x", y = "y" )
#> [[1]]
#> [[1]]
#> [[1]][[1]]
#> [,1] [,2]
#> [1,] 0 0
#> [2,] 0 1
#> [3,] 1 1
#> [4,] 1 0
#> [5,] 0 0
#>
#>
#> attr(,"class")
#> [1] "XY" "MULTIPOLYGON" "sfg"
#>
#> attr(,"n_empty")
#> [1] 0
#> attr(,"crs")
#> $input
#> [1] NA
#>
#> $wkt
#> [1] NA
#>
#> attr(,"class")
#> [1] "crs"
#> attr(,"class")
#> [1] "sfc_MULTIPOLYGON" "sfc"
#> attr(,"precision")
#> [1] 0
#> attr(,"bbox")
#> xmin ymin xmax ymax
#> 0 0 1 1
#> attr(,"class")
#> [1] "bbox"
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)
)
sfc_multipolygon( df, multipolygon_id = "id", polygon_id = "id", linestring_id = "id")
#> [[1]]
#> [[1]]
#> [[1]][[1]]
#> [,1] [,2]
#> [1,] 0 0
#> [2,] 0 1
#> [3,] 1 1
#> [4,] 1 0
#> [5,] 0 0
#>
#>
#> attr(,"class")
#> [1] "XY" "MULTIPOLYGON" "sfg"
#>
#> [[2]]
#> [[1]]
#> [[1]][[1]]
#> [,1] [,2]
#> [1,] 1 1
#> [2,] 1 2
#> [3,] 2 2
#> [4,] 2 1
#> [5,] 1 1
#>
#>
#> attr(,"class")
#> [1] "XY" "MULTIPOLYGON" "sfg"
#>
#> attr(,"n_empty")
#> [1] 0
#> attr(,"crs")
#> $input
#> [1] NA
#>
#> $wkt
#> [1] NA
#>
#> attr(,"class")
#> [1] "crs"
#> attr(,"class")
#> [1] "sfc_MULTIPOLYGON" "sfc"
#> attr(,"precision")
#> [1] 0
#> attr(,"bbox")
#> xmin ymin xmax ymax
#> 0 0 2 2
#> attr(,"class")
#> [1] "bbox"
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)
)
sfc_multipolygon( df, multipolygon_id = "id1", polygon_id = "id2")
#> [[1]]
#> [[1]]
#> [[1]][[1]]
#> [,1] [,2]
#> [1,] 0 0
#> [2,] 0 1
#> [3,] 1 1
#> [4,] 1 0
#> [5,] 0 0
#>
#>
#> [[2]]
#> [[2]][[1]]
#> [,1] [,2]
#> [1,] 1 1
#> [2,] 1 2
#> [3,] 2 2
#> [4,] 2 1
#> [5,] 1 1
#>
#>
#> attr(,"class")
#> [1] "XY" "MULTIPOLYGON" "sfg"
#>
#> attr(,"n_empty")
#> [1] 0
#> attr(,"crs")
#> $input
#> [1] NA
#>
#> $wkt
#> [1] NA
#>
#> attr(,"class")
#> [1] "crs"
#> attr(,"class")
#> [1] "sfc_MULTIPOLYGON" "sfc"
#> attr(,"precision")
#> [1] 0
#> attr(,"bbox")
#> xmin ymin xmax ymax
#> 0 0 2 2
#> attr(,"class")
#> [1] "bbox"
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)
)
sfc_multipolygon( df, multipolygon_id = "id1", polygon_id = "id2")
#> [[1]]
#> [[1]]
#> [[1]][[1]]
#> [,1] [,2]
#> [1,] 0 0
#> [2,] 0 1
#> [3,] 1 1
#> [4,] 1 0
#> [5,] 0 0
#>
#>
#> [[2]]
#> [[2]][[1]]
#> [,1] [,2]
#> [1,] 1 1
#> [2,] 1 2
#> [3,] 2 2
#> [4,] 2 1
#> [5,] 1 1
#>
#>
#> attr(,"class")
#> [1] "XY" "MULTIPOLYGON" "sfg"
#>
#> [[2]]
#> [[1]]
#> [[1]][[1]]
#> [,1] [,2]
#> [1,] 3 3
#> [2,] 3 4
#> [3,] 4 4
#> [4,] 4 3
#> [5,] 3 3
#>
#>
#> attr(,"class")
#> [1] "XY" "MULTIPOLYGON" "sfg"
#>
#> attr(,"n_empty")
#> [1] 0
#> attr(,"crs")
#> $input
#> [1] NA
#>
#> $wkt
#> [1] NA
#>
#> attr(,"class")
#> [1] "crs"
#> attr(,"class")
#> [1] "sfc_MULTIPOLYGON" "sfc"
#> attr(,"precision")
#> [1] 0
#> attr(,"bbox")
#> xmin ymin xmax ymax
#> 0 0 4 4
#> attr(,"class")
#> [1] "bbox"
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)
)
sfc_multipolygon( df, multipolygon_id = "id1", polygon_id = "id2" )
#> [[1]]
#> [[1]]
#> [[1]][[1]]
#> [,1] [,2]
#> [1,] 0 0
#> [2,] 0 1
#> [3,] 1 1
#> [4,] 1 0
#> [5,] 0 0
#>
#>
#> attr(,"class")
#> [1] "XY" "MULTIPOLYGON" "sfg"
#>
#> [[2]]
#> [[1]]
#> [[1]][[1]]
#> [,1] [,2]
#> [1,] 1 1
#> [2,] 1 2
#> [3,] 2 2
#> [4,] 2 1
#> [5,] 1 1
#>
#>
#> attr(,"class")
#> [1] "XY" "MULTIPOLYGON" "sfg"
#>
#> attr(,"n_empty")
#> [1] 0
#> attr(,"crs")
#> $input
#> [1] NA
#>
#> $wkt
#> [1] NA
#>
#> attr(,"class")
#> [1] "crs"
#> attr(,"class")
#> [1] "sfc_MULTIPOLYGON" "sfc"
#> attr(,"precision")
#> [1] 0
#> attr(,"bbox")
#> xmin ymin xmax ymax
#> 0 0 2 2
#> attr(,"class")
#> [1] "bbox"
sfc_multipolygon( df, polygon_id = "id1", linestring_id = "id2" )
#> [[1]]
#> [[1]]
#> [[1]][[1]]
#> [,1] [,2]
#> [1,] 0 0
#> [2,] 0 1
#> [3,] 1 1
#> [4,] 1 0
#> [5,] 0 0
#>
#>
#> [[2]]
#> [[2]][[1]]
#> [,1] [,2]
#> [1,] 1 1
#> [2,] 1 2
#> [3,] 2 2
#> [4,] 2 1
#> [5,] 1 1
#>
#>
#> attr(,"class")
#> [1] "XY" "MULTIPOLYGON" "sfg"
#>
#> attr(,"n_empty")
#> [1] 0
#> attr(,"crs")
#> $input
#> [1] NA
#>
#> $wkt
#> [1] NA
#>
#> attr(,"class")
#> [1] "crs"
#> attr(,"class")
#> [1] "sfc_MULTIPOLYGON" "sfc"
#> attr(,"precision")
#> [1] 0
#> attr(,"bbox")
#> xmin ymin xmax ymax
#> 0 0 2 2
#> attr(,"class")
#> [1] "bbox"
sfc_multipolygon( df, x = "x", y = "y", polygon_id = "id1")
#> [[1]]
#> [[1]]
#> [[1]][[1]]
#> [,1] [,2]
#> [1,] 0 0
#> [2,] 0 1
#> [3,] 1 1
#> [4,] 1 0
#> [5,] 0 0
#>
#>
#> [[2]]
#> [[2]][[1]]
#> [,1] [,2]
#> [1,] 1 1
#> [2,] 1 2
#> [3,] 2 2
#> [4,] 2 1
#> [5,] 1 1
#>
#>
#> attr(,"class")
#> [1] "XY" "MULTIPOLYGON" "sfg"
#>
#> attr(,"n_empty")
#> [1] 0
#> attr(,"crs")
#> $input
#> [1] NA
#>
#> $wkt
#> [1] NA
#>
#> attr(,"class")
#> [1] "crs"
#> attr(,"class")
#> [1] "sfc_MULTIPOLYGON" "sfc"
#> attr(,"precision")
#> [1] 0
#> attr(,"bbox")
#> xmin ymin xmax ymax
#> 0 0 2 2
#> attr(,"class")
#> [1] "bbox"
sfc_multipolygon( df, x = "x", y = "y", polygon_id = "id1", linestring_id = "id2")
#> [[1]]
#> [[1]]
#> [[1]][[1]]
#> [,1] [,2]
#> [1,] 0 0
#> [2,] 0 1
#> [3,] 1 1
#> [4,] 1 0
#> [5,] 0 0
#>
#>
#> [[2]]
#> [[2]][[1]]
#> [,1] [,2]
#> [1,] 1 1
#> [2,] 1 2
#> [3,] 2 2
#> [4,] 2 1
#> [5,] 1 1
#>
#>
#> attr(,"class")
#> [1] "XY" "MULTIPOLYGON" "sfg"
#>
#> attr(,"n_empty")
#> [1] 0
#> attr(,"crs")
#> $input
#> [1] NA
#>
#> $wkt
#> [1] NA
#>
#> attr(,"class")
#> [1] "crs"
#> attr(,"class")
#> [1] "sfc_MULTIPOLYGON" "sfc"
#> attr(,"precision")
#> [1] 0
#> attr(,"bbox")
#> xmin ymin xmax ymax
#> 0 0 2 2
#> attr(,"class")
#> [1] "bbox"
sfc_multipolygon( df, x = "x", y = "y", linestring_id = "id1")
#> [[1]]
#> [[1]]
#> [[1]][[1]]
#> [,1] [,2]
#> [1,] 0 0
#> [2,] 0 1
#> [3,] 1 1
#> [4,] 1 0
#> [5,] 0 0
#>
#> [[1]][[2]]
#> [,1] [,2]
#> [1,] 1 1
#> [2,] 1 2
#> [3,] 2 2
#> [4,] 2 1
#> [5,] 1 1
#>
#>
#> attr(,"class")
#> [1] "XY" "MULTIPOLYGON" "sfg"
#>
#> attr(,"n_empty")
#> [1] 0
#> attr(,"crs")
#> $input
#> [1] NA
#>
#> $wkt
#> [1] NA
#>
#> attr(,"class")
#> [1] "crs"
#> attr(,"class")
#> [1] "sfc_MULTIPOLYGON" "sfc"
#> attr(,"precision")
#> [1] 0
#> attr(,"bbox")
#> xmin ymin xmax ymax
#> 0 0 2 2
#> attr(,"class")
#> [1] "bbox"
sfc_multipolygon( df, x = "x", y = "y", linestring_id = "id2")
#> [[1]]
#> [[1]]
#> [[1]][[1]]
#> [,1] [,2]
#> [1,] 0 0
#> [2,] 0 1
#> [3,] 1 1
#> [4,] 1 0
#> [5,] 0 0
#> [6,] 1 1
#> [7,] 1 2
#> [8,] 2 2
#> [9,] 2 1
#> [10,] 1 1
#> [11,] 0 0
#>
#>
#> attr(,"class")
#> [1] "XY" "MULTIPOLYGON" "sfg"
#>
#> attr(,"n_empty")
#> [1] 0
#> attr(,"crs")
#> $input
#> [1] NA
#>
#> $wkt
#> [1] NA
#>
#> attr(,"class")
#> [1] "crs"
#> attr(,"class")
#> [1] "sfc_MULTIPOLYGON" "sfc"
#> attr(,"precision")
#> [1] 0
#> attr(,"bbox")
#> xmin ymin xmax ymax
#> 0 0 2 2
#> attr(,"class")
#> [1] "bbox"
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)
)
sfc_multipolygon( df, x = "x", y = "y", polygon_id = "id1")
#> [[1]]
#> [[1]]
#> [[1]][[1]]
#> [,1] [,2]
#> [1,] 0 0
#> [2,] 0 1
#> [3,] 1 1
#> [4,] 1 0
#> [5,] 0 0
#>
#>
#> [[2]]
#> [[2]][[1]]
#> [,1] [,2]
#> [1,] 1 1
#> [2,] 1 2
#> [3,] 2 2
#> [4,] 2 1
#> [5,] 1 1
#>
#>
#> attr(,"class")
#> [1] "XY" "MULTIPOLYGON" "sfg"
#>
#> attr(,"n_empty")
#> [1] 0
#> attr(,"crs")
#> $input
#> [1] NA
#>
#> $wkt
#> [1] NA
#>
#> attr(,"class")
#> [1] "crs"
#> attr(,"class")
#> [1] "sfc_MULTIPOLYGON" "sfc"
#> attr(,"precision")
#> [1] 0
#> attr(,"bbox")
#> xmin ymin xmax ymax
#> 0 0 2 2
#> attr(,"class")
#> [1] "bbox"