Skip to content

Commit b441288

Browse files
authored
Add r function to download geoshape
1 parent 0e0aa91 commit b441288

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

R/ods_get_geoshape.R

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#' Return a polygon of a valid statistical geography
2+
#'
3+
#' \code{ods_get_geoshape} returns a string from \href{https://statistics.gov.scot/}{statistics.gov.scot} of all geographies which contain the geography provided
4+
#'
5+
#' The \code{geography} parameter must be passed a valid geography unit.
6+
#'
7+
#' @param geography \code{string}. A valid geography unit from \href{https://statistics.gov.scot/}{statistics.gov.scot}.
8+
#'
9+
#' @return \code{string}.
10+
#'
11+
#' @examples
12+
#' ods_get_geoshape("S02001257")
13+
#'
14+
#' @export
15+
16+
ods_get_geoshape <- function(geography) {
17+
18+
endpoint <- "http://statistics.gov.scot/sparql"
19+
20+
query_text <- read_query_file("get_geoshape")
21+
query <- glue::glue(query_text, geography, .open = "[", .close = "]")
22+
query <- sub("(}).*", "\\1", query) #having some issues with extra text, adding hack
23+
query_data <- ods_query_database(endpoint, query)
24+
25+
return(query_data$map)
26+
27+
}
28+
query_text <- paste(query_text, collapse = " ")

0 commit comments

Comments
 (0)