Open sckott opened 6 years ago
cc @ateucher
moving to next milestone - played around with this a bit, but it's complicated since at least with geosjon_read
a user can pass in files and urls, each with various extensions, so makes it quite complicated. e.g. we'd not want to lint a kml file or a shp file
here's what i tried:
#' @export
geojson_read.character <- function(x, method = "web", parse = FALSE, what = "list", ...) {
lint_geojson(x)
read_json(as.location(x), method, parse, what, ...)
}
lint_geojson <- function(x) {
if (inherits(x, "character")) {
if (file.exists(x)) {
geojsonlint::geojson_validate(unclass(x), error = TRUE)
}
}
if (inherits(x, "location_")) {
if (attr(x, "type") == "file") {
geojsonlint::geojson_validate(unclass(x), error = TRUE)
}
}
}
#' @export
geojson_read.location_ <- function(x, method = "web", parse = FALSE, what = "list", ...) {
lint_geojson(x)
read_json(x, method, parse, what, ...)
}
arose from https://stackoverflow.com/questions/50240935/removing-brackets-from-ends-of-geojson-in-r
With the
bad.txt
file below, which contains JSON, rgdal fails without a helpful message:With
good.txt
it works fine:Options:
geojsonlint
to lint json to attempt to make sure the json is valid geojsonIf we use
geojsonlint
bad bad.txt good good.txt