
Get Brazilian municipalities longitude
Source:R/brazil_municipality_longitude.R
brazil_municipality_longitude.Rdbrazil_municipality_longitude() returns the longitude 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_longitude(
municipality_code,
year = as.numeric(substr(Sys.Date(), 1, 4)),
coords_method = "geobr",
names = TRUE,
...
)Arguments
- municipality_code
An
integerishvector with the IBGE codes of Brazilian municipalities. Usebrazil_municipality_code()to obtain codes from municipality names and states.- year
(optional) An
integerishnumber indicating the year of the data regarding the municipalities (default:Sys.Date() |> substr(1, 4) |> as.numeric()).- coords_method
(optional) A
characterstring indicating the method to retrieve the latitude and longitude coordinates of the municipalities (default:"geobr"). Options are:"geobr": Usesread_municipal_seat()from thegeobrpackage to retrieve the coordinates."geocodebr": Uses thegeocode()from thegeocodebrpackage to retrieve the coordinates.
- names
(optional) A
logicalflag indicating whether to return the names of the municipalities as names of the vector (default:TRUE).- ...
(optional) Additional arguments passed to
brazil_municipality().
Value
A numeric vector with the longitude of the
Brazilian municipalities.
Details
Data from this function is based on data from the Brazilian Institute
of Geography and Statistics (IBGE) via the
geobr R package.
The geobr package is produced by Brazil's Institute for
Applied Economic Research (IPEA) and access the
Brazilian Institute of Geography and Statistics
(IBGE) data. You can see a list of all
geobr datasets by running
geobr::list_geobr().
See also
Other Brazil functions:
brazil_fu(),
brazil_municipality(),
brazil_municipality_code(),
brazil_municipality_coords(),
brazil_municipality_latitude(),
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_longitude(3550308)
}
#> ! The closest map year to 2026 is 2024. Using year 2024 instead.
#> São Paulo-SP
#> -46.57038318
# }
# \dontrun{
if (has_internet()) {
brazil_municipality_longitude(c(3550308, 3500204))
}
#> ! The closest map year to 2026 is 2024. Using year 2024 instead.
#> São Paulo-SP Adolfo-SP
#> -46.57038318 -49.64972143
# }
# \dontrun{
if (has_internet()) {
brazil_municipality_longitude(c(3550308, 1000, 3500204))
}
#> ! The closest map year to 2026 is 2024. Using year 2024 instead.
#> São Paulo-SP <NA> Adolfo-SP
#> -46.57038318 NA -49.64972143
# }
# \dontrun{
if (has_internet()) {
brazil_municipality_longitude(c(3550308, NA, 3500204))
}
#> ! The closest map year to 2026 is 2024. Using year 2024 instead.
#> São Paulo-SP <NA> Adolfo-SP
#> -46.57038318 NA -49.64972143
# }