Skip to content

Commit

Permalink
minor changes to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rafapereirabr committed Dec 15, 2024
1 parent 147ff88 commit e255674
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 36 deletions.
4 changes: 4 additions & 0 deletions R/create_geocodebr_db.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ create_geocodebr_db <- function(db_path = tempdir(),
# DBI::dbExecute(con, "SET memory_limit = '20GB'")


if (DBI::dbExistsTable(con, 'cnefe')){
duckdb::duckdb_unregister_arrow(con, 'cnefe')
}

# Load CNEFE data and write it to DuckDB
cnefe <- arrow_open_dataset(cache_dir)
duckdb::duckdb_register_arrow(con, "cnefe", cnefe)
Expand Down
27 changes: 14 additions & 13 deletions R/geocode.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#' Download microdata of population records from Brazil's census
#' Geocoding addresses based on CNEFE data
#'
#' @description
#' Download microdata of population records from Brazil's census. Data collected
#' in the sample component of the questionnaire.
#' Takes a data frame containing addresses as an input and returns the spatial
#' coordinates found based on CNEFE data.
#'
#' @param input_table A data frame.
#' @param logradouro A string.
Expand All @@ -26,16 +26,16 @@
#' data_path <- system.file("extdata/sample_1.csv", package = "geocodebr")
#' input_df <- read.csv(data_path)
#'
#' # df <- geocodebr::geocode(
#' # input_table = input_df,
#' # logradouro = "nm_logradouro",
#' # numero = "Numero",
#' # complemento = "Complemento",
#' # cep = "Cep",
#' # bairro = "Bairro",
#' # municipio = "nm_municipio",
#' # estado = "nm_uf"
#' # )
#' df <- geocodebr::geocode(
#' input_table = input_df,
#' logradouro = "nm_logradouro",
#' numero = "Numero",
#' complemento = "Complemento",
#' cep = "Cep",
#' bairro = "Bairro",
#' municipio = "nm_municipio",
#' estado = "nm_uf"
#' )
#'
geocode <- function(input_table,
logradouro = NULL,
Expand Down Expand Up @@ -657,6 +657,7 @@ geocode <- function(input_table,

# Disconnect from DuckDB when done
duckdb::dbDisconnect(con, shutdown=TRUE)
gc()

# Return the result
return(output_deterministic)
Expand Down
16 changes: 11 additions & 5 deletions R/reverse_geocode.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#' Reverse geocoding
#' Reverse geocoding coordinates based on CNEFE data
#'
#' @description
#' Reverse geocode coordinate pairs to find the address in CNEFE that most
#' closely matches the input coordinates.
#' Takes a data frame containing coordinates (latitude and longitude) and
#' returns the address in CNEFE that is the closest to the input coordinates.
#' Latitude and longitude inputs are limited to possible values. Latitudes must
#' be between -90 and 90 and longitudes must be between -180 and 180.
#'
#' @param input_table A data frame. It must contain the columns `'id'`, `'lon'`, `'lat'`
#' @template ncores
Expand All @@ -15,14 +17,17 @@
#' @examplesIf identical(tolower(Sys.getenv("NOT_CRAN")), "true")
#'
#' # input data
#' lonlat_df <- data.frame(
#' df_coords <- data.frame(
#' id = 1:6,
#' lon = c(-67.83112, -67.83559, -67.81918, -43.47110, -51.08934, -67.8191),
#' lat = c(-9.962392, -9.963436, -9.972736, -22.695578, -30.05981, -9.97273)
#' )
#'
#' # reverse geocode
#' df_addresses <- geocodebr::reverse_geocode(input_table = lonlat_df)
#' df_addresses <- geocodebr::reverse_geocode(
#' input_table = df_coords,
#' progress = TRUE
#' )
#'
reverse_geocode <- function(input_table,
progress = TRUE,
Expand Down Expand Up @@ -146,6 +151,7 @@ reverse_geocode <- function(input_table,

# Disconnect from DuckDB when done
duckdb::dbDisconnect(con, shutdown=TRUE)
gc()

return(output)
}
26 changes: 13 additions & 13 deletions man/geocode.Rd

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

15 changes: 10 additions & 5 deletions man/reverse_geocode.Rd

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

0 comments on commit e255674

Please sign in to comment.