sf icon indicating copy to clipboard operation
sf copied to clipboard

check validity of polygon geometry, cast to single polygons and remove holes

Open edizherms opened this issue 3 years ago • 2 comments

Hi,

I am using the sf package to check validity of polygon geometry, cast to single polygons and remove holes. Unfortunately, my code fails

polygon = st_make_valid(polygon) %>% sf_remove_holes() %>% st_cast("MULTIPOLYGON" ) %>% st_cast("POLYGON")

and gives me the warning message

In st_cast.sf(., "POLYGON") :
  repeating attributes for all sub-geometries for which they may not be constant

Is here someone that can help with this issue?

polygon.csv

edizherms avatar Jul 18 '22 07:07 edizherms

What is the issue?

edzer avatar Jul 18 '22 07:07 edzer

What is the issue?

Thank you for your response.

Basically, the same issue that is described here: https://github.com/r-spatial/sf/issues/323#event-1063195119

This code works: polygon = st_cast(polygon, "POLYGON")

But this code is not working: polygon = st_make_valid(polygon) %>% st_cast("MULTIPOLYGON") %>% st_cast("POLYGON")

I dont understand why and unfortunately cannot follow your response to question #323.

edizherms avatar Jul 18 '22 09:07 edizherms

st_make_valid(pol) %>% st_cast("MULTIPOLYGON" ) %>% st_cast("POLYGON")

works, sf_remove_holes is not an sf function.

edzer avatar Mar 27 '23 18:03 edzer