datazoom.amazonia icon indicating copy to clipboard operation
datazoom.amazonia copied to clipboard

Error in the dataframe sigmine_active

Open reichaves opened this issue 3 years ago • 5 comments

Hi In the 'sigmine_active' database I used the command below to add a characteristic. But an error appears that I've never seen - do you know? It seems to point an error in the dataframe

library(tidyverse)
library(datazoom.amazonia)
minera <- load_sigmine(dataset = 'sigmine_active', raw_data = TRUE, language = "pt")


# In the "CONCESSÃO DE LAVRA" phase, which are the 20 companies that have the most records
filter(minera, fase=="CONCESSÃO DE LAVRA") %>% 
  group_by(nome) %>% 
  summarize(total=n()) %>%    
  arrange(desc(total)) %>% 
  head(20)

Error: st_as_s2(): dropping Z and/or M coordinate st_as_s2(): dropping Z and/or M coordinate Error in s2_geography_from_wkb(x, oriented = oriented, check = check) : Evaluation error: Found 1 feature with invalid spherical geometry. [1] Loop 0 is not valid: Edge 39 has duplicate vertex with edge 51.

reichaves avatar Apr 07 '22 18:04 reichaves

Hi @reichaves

For now, I think you can achieve what you intended by dropping the geometry feature with sf::st_drop_geometry():

filter(minera, fase=="CONCESSÃO DE LAVRA") %>% 
    sf::st_drop_geometry() %>% 
    group_by(nome) %>% 
    summarize(total=n()) %>%    
    arrange(desc(total)) %>% 
    head(20)

The error is probably due to an inconsistency in the geometries in the sigmine database.

gnjardim avatar Apr 08 '22 15:04 gnjardim

Thanks @gnjardim I don't know this command

I tried:

sf::st_drop_geometry()
Error in UseMethod("st_drop_geometry") : 
  no applicable method for 'st_drop_geometry' applied to an object of class "NULL"

Should I assign to dataframe minera?

reichaves avatar Apr 08 '22 15:04 reichaves

No problem, @reichaves

Yes, you can use:

minera_no_geom <- sf::st_drop_geometry(minera)

That will return the same dataframe but without the geometry column

gnjardim avatar Apr 08 '22 16:04 gnjardim

Thanks

reichaves avatar Apr 08 '22 18:04 reichaves

I created a script of usage examples, next week we should publish it on Abraji's website - https://github.com/abraji/datazoomamazonia/blob/main/amazonia.R

reichaves avatar Apr 08 '22 21:04 reichaves