14

I'm trying to get a convex hull of point features in R.

library(tmap)
library(sf)
nc <- st_centroid(st_read(system.file("shape/nc.shp", package="sf")))
qtm(nc)

ch <- st_convex_hull(nc) 
qtm(ch)

identical(nc, ch)

I'd expect the st_convex_hull to contain polygon with convex hull. However it returns points that are not identical. How can I get the polygon instead?

radek
  • 7,240
  • 8
  • 58
  • 83

1 Answers1

23

You need to union the points into MULTIPOINTS

library(tmap)
library(sf)
nc <- st_centroid(st_read(system.file("shape/nc.shp", package="sf")))
qtm(nc)

ch <- st_convex_hull(st_union(nc)) 
qtm(ch)
TimSalabim
  • 5,604
  • 1
  • 25
  • 36