geojson_hint: Validate GeoJSON using geojsonhint Javascript library

Description Usage Arguments Details Value Examples

View source: R/geojsonhint.R

Description

Validate GeoJSON using geojsonhint Javascript library

Usage

1
geojson_hint(x, inform = FALSE, error = FALSE)

Arguments

x

Input, a geojson character string, json object, or file or url pointing to one of the former

inform

(logical) When geojson is invalid, return reason why (TRUE) or don't return reason (FALSE). Default: FALSE

error

(logical) Throw an error on parse failure? If TRUE, then function returns TRUE on success, and stop with the error message on error. Default: FALSE

Details

Uses the Javascript library https://www.npmjs.com/package/geojsonhint via the V8 package

Value

TRUE or FALSE. If inform=TRUE an attribute of name errors is added with error information

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
geojson_hint('{"type": "FooBar"}')
geojson_hint('{ "type": "FeatureCollection" }')
geojson_hint(
  '{"type":"Point","geometry":{"type":"Point","coordinates":[-80,40]},"properties":{}}'
)

# A file
file <- system.file("examples", "zillow_or.geojson", package = "geojsonlint")
geojson_hint(as.location(file))

# A URL
if (interactive()) {
url <- "https://raw.githubusercontent.com/glynnbird/usstatesgeojson/master/california.geojson"
geojson_hint(as.location(url))
}

# from json (jsonlite class)
x <- jsonlite::minify('{ "type": "FeatureCollection" }')
class(x)
geojson_hint(x)

# toggle whether reason for validation failure is given back
geojson_hint('{ "type": "FeatureCollection" }')
geojson_hint('{ "type": "FeatureCollection" }', inform = TRUE)

# toggle whether to stop with error message
geojson_hint('{ "type": "FeatureCollection" }')
geojson_hint('{ "type": "FeatureCollection" }', inform = TRUE)
if (interactive()) {
geojson_hint('{ "type": "FeatureCollection" }', error = TRUE)
}

Example output

[1] FALSE
[1] FALSE
[1] FALSE
[1] FALSE
[1] "json"
[1] FALSE
[1] FALSE
[1] FALSE
attr(,"errors")
  line                    message
1    1 "features" member required
[1] FALSE
[1] FALSE
attr(,"errors")
  line                    message
1    1 "features" member required

geojsonlint documentation built on Feb. 13, 2020, 9:06 a.m.