ipeaGIT / geobr

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

read_municipality() and read_state() going wrong #284

Closed augustocfg closed 1 year ago

augustocfg commented 2 years ago

Hello, i'm having trouble reading the geom column in both functions.

brasil <- read_state(code_state = "all") brasil2 <- read_municipality(code_muni = "all")

when i try run with tmap package it gives me strange outputs.

tm_shape(brasil) + tm_borders()

tm_shape(brasil2) + tm_borders()

the output to the first function it's a deformed map, but when i try to remove a random row from the dataset, it works.

q

The output to the second function is Error: Shape contains invalid polygons. Please fix it or set tmap_options(check.and.fix = TRUE) and rerun the plot

i've searched everywhere and didn't found an answer for why it's doing it.

rafapereirabr commented 2 years ago

Hi @augustocfg . Thank you for opening this issue.

Regarding the first problem, I've opened an issue on tmap repo to see what could be causing this. As a temporary fix for this problem, you can subset the data removing a row that does not exist, and it will work (I don't know why, but it works).

brasil3 <- subset(brasil, abbrev_state  != "xx")

Regarding the second problem, this can be fixed by using the sf::st_make_valid() function as in my example below. I will make sure to make this correction in the data in the next few days so that users don't need to make this every time they use geobr.

brasil2 <- st_make_valid(brasil2)
tm_shape(brasil2) + tm_borders()
rafapereirabr commented 1 year ago

This has now been fixed with #9c1dd5aa in the dev version.