Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid geometry for Amazônia in read_biomes #361

Open
OlivazShai opened this issue Jul 5, 2024 · 7 comments
Open

Invalid geometry for Amazônia in read_biomes #361

OlivazShai opened this issue Jul 5, 2024 · 7 comments

Comments

@OlivazShai
Copy link

When running:
read_biomes( year = 2019, simplified = TRUE )

The geometry for the Amazon is invalid, which makes it impossible to perform intersections and other operations. When running:
st_is_valid(reason=TRUE)

We get following result, for Amazon:
"Loop 114: Edge 168413 crosses edge 168418"

Applying st_make_valid doesn't solve the issue, for some reason...

@rafapereirabr
Copy link
Member

Try using simplified = FALSE

read_biomes( year = 2019, simplified = FALSE)

@OlivazShai
Copy link
Author

Ah sorry! I copy-pasted the wrong version, lack of attention there. It's actually the opposite. I had switched to simplified = TRUE earlier, because then I get no issue and can perform intersections normally (just not accurately, I reckon).

The problem I mentioned only appears when I use simplified = FALSE.

I basically want which biomes are in each municipality, so I imagine using simplified = TRUE for now is probably okay, right? Do you know any alternative sources or ways to get that info? Oh, and thx a lot for the quick reply!

@rafapereirabr
Copy link
Member

Could you please share the code to reproduce the error ?

@OlivazShai
Copy link
Author

Sure! I'm sending a PDF knit of the code, in R.

Essentially, I'm running:

biomes <- read_biomes(
  year = 2019, 
  simplified = FALSE,
  showProgress = FALSE
  )

mun <- read_municipality(
  code_muni = "all", 
  year = 2017,
  simplified = FALSE,
  showProgress = FALSE
  )

And doing:

st_intersects(
    mun,
    biomes,
    sparse = FALSE
  )

Which yields this error:

Error in wk_handle.wk_wkb(wkb, s2_geography_writer(oriented = oriented, :
Loop 114 is not valid: Edge 168413 crosses edge 168418

I think more details can be seen in the file
biome_issue.pdf
.

@rafapereirabr
Copy link
Member

Hi @OlivazShai , thanks for reporting this issue. This is a problem with the original data set made publicly available by IBGE on the http: 'https://geoftp.ibge.gov.br/informacoes_ambientais/estudos_ambientais/biomas/vetores/Biomas_250mil.zip'

I haven't found a way to fix this topology error yet. I wanntry dissolving borders a fast approach like this one but I haven't found the time to test it yet.

@OlivazShai
Copy link
Author

Thanks a lot for the help! Let me know if you find a solution, or if IBGE updates their data. I'm currently using the simplified polygons, which seem to suffice for my analysis by municipality. If/when I switch to a more granular approach I'll probably have to look for some workarounds, I'll let you know if I reach any usable solution too.

By the way, IBGE issued recently (like, two weeks ago) a list of municipalities by predominant biome, which is kind of what I was looking for. And there also is an older list, from 2019, with a slighly different approach. They're available at https://geoftp.ibge.gov.br/informacoes_ambientais/estudos_ambientais/biomas/documentos/

It's a simple table and very tractable as it is, but seems like it could be a nice addition to the geobr package :)

@OlivazShai
Copy link
Author

As an update, I checked turning off s2 following this suggestion, with sf_use_s2(FALSE).

After doing so, running:

st_is_valid(biomes)

Retuns TRUE for all biomes.

Not ideal, though...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants