From 30c5666b15f5b3a7941eed930cd5a2342ca72d7f Mon Sep 17 00:00:00 2001 From: Sharla Gelfand Date: Fri, 12 Jul 2019 16:54:55 -0400 Subject: [PATCH] Add support for geojson --- DESCRIPTION | 3 ++- R/ckan_fetch.R | 12 ++++++++++++ R/zzz.R | 2 +- codemeta.json | 12 ++++++++++++ man/ckan_fetch.Rd | 6 ++++++ 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0d3d8cc..35fe749 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 diff --git a/R/ckan_fetch.R b/R/ckan_fetch.R index 11da9c1..00242d7 100644 --- a/R/ckan_fetch.R +++ b/R/ckan_fetch.R @@ -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")) @@ -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) } ) } diff --git a/R/zzz.R b/R/zzz.R index 42e62ab..05e29a3 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -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, ...) diff --git a/codemeta.json b/codemeta.json index 18bdae5..ce3c334 100644 --- a/codemeta.json +++ b/codemeta.json @@ -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": [ diff --git a/man/ckan_fetch.Rd b/man/ckan_fetch.Rd index a6608b6..6756dd4 100644 --- a/man/ckan_fetch.Rd +++ b/man/ckan_fetch.Rd @@ -64,5 +64,11 @@ res <- resource_show(id = "6cbb0aa3-a8d1-421c-9c40-14c6f05e0c73", as = "table") 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) + } }