Skip to content

Commit

Permalink
Add support for geojson
Browse files Browse the repository at this point in the history
  • Loading branch information
sharlagelfand authored and sckott committed Jul 19, 2019
1 parent ac82ca1 commit 30c5666
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ Suggests:
readxl,
testthat,
xml2,
lazyeval
lazyeval,
geojsonio
RoxygenNote: 6.1.1
X-schema.org-keywords: database, open-data, ckan, api, data, dataset
X-schema.org-applicationCategory: Data Access
Expand Down
12 changes: 12 additions & 0 deletions R/ckan_fetch.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@
#' x <- ckan_fetch(res$url)
#' class(x)
#' plot(x)
#'
#' GeoJSON file - requires geojsonio package
#' ckanr_setup("http://open.canada.ca/data/en")
#' res <- resource_show(id = "1502d5ec-0af2-4e2f-8fa7-1e90a43f356a", as = "table")
#' ckan_fetch(res$url)
#'
#' }
ckan_fetch <- function(x, store = "session", path = "file", format = NULL, ...) {
store <- match.arg(store, c("session", "disk"))
Expand Down Expand Up @@ -90,6 +96,12 @@ read_session <- function(fmt, dat, path) {
shp = {
check4X("sf")
sf::st_read(path)
},
geojson = {
check4X("geojsonio")
geojsonio::geojson_read(path,
method = "local",
parse = TRUE)
}
)
}
2 changes: 1 addition & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fetch_GET <- function(x, store, path, args = NULL, format = NULL, ...) {
fmt <- ifelse(identical(file_fmt, character(0)), format, file_fmt)
fmt <- tolower(fmt)
if (store == "session") {
if (fmt %in% c("xls", "xlsx")) {
if (fmt %in% c("xls", "xlsx", "geojson")) {
dat <- NULL
path <- paste0(path, ".", fmt)
res <- GET(x, query = args, write_disk(path, TRUE), config = proxy, ...)
Expand Down
12 changes: 12 additions & 0 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@
"url": "https://cran.r-project.org"
},
"sameAs": "https://CRAN.R-project.org/package=lazyeval"
},
{
"@type": "SoftwareApplication",
"identifier": "geojsonio",
"name": "geojsonio",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
"name": "Comprehensive R Archive Network (CRAN)",
"url": "https://cran.r-project.org"
},
"sameAs": "https://CRAN.R-project.org/package=geojsonio"
}
],
"softwareRequirements": [
Expand Down
6 changes: 6 additions & 0 deletions man/ckan_fetch.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 30c5666

Please sign in to comment.