Skip to content

TopologyException in multipolygons (intersection function) #794

@carlosmolinaguerra

Description

@carlosmolinaguerra

Hi,
I have a large sfc (MULTIPOLYGON) objects which throw several TopologyException errors when I try to use the intersection function on them. I have a couple of questions so, If anyone has a moment, I would really appreciate it if you could take a look at this. I've attached the files in RDS format (all). Below is some example code.

all<-readr::read_rds("all.rds")

None of these lines seems to work:

all %>% st_intersection
all %>% st_set_precision(1000000) %>% lwgeom::st_make_valid %>% st_intersection
all %>% st_set_precision(1000) %>% lwgeom::st_make_valid %>% st_intersection

  1. sf::st_is_valid returns TRUE for all objects. I've tried using mapview, lwgeom::st_make_valid and modifying the precision of the calculations. Only when I set precision to 100 or lower, the "rounded coordinates" become valid geometries to execute the st_intersection function. This issue is related to discussions in #600 and #603. The problem for me is that rounding the coordinates (two decimal places) does not seem appropriate for the work I'm doing. I tried several strategies including rounding (and using st_make_valid) the coordinates just for next rows (sfg):
    all %>% st_set_precision(100) %>% lwgeom::st_make_valid %>% sf::st_is_valid
    However, the issue remains.

  2. A subset of the data that generates one of the TopologyException errors is:

subset<-all %>% subset(id %in% c(47,98,158))
st_intersection(subset)

I imagine I am off-track here but It seems tricky to me that the st_intersection of these three multipolygons do not work but pairwise-intersections of these rows do not generate any error. Could you please let me know what I am missing?

int12<-st_intersection(subset[c(1,2),])
int13<-st_intersection(subset[c(1,3),])
int23<-st_intersection(subset[c(2,3),])

Apologies if I've posted this in the wrong place. I hope I am not completely off-track. In case, feel free to delete this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions