Home > Software design >  Create polygon from outermost point spatial coordinates
Create polygon from outermost point spatial coordinates

Time:06-29

I have a large dataframe of point coordinates and I am trying to make a polygon out of the edge of the coordinates. Some of the points fall near the middle, so I do not want those points to shape the boundary of the polygon created. These are spatial data and I do convert them into sf or terra objects, but in the simplest form they are just (x,y) coordinates.

I've looked and I can't find any already developed function for this task.

Here's a basic set of coordinates that replicate the problem:

lat <- c(-34.8861,-34.9845,-34.9839,-34.4555,-34.3272,-34.922,-34.7)
lon <- c(118,117.721,117.118,116.789,115.785,115.843,116.5)

plot(lon,lat)

Any ideas for creating a polygon out of the outermost points of these coordinates?

CodePudding user response:

something like this:

library(sf)
df <- data.frame(x = lon, y = lat)
pts1 <- st_as_sf(x = df, coords = c('x', 'y'))
my_hull <- st_convex_hull(st_union(pts1))
plot(my_hull)
  • Related