Skip to content
Prev 29521 / 29559 Next

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

Hi Xiang! I would use the following approach:

library(tidyverse)
library(sf)
library(spData)
# You need the development version of sfnetworks:
# remotes::install_github("luukvdmeer/sfnetworks")
library(sfnetworks) # Exports st_duplicated

polygon = st_geometry(us_states)
pts_matrix <- st_coordinates(polygon)
pts_sfc <- st_multipoint(pts_matrix[, c(1, 2)]) |> st_sfc(crs = 
st_crs(polygon)) |> st_cast("POINT")
pts_dup <- st_duplicated(pts_sfc)
pts_interior <- pts_sfc[pts_dup]

plot(polygon, reset = FALSE)
points(pts_interior, cex = 1, pch = 16, col = 2)

You can also check the output here: 
https://gist.github.com/agila5/2b5d9b7e1453c4d3f292e7aae5fdb79e

Hope that's helpful.

Andrea
On 8/6/2025 7:27 PM, Dexter Locke wrote: