Skip to content
Prev 29525 / 29559 Next

How to retrieve the interior boundary (points) of a polygon sf object

Dear Andrea,

Thank you for your detailed response. I followed your instructions carefully, and was able to get the expected results.

St_duplicated() is cool!

I have two following questions.


  1.
Why st_duplicated() works?

My guess is that for a typical (multi)polygon sf object, all vertices on the interior borders will be adopted twice to form polygons. Technically, this makes them appear twice in the geometry column of the data set. Meanwhile, vertices on the exterior borders only appear once. When checked by st_duplicated(), all the second appearance of the interior-border vertices will be marked true, and thus they are extracted.
Is my understanding correct?


  1.
Can we simplify a sentence?

In the script, there is a sentence:
pts_sfc <- st_multipoint(pts_matrix[, c(1, 2)]) |> st_sfc(crs = st_crs(polygon)) |> st_cast("POINT")
Is this sentence equal to the following one?
pts_sfc_2 <- st_cast(polygon, 'point')
I experimented by myself, and find identical(pts_sfc, pts_sfc_2)==FALSE. However, identical(st_duplicated(pts_sfc), st_duplicated(pts_sfc_2))==TRUE.

Again, thank you so much for your awesome solution!

Xiang