Free Access Week - Data Engineering + BI
Data Engineering and BI courses are free this week!
Free Access Week - Jun 2-8

sfheaders (version 0.4.0)

sf_cast: sf cast

Description

convert the input sf to a different geometry

Usage

sf_cast(sf, to, close = TRUE)

Arguments

sf

object to convert

to

the geometry to convert to.

close

logical indicating if polygons should be closed

Examples

Run this code

df <- data.frame(
 id1 = c(1,1,1,1,1,1,1,1,2,2,2,2)
 , id2 = c(1,1,1,1,2,2,2,2,1,1,1,1)
 , x = c(0,0,1,1,1,1,2,2,3,4,4,3)
 , y = c(0,1,1,0,1,2,2,1,3,3,4,4)
)

pt <- sf_point(obj = df, x = "x", y = "y", z = "id1")
mpt <- sf_multipoint(obj = df, x = "x", y = "y", multipoint_id = "id1")
ls <- sf_linestring(obj = df, x = "x", y = "y", linestring_id = "id1")
mls <- sf_multilinestring(obj = df, x = "x", y = "y", multilinestring_id = "id1")
p <- sf_polygon(
  obj = df
  , x = "x"
  , y = "y"
  , polygon_id = "id1"
  , linestring_id = "id2"
  , close = FALSE
  )
mp <- sf_multipolygon(
  obj = df
  , x = "x"
  , y = "y"
  , multipolygon_id = "id1"
  , linestring_id = "id2"
  , close = FALSE
  )

sf_cast( pt, "LINESTRING" )
sf_cast( mpt, "POLYGON" )
sf_cast( ls, "POINT" )
sf_cast( mls, "MULTIPOLYGON" )
sf_cast( p, "POINT" )
sf_cast( mp, "LINESTRING" )


Run the code above in your browser using DataLab