Learn R Programming

geojsonsf (version 1.1)

geojson_sfc: Geojson to sfc

Description

Extracts geometries from GeoJSON and returns an `sfc` object

Usage

geojson_sfc(geojson, expand_geometries = FALSE)

Arguments

geojson

string or vector of GeoJSON, or a URL or file pointing to a geojson file

expand_geometries

logical indicating whether to unnest GEOMETRYCOLLECTION rows. see details

Details

specifying expand_geometries = TRUE will expand individual GEOMETRYCOLLECTION geometries to their own row in the resulting `sf` object. If the geometries are part of a Feature (i.e., with properties), the properties will be repeated on each row.

The GEOMETRYCOLLECTION information is not kept when using expand_geometries = TRUE. Therefore, it is not possible to reconstruct the GEOMETRYCOLLECTION after unnesting it.

Examples

Run this code
# NOT RUN {
## character string of GeoJSON

## load 'sf' for print methods
# library(sf)
geojson <- '{ "type" : "Point", "coordinates" : [0, 0] }'
geojson_sfc(geojson)

# }
# NOT RUN {
## GeoJSON at a url
myurl <- "http://eric.clst.org/assets/wiki/uploads/Stuff/gz_2010_us_050_00_500k.json"
sf <- geojson_sfc(myurl)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab