geojson_validate: Validate GeoJSON using is-my-json-valid Javascript library

View source: R/geojson_validate.R

geojson_validateR Documentation

Validate GeoJSON using is-my-json-valid Javascript library

Description

Validate GeoJSON using is-my-json-valid Javascript library

Usage

geojson_validate(x, inform = FALSE, error = FALSE, greedy = 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 NULL on success, and stop with the error message on error. Default: FALSE

greedy

(logical) Continue after the first error? TRUE or FALSE. Default: FALSE

Details

Sometimes you may get a response that your input GeoJSON is invalid, but get a somewhat unhelpful error message, e.g., no (or more than one) schemas match. See https://github.com/ropensci/geojsonlint/issues/7#issuecomment-219881961. We'll hopefully soon get this sorted out so you'll get a meaningful error message. However, this method is faster than the other two methods in this package, so there is that.

Value

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

References

https://www.npmjs.com/package/is-my-json-valid

Examples

# From a json character string
## good
geojson_validate('{"type": "Point", "coordinates": [-100, 80]}')
## bad
geojson_validate(
 '{"type": "Rhombus", "coordinates": [[1, 2], [3, 4], [5, 6]]}')

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

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

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

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

ropensci/geojsonlint documentation built on Sept. 12, 2022, 8 a.m.