5.11 Type Transformations
= st_multipoint(matrix(c(1, 3, 5, 1, 3, 1), ncol = 2))
multipoint
|> ggplot() + geom_sf() + theme_minimal() +
multipoint labs(title = "Multipoint")
= st_cast(multipoint, "LINESTRING")
linestring
|> ggplot() + geom_sf() + theme_minimal() +
linestring labs(title = "Linestring")
= st_cast(multipoint, "POLYGON")
polyg
|> ggplot() + geom_sf() + theme_minimal() +
polyg labs(title = "Polygon")
= st_cast(linestring, "MULTIPOINT")
multipoint_2 = st_cast(polyg, "MULTIPOINT")
multipoint_3 all.equal(multipoint, multipoint_2)
## [1] TRUE
all.equal(multipoint, multipoint_3)
## [1] TRUE

allowed typecasting
5.11.1 New Objects
= list(matrix(c(1, 4, 5, 3), ncol = 2),
multilinestring_list matrix(c(4, 4, 4, 1), ncol = 2),
matrix(c(2, 4, 2, 2), ncol = 2))
= st_multilinestring(multilinestring_list)
multilinestring = st_sf(geom = st_sfc(multilinestring))
multilinestring_sf multilinestring_sf
## Simple feature collection with 1 feature and 0 fields
## Geometry type: MULTILINESTRING
## Dimension: XY
## Bounding box: xmin: 1 ymin: 1 xmax: 4 ymax: 5
## CRS: NA
## geom
## 1 MULTILINESTRING ((1 5, 4 3)...
|> ggplot() + geom_sf() + theme_minimal() +
multilinestring_sf labs(title = "Multilinestring")
= st_cast(multilinestring_sf, "LINESTRING")
linestring_sf2 linestring_sf2
## Simple feature collection with 3 features and 0 fields
## Geometry type: LINESTRING
## Dimension: XY
## Bounding box: xmin: 1 ymin: 1 xmax: 4 ymax: 5
## CRS: NA
## geom
## 1 LINESTRING (1 5, 4 3)
## 2 LINESTRING (4 4, 4 1)
## 3 LINESTRING (2 2, 4 2)