Skip to content

Add function to save to geojson file #96

@mem48

Description

@mem48

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions