Skip to content

Instantly share code, notes, and snippets.

@scbrown86
Created June 11, 2018 11:58
Show Gist options
  • Save scbrown86/ccf754217c9b4968c81241e305659f73 to your computer and use it in GitHub Desktop.
Save scbrown86/ccf754217c9b4968c81241e305659f73 to your computer and use it in GitHub Desktop.
geoJSON to multilayer geopackage R
# Convert a GeoJSON object to a geopackage
# Add a second geoJSON object in as a second layer
# https://gis.stackexchange.com/q/223240/24249
library(rgdal)
library(sf)
# Here I open a shapefile, but readOGR can be used to read geoJSON files
nc <- st_as_sf(readOGR(system.file("shape/nc.shp", package = "sf")))
storms <- st_as_sf(readOGR(system.file("shape/storms_xyz.shp", package = "sf")))
# Export, and add an extra layer
st_write(nc, "./export_geopackage.gpkg", "nc_state")
st_write(storms, "./export_geopackage.gpkg", "storms_state", update = TRUE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment