Skip to contents

get_brazil_municipality_coords() returns a tibble with the latitude and longitude coordinates of Brazilian municipalities.

Note: This function requires an internet connection to work and the geobr or geocodebr package to be installed, depending on the chosen method for retrieving coordinates.

Usage

get_brazil_municipality_coords(
  municipality_code = NULL,
  year = as.numeric(substr(Sys.Date(), 1, 4)),
  coords_method = "geobr",
  force = FALSE
)

Arguments

municipality_code

(optional) An integerish vector with the IBGE codes of Brazilian municipalities. Use get_brazil_municipality_code() to obtain codes from municipality names and states. If NULL the function returns all municipalities (default: NULL).

year

(optional) An integerish number indicating the year of the data regarding the municipalities (default: Sys.Date() |> substr(1, 4) |> as.numeric()).

coords_method

(optional) A string indicating the method to retrieve the latitude and longitude coordinates of the municipalities. Options are:

force

(optional) A logical flag indicating whether to force the download of the data again (default: FALSE).

Value

A tibble with the following columns:

  • municipality_code: The municipality code.

  • latitude: The municipality latitude.

  • longitude: The municipality longitude.

Details

The data from this function is based on data from the Brazilian Institute of Geography and Statistics (IBGE) via the geobr and geocodebr R packages.

Both packages are produced by Brazil's Institute for Applied Economic Research (IPEA) and access the Brazilian Institute of Geography and Statistics (IBGE) data.

Examples

if (FALSE) { # \dontrun{
  get_brazil_municipality_coords() |> dplyr::glimpse()

  get_brazil_municipality_coords(municipality_code = 3550308)

  get_brazil_municipality_coords(municipality_code = 3550)

  get_brazil_municipality_coords(municipality_code = c(3550308, 3304557))
} # }