Learn R Programming

geojsonlint (version 0.3.0)

geojson_lint: Validate GeoJSON using geojsonlint.com web service

Description

Validate GeoJSON using geojsonlint.com web service

Usage

geojson_lint(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

...

curl options passed on to crul::verb-GET or crul::verb-POST

Value

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

Details

Uses the web service at http://geojsonlint.com

Examples

Run this code
# NOT RUN {
library(jsonlite)

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

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

# A URL
url <- "https://raw.githubusercontent.com/glynnbird/usstatesgeojson/master/california.geojson"
geojson_lint(as.location(url))

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

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

Run the code above in your browser using DataLab