Read geojson or other formats from a local file or a URL

Description

Read geojson or other formats from a local file or a URL

Usage

1
geojson_read(x, method = "web", parse = FALSE, what = "list", ...)

Arguments

x

(character) Path to a local file or a URL.

method

(character) One of "web" (default) or "local". Matches on partial strings.

parse

(logical) To parse geojson to data.frame like structures if possible. Default: FALSE

what

(character) What to return. One of "list" or "sp" (for Spatial class). Default: "list". If "sp" chosen, forced to method="local".

...

Additional parameters passed to readOGR

Details

Uses file_to_geojson internally to give back geojson, and other helper functions when returning spatial classes.

This function supports various geospatial file formats from a URL, as well as local kml, shp, and geojson file formats.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
## Not run: 
# From a file
file <- system.file("examples", "california.geojson", package = "geojsonio")
out <- geojson_read(file)

# From a URL
url <- "https://raw.githubusercontent.com/glynnbird/usstatesgeojson/master/california.geojson"
geojson_read(url, method = "local")

# Use as.location first if you want
geojson_read(as.location(file))

# use jsonlite to parse to data.frame structures where possible
geojson_read(url, method = "local", parse = TRUE)

# output a SpatialClass object
## read kml
file <- system.file("examples", "norway_maple.kml", package = "geojsonio")
geojson_read(as.location(file), what = "sp")
## read geojson
file <- system.file("examples", "california.geojson", package = "geojsonio")
geojson_read(as.location(file), what = "sp")
## read geojson from a url
url <- "https://raw.githubusercontent.com/glynnbird/usstatesgeojson/master/california.geojson"
geojson_read(url, what = "sp")
## read from a shape file
file <- system.file("examples", "bison.zip", package = "geojsonio")
dir <- tempdir()
unzip(file, exdir = dir)
shpfile <- list.files(dir, pattern = ".shp", full.names = TRUE)
geojson_read(shpfile, what = "sp")

# doesn't work right now
## file <- system.file("examples", "feature_collection.geojson", package = "geojsonio")
## geojson_read(file, what = "sp")

## End(Not run)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.