ipeaGIT / geobr

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

CEP data #230

Open JoaoCarabetta opened 3 years ago

JoaoCarabetta commented 3 years ago

Following up our conversation about adding CEP data to geobr.

The current idea is to map CEP numbers to h3 hexagons, so that each hexagon would have a list of CEPs.

API

get_cep_by_geo(latitude, longitude, h3_id)
"""
Gets H3 hexagon in that maps to the coordinates and returns a list of CEP numbers.

The user can use lat, lon or the h3_id to get the CEP numbers

Return
-------
Dataframe:
     h3_id
     h3_geometry
     cep_number
"""

get_geo_by_cep(cep_number)
"""
Gets all H3 hexagons that contains the CEP number. 

Return
-------
Dataframe:
      h3_id
      h3_geometry
      cep_number

Infrastructure

get_cep_by_geo
  1. Map latitude, longitude to h3 cell using the H3 package that is available for python and R.
  2. Get the selected h3 cell parents
  3. Search a file system with the following structure:
    • h3_cell_resolution_4_id
      • h3_cell_resolution_5_id
        • h3_cell_resolution_6_id
          • ... up to a convenient resolution On a reasonable resolution, we should save a dataframe that is small enough to be downloaded and filtered.
  4. Download df, filter by h3 cell id and return
get_geo_by_cep
  1. Search a file system with the following structure:
    • first CEP digit
      • second CEP digit
        • third CEP digit
          • ....
            On a reasonable CEP digit, we should save a dataframe that is small enough to be downloaded and filtered.
  2. Download df, filter by h3 cell id and return

@rafapereirabr let me know what you think. It is not easy to build those indexes, but I it would be incredible to have it!

mmaga commented 3 months ago

Hello everyone,

Maybe this project by @millengustavo may inspire some very useful feature, which allows to intersect geobr with DataSUS microdata.

https://github.com/millengustavo/ibge-censo-cep-coordenadas/blob/main/notebooks/ibge_data.ipynb

Thanks for your request to @JoaoCarabetta, and many many many Thanks to IPEA team for maintaining this project and IPEAData also. Great job guys!