geojson_hint: Validate GeoJSON using geojsonhint Javascript library

View source: R/geojsonhint.R

geojson_hintR Documentation

Validate GeoJSON using geojsonhint Javascript library

Description

Validate GeoJSON using geojsonhint Javascript library

Usage

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

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)
}

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