ipeaGIT / geobr

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

ERROR in to_state(20725010) #317

Closed rafapereirabr closed 1 year ago

rafapereirabr commented 1 year ago

true address: CEP 20725-25 - Rua Cônego Tobias, Rio de Janeiro, RJ

Yet, the function geobr::cep_to_state() returns an error:

geobr::cep_to_state(20725010)

vss-2 commented 1 year ago

In cep_to_state.R line 49 (https://github.com/ipeaGIT/geobr/blob/c9787a742b099373c10939173995a974e187f62c/r-package/R/cep_to_state.R#LL49C32-L49C33) the following conditional ifelse( firstdigits2 >20 & firstdigits2 <28, 'RJ', # Rio de Janeiro

should be changed to: ifelse( firstdigits2 >19 & firstdigits2 <28, 'RJ', # Rio de Janeiro or ifelse( firstdigits2 >= 20 & firstdigits2 <28, 'RJ', # Rio de Janeiro

in order to fix the error.

Also, according to Wikipedia (https://pt.wikipedia.org/wiki/C%C3%B3digo_de_Endere%C3%A7amento_Postal), which I don't know if it is a secure source for this information, RJ state-codes start from 20000 to 28999. If correct, then <28 conditional must be fixed also (to <29 or <=28)!

rafapereirabr commented 1 year ago

Thanks. Fixed in dev version with #cddd6172.