ipeaGIT / geobr

Easy access to official spatial data sets of Brazil in R and Python
https://ipeagit.github.io/geobr/
778 stars 116 forks source link

District and subdistrict boundaries #354

Closed hugonbgg closed 2 months ago

hugonbgg commented 2 months ago

Hello, would it be possible to make the data available by district and subdistrict?

rafapereirabr commented 2 months ago

Hi @hugonbgg. Thanks for the suggestion. The data or districts and subdistricts are not available for all municipalities. Creating additional functions to read these data sets would add an extra load of work to the maintainers of the data in {geobr} (basically me, myself and I).

Moreover, it is super simple to generate these boundaries from the census tracts data set. See example below. In this example, I create the boundaries of neighborhoods in Porto Alegre because this municipality does not have info on districts and subdistricts in 2010. However, the code can be easily adapted to generate the geometry of districts and subdistricts for other municipalities where this info is available.

library(geobr)
library(sf)
library(dplyr)
library(sfheaders)

# using planar geometry
sf::sf_use_s2(FALSE)

# get muni info
poa_info <- geobr::lookup_muni(name_muni = 'Porto Alegre')

# download census tracts
poa_tracts <- geobr::read_census_tract(year = 2010,
                                       code_tract = poa_info$code_muni, 
                                       simplified = FALSE)

# get boundaries of neighborhoods
poa_district <- poa_tracts |>
                    group_by(name_neighborhood) |>
                    summarise() |>
                    sfheaders::sf_remove_holes() 

plot(poa_district['name_neighborhood'])

Rplot01