Hi,
Below is the code I use when I need to create sf class object for polygons (and other types)
d <- data.frame(matrix(, nrow=length(mydata), ncol=0))
st_geometry(d) <- mydata
my_sf <- st_as_sf(d)
I'm not sure if what I'm doing is the best approach, is there any helper function I'm not utilizing so that I can just pipe the sfc object and get a sf object immediately and add properties later on.
Suggestions are welcomed.
Why not use
st_sf(mydata)
?
omg it's that simple
I guess I'm having this question because I didn't see such conversion example in package vignette.
The closest example is
st_sf(a = 15:16, geometry = geom)
I'm closing this 'non-issue'
The above doesn't actually complete the job. If, like me, you are still having issues, try this:
library(sf)
library(tidyverse)
sf_object = sfc_object %>%
st_sf %>%
st_cast
This is particularly useful when performing unions and intersection before outputting in leaflet.
Most helpful comment
Why not use
?