-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c8ac40
commit 6908a68
Showing
3 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#' Download urban concentration areas in Brazil | ||
#' | ||
#' @description | ||
#' This function reads the official data on the urban concentration areas (Areas | ||
#' de Concentracao de Populacao) of Brazil. Original data were generated by the | ||
#' Institute of Geography and Statistics (IBGE) For more information about the | ||
#' methodology, see details at \url{https://www.ibge.gov.br/apps/arranjos_populacionais/2015/pdf/publicacao.pdf} | ||
#' | ||
#' @param year A year number in YYYY format. Defaults to `2015` | ||
#' @param simplified Logic `FALSE` or `TRUE`, indicating whether the function returns | ||
#' the data set with 'original' resolution or a data set with 'simplified' borders. | ||
#' Defaults to `TRUE`. For spatial analysis and statistics users should set | ||
#' `simplified = FALSE`. Borders have been simplified by removing vertices of | ||
#' borders using `st_simplify{sf}` preserving topology with a `dTolerance` of 100. | ||
#' @param showProgress Logical. Defaults to `TRUE` display progress bar | ||
#' | ||
#' @return An `"sf" "data.frame"` object | ||
#' | ||
#' @export | ||
#' @examples \dontrun{ if (interactive()) { | ||
#' # Read urban footprint of Brazilian cities in an specific year | ||
#' uc <- read_urban_concentrations(year=2015) | ||
#' } } | ||
read_urban_concentrations <- function(year=2015, simplified=TRUE, showProgress=TRUE){ | ||
|
||
# Get metadata with data url addresses | ||
temp_meta <- select_metadata(geography="urban_concentrations", year=year, simplified=simplified) | ||
|
||
# list paths of files to download | ||
file_url <- as.character(temp_meta$download_path) | ||
|
||
# download files | ||
temp_sf <- download_gpkg(file_url, progress_bar = showProgress) | ||
return(temp_sf) | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
context("read_urban_concentrations") | ||
|
||
|
||
# skip tests because they take too much time | ||
testthat::skip_on_cran() | ||
# testthat::skip_on_travis() | ||
# skip_if(Sys.getenv("TEST_ONE") != "") | ||
|
||
|
||
# Reading the data ----------------------- | ||
|
||
test_that("read_urban_concentrations", { | ||
|
||
# read data and check sf object | ||
test_sf <- read_urban_concentrations() | ||
|
||
expect_true(is(test_sf, "sf")) | ||
|
||
}) | ||
|
||
|
||
|
||
# ERRORS and messagens ----------------------- | ||
test_that("read_urban_concentrations", { | ||
|
||
# Wrong year | ||
expect_error(read_urban_concentrations(year=9999999)) | ||
|
||
}) |