
Get Brazilian municipalities geographic coordinates
Source:R/brazil_municipality_coords.R
brazil_municipality_coords.Rd
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
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. Usebrazil_municipality_code()
to obtain codes from municipality names and states. IfNULL
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 (default:
"geobr"
). Options are:"geobr"
: Usesread_municipal_seat()
from thegeobr
package to retrieve the coordinates."geocodebr"
: Uses thegeocode()
from thegeocodebr
package to retrieve the coordinates.
- 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.
See also
Other Brazil functions:
brazil_fu()
,
brazil_municipality()
,
brazil_municipality_code()
,
brazil_municipality_latitude()
,
brazil_municipality_longitude()
,
brazil_region()
,
brazil_region_code()
,
brazil_render_address()
,
brazil_state()
,
brazil_state_by_utc()
,
brazil_state_capital()
,
brazil_state_code()
,
brazil_state_latitude()
,
brazil_state_longitude()
Examples
library(curl)
# \dontrun{
if (has_internet()) {
brazil_municipality_coords()
}
#> ! The closest map year to 2025 is 2010. Using year 2010 instead.
#> Using year/date 2010
#> # A tibble: 5,565 × 3
#> municipality_code latitude longitude
#> <dbl> <dbl> <dbl>
#> 1 1100015 -11.9 -62.0
#> 2 1100023 -9.91 -63.0
#> 3 1100031 -13.5 -60.5
#> 4 1100049 -11.4 -61.4
#> 5 1100056 -13.2 -60.8
#> 6 1100064 -13.1 -60.6
#> # ℹ 5,559 more rows
# }
# \dontrun{
if (has_internet()) {
brazil_municipality_coords(municipality_code = 3550308)
}
#> ! The closest map year to 2025 is 2010. Using year 2010 instead.
#> Using year/date 2010
#> # A tibble: 1 × 3
#> municipality_code latitude longitude
#> <dbl> <dbl> <dbl>
#> 1 3550308 -23.6 -46.6
# }
# \dontrun{
if (has_internet()) {
brazil_municipality_coords(municipality_code = 3550)
}
#> ! The closest map year to 2025 is 2010. Using year 2010 instead.
#> Using year/date 2010
#> # A tibble: 10 × 3
#> municipality_code latitude longitude
#> <dbl> <dbl> <dbl>
#> 1 3550001 -23.2 -45.3
#> 2 3550100 -22.7 -48.6
#> 3 3550209 -23.9 -48.0
#> 4 3550308 -23.6 -46.6
#> 5 3550407 -22.5 -47.9
#> 6 3550506 -22.8 -49.7
#> # ℹ 4 more rows
# }
# \dontrun{
if (has_internet()) {
brazil_municipality_coords(municipality_code = c(3550308, 3304557))
}
#> ! The closest map year to 2025 is 2010. Using year 2010 instead.
#> Using year/date 2010
#> # A tibble: 2 × 3
#> municipality_code latitude longitude
#> <dbl> <dbl> <dbl>
#> 1 3304557 -22.9 -43.2
#> 2 3550308 -23.6 -46.6
# }