Unless I've missed it, why there is no easy way to save an sf object to disk as a geojson file?
I created a little test function
write_geojson <- function(x, path){
x <- geojsonsf::sf_geojson(x)
filecon <- file(path)
writeLines(x, filecon)
close(filecon)
}
And it was 7x faster than sf::st_write. The output wasn't identical as sf writes each feature to a new line in the file. But I was able to st_read it back in and it was identical to the original sf data frame.
I'm sure this function needs some refining, but it would be a really useful feature for geojsonsf
Thanks.
Unless I've missed it, why there is no easy way to save an sf object to disk as a geojson file?
I created a little test function
And it was 7x faster than
sf::st_write. The output wasn't identical assfwrites each feature to a new line in the file. But I was able tost_readit back in and it was identical to the original sf data frame.I'm sure this function needs some refining, but it would be a really useful feature for
geojsonsfThanks.