Validate GeoJSON using geojsonhint Javascript library

Share:

Description

Validate GeoJSON using geojsonhint Javascript library

Usage

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

Arguments

x

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

verbose

(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 verbose=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
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
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" }', verbose = TRUE)

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