#' electoral_areas Function
#'
#' This function download data about electoral areas in Poznan.
#' @keywords keyword
#' @export
#' @param coords show basic data about electoral areas in Poznań. When set TRUE shows coords of electoral areas.
#' @details Details of usage
#' @importFrom jsonlite fromJSON
#' @importFrom purrr map map2_df
#' @format
#' \describe{
#' \item{ID}{numeric; ID of area electoral.}
#' \item{District_no}{numeric; Number of district.}
#' \item{Longitude}{numeric; Longitude of area electoral.}
#' \item{Latitude}{numeric; Latitude of area electoral.}
#' }
#' @examples
#' Area_Electoral <- electoral_areas(coords = F)
#' Areas <- electoral_areas(coords = T)
#' coord <- Areas$coord
electoral_areas <- function(coords = F){
# dane wybory samorzadowe obwody wyborcze
# wczytanie danych o wyborach samorzadowych
if(have_ip() == T){
tryCatch({ # w przypadku baraku internetu wywoła wyjątek
ob2 <- fromJSON("http://www.poznan.pl/featureserver/featureserver.cgi/wybory_obwody_wgs/")
},error = function(err) {
warning("You used bad link!")
})
}else{
warning("You lost connection to internet!")
}
oblast2 <- ob2$features
# Oczyszczenie danych z niepotrzebnych informacji + nazwanie
oblast2coord <- oblast2$geometry$coordinates
oblast2coord2d <- map(oblast2coord, drop)
oblast2coord_df <- map(oblast2coord2d, as.data.frame)
oblast2coord_id <- map2_df(oblast2coord_df, oblast2$id, ~mutate(.x, id=.y))
oblast2_basic_info <- data.frame(ID=oblast2$id,
District_no=oblast2$properties$nr_obwodu)
oblast2coord_id <- data.frame(Longitude=oblast2coord_id$V1,
Latitude=oblast2coord_id$V2,
id=oblast2coord_id$id)
# z??czenie wszystkich kolumn
if(coords == T){
result <- list(area=oblast2_basic_info, coord=oblast2coord_id)
} else {
return(oblast2_basic_info)
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.