Skip to content

Commit

Permalink
Closes #232
Browse files Browse the repository at this point in the history
  • Loading branch information
rafapereirabr committed Apr 1, 2021
1 parent 2c8ac40 commit 6908a68
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
36 changes: 36 additions & 0 deletions r-package/R/read_urban_concentrations.R
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)

}
34 changes: 34 additions & 0 deletions r-package/man/read_urban_concentrations.Rd

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

29 changes: 29 additions & 0 deletions r-package/tests/testthat/test-read_urban_concentrations.R
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))

})

0 comments on commit 6908a68

Please sign in to comment.