constructs sfg MULTIPOLYGON object
sfg_multipolygon(
obj,
x = NULL,
y = NULL,
z = NULL,
m = NULL,
polygon_id = NULL,
linestring_id = NULL,
close = TRUE
)
matrix or data.frame
x geometry column
y geometry column
z geometry column
m geometry column
column of ids for polygons (within the multipolygon)
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
sfg
object of MULTIPOLYGON geometry
df <- data.frame(
polygon_id = c(rep(1, 5), rep(2, 10))
, line_id = c(rep(1, 10), rep(2, 5))
, x = c(0,0,1,1,0,2,2,5,5,2,3,3,4,4,3)
, y = c(0,1,1,0,0,2,5,5,2,2,3,4,4,3,3)
, z = c(1)
, m = c(1)
)
m <- as.matrix( df )
sfg_multipolygon( df[, c("x","y") ] )
#> [[1]]
#> [[1]][[1]]
#> [,1] [,2]
#> [1,] 0 0
#> [2,] 0 1
#> [3,] 1 1
#> [4,] 1 0
#> [5,] 0 0
#> [6,] 2 2
#> [7,] 2 5
#> [8,] 5 5
#> [9,] 5 2
#> [10,] 2 2
#> [11,] 3 3
#> [12,] 3 4
#> [13,] 4 4
#> [14,] 4 3
#> [15,] 3 3
#> [16,] 0 0
#>
#>
#> attr(,"class")
#> [1] "XY" "MULTIPOLYGON" "sfg"
sfg_multipolygon(
df, x = "x", y = "y", polygon_id = "polygon_id", linestring_id = "line_id"
)
#> [[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,] 2 2
#> [2,] 2 5
#> [3,] 5 5
#> [4,] 5 2
#> [5,] 2 2
#>
#> [[2]][[2]]
#> [,1] [,2]
#> [1,] 3 3
#> [2,] 3 4
#> [3,] 4 4
#> [4,] 4 3
#> [5,] 3 3
#>
#>
#> attr(,"class")
#> [1] "XY" "MULTIPOLYGON" "sfg"
sfg_multipolygon(
df, x = "x", y = "y", z = "z", polygon_id = "polygon_id", linestring_id = "line_id"
)
#> [[1]]
#> [[1]][[1]]
#> [,1] [,2] [,3]
#> [1,] 0 0 1
#> [2,] 0 1 1
#> [3,] 1 1 1
#> [4,] 1 0 1
#> [5,] 0 0 1
#>
#>
#> [[2]]
#> [[2]][[1]]
#> [,1] [,2] [,3]
#> [1,] 2 2 1
#> [2,] 2 5 1
#> [3,] 5 5 1
#> [4,] 5 2 1
#> [5,] 2 2 1
#>
#> [[2]][[2]]
#> [,1] [,2] [,3]
#> [1,] 3 3 1
#> [2,] 3 4 1
#> [3,] 4 4 1
#> [4,] 4 3 1
#> [5,] 3 3 1
#>
#>
#> attr(,"class")
#> [1] "XYZ" "MULTIPOLYGON" "sfg"
sfg_multipolygon(
df, x = "x", y = "y", z = "z", m = "m", polygon_id = "polygon_id", linestring_id = "line_id"
)
#> [[1]]
#> [[1]][[1]]
#> [,1] [,2] [,3] [,4]
#> [1,] 0 0 1 1
#> [2,] 0 1 1 1
#> [3,] 1 1 1 1
#> [4,] 1 0 1 1
#> [5,] 0 0 1 1
#>
#>
#> [[2]]
#> [[2]][[1]]
#> [,1] [,2] [,3] [,4]
#> [1,] 2 2 1 1
#> [2,] 2 5 1 1
#> [3,] 5 5 1 1
#> [4,] 5 2 1 1
#> [5,] 2 2 1 1
#>
#> [[2]][[2]]
#> [,1] [,2] [,3] [,4]
#> [1,] 3 3 1 1
#> [2,] 3 4 1 1
#> [3,] 4 4 1 1
#> [4,] 4 3 1 1
#> [5,] 3 3 1 1
#>
#>
#> attr(,"class")
#> [1] "XYZM" "MULTIPOLYGON" "sfg"
sfg_multipolygon( m[, c("x","y") ] )
#> [[1]]
#> [[1]][[1]]
#> [,1] [,2]
#> [1,] 0 0
#> [2,] 0 1
#> [3,] 1 1
#> [4,] 1 0
#> [5,] 0 0
#> [6,] 2 2
#> [7,] 2 5
#> [8,] 5 5
#> [9,] 5 2
#> [10,] 2 2
#> [11,] 3 3
#> [12,] 3 4
#> [13,] 4 4
#> [14,] 4 3
#> [15,] 3 3
#> [16,] 0 0
#>
#>
#> attr(,"class")
#> [1] "XY" "MULTIPOLYGON" "sfg"
sfg_multipolygon(
m, x = "x", y = "y", polygon_id = "polygon_id", linestring_id = "line_id"
)
#> [[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,] 2 2
#> [2,] 2 5
#> [3,] 5 5
#> [4,] 5 2
#> [5,] 2 2
#>
#> [[2]][[2]]
#> [,1] [,2]
#> [1,] 3 3
#> [2,] 3 4
#> [3,] 4 4
#> [4,] 4 3
#> [5,] 3 3
#>
#>
#> attr(,"class")
#> [1] "XY" "MULTIPOLYGON" "sfg"
sfg_multipolygon(
m, x = "x", y = "y", z = "z", polygon_id = "polygon_id", linestring_id = "line_id"
)
#> [[1]]
#> [[1]][[1]]
#> [,1] [,2] [,3]
#> [1,] 0 0 1
#> [2,] 0 1 1
#> [3,] 1 1 1
#> [4,] 1 0 1
#> [5,] 0 0 1
#>
#>
#> [[2]]
#> [[2]][[1]]
#> [,1] [,2] [,3]
#> [1,] 2 2 1
#> [2,] 2 5 1
#> [3,] 5 5 1
#> [4,] 5 2 1
#> [5,] 2 2 1
#>
#> [[2]][[2]]
#> [,1] [,2] [,3]
#> [1,] 3 3 1
#> [2,] 3 4 1
#> [3,] 4 4 1
#> [4,] 4 3 1
#> [5,] 3 3 1
#>
#>
#> attr(,"class")
#> [1] "XYZ" "MULTIPOLYGON" "sfg"
sfg_multipolygon(
m, x = "x", y = "y", z = "z", m = "m", polygon_id = "polygon_id", linestring_id = "line_id"
)
#> [[1]]
#> [[1]][[1]]
#> [,1] [,2] [,3] [,4]
#> [1,] 0 0 1 1
#> [2,] 0 1 1 1
#> [3,] 1 1 1 1
#> [4,] 1 0 1 1
#> [5,] 0 0 1 1
#>
#>
#> [[2]]
#> [[2]][[1]]
#> [,1] [,2] [,3] [,4]
#> [1,] 2 2 1 1
#> [2,] 2 5 1 1
#> [3,] 5 5 1 1
#> [4,] 5 2 1 1
#> [5,] 2 2 1 1
#>
#> [[2]][[2]]
#> [,1] [,2] [,3] [,4]
#> [1,] 3 3 1 1
#> [2,] 3 4 1 1
#> [3,] 4 4 1 1
#> [4,] 4 3 1 1
#> [5,] 3 3 1 1
#>
#>
#> attr(,"class")
#> [1] "XYZM" "MULTIPOLYGON" "sfg"