geojson_sfc: Geojson to sfc

View source: R/geojson_sf.R

geojson_sfcR Documentation

Geojson to sfc

Description

Extracts geometries from GeoJSON and returns an 'sfc' object

Usage

geojson_sfc(
  geojson,
  expand_geometries = FALSE,
  input = NULL,
  wkt = NULL,
  crs = NULL,
  proj4string = NULL,
  buffer_size = 1024
)

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

input

user input for coordinate reference system object

wkt

well-known text for coordinate reference system object

crs

deprecated. coordinate reference system. See Details

proj4string

deprecated. proj4string. See Details

buffer_size

size of buffer used when reading a file from disk. Defaults 1024

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.

Geojson specification RFC7946 https://tools.ietf.org/html/rfc7946#page-12 says all CRS should be the World Geodetic System 1984 (WGS 84) [WGS84] datum, with longitude and latitude units of decimal degrees. This is equivalent to the coordinate reference system identified by the Open Geospatial Consortium (OGC) URN urn:ogc:def:crs:OGC::CRS84

geojson_sfc and geojson_sf automatically set the CRS to WGS 84. The fields input and wkt let you to overwrite the defaults.

Examples


## character string of GeoJSON

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

geojson <- '[
  { "type":"Point","coordinates":[0,0]},
  {"type":"LineString","coordinates":[[0,0],[1,1]]}
  ]'
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)

## End(Not run)


geojsonsf documentation built on May 31, 2022, 1:05 a.m.