I'm trying to extract a list of lists that hold coordinate information into a sf dataframe.
Here is the list
feature <- list(type = "Feature", properties = list(`_leaflet_id` = 26065L,
feature_type = "polyline"), geometry = list(type = "LineString",
coordinates = list(list(-74.210091, 40.382121), list(-73.942375,
40.661889))))
and I would like to convert it to a sf dataframe of 3 columns (leaflet_id, feature_type, geometry)
I've tried using purrr::flatten_dfr(feature) but get the error: argument 1 must have names.
I've reviewed other SO posts like below which seem promising but wasn't working.
Thanks
Your
feature
list looks like the result of readinggeojson
using something likejsonlite::fromJSON()
.If you read the
geojson
directly usingsf::st_read()
you'll get yoursf
object.To fix your code as-is, you can do