Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In R, how do I run st_convex_hull function on point sf object?

Tags:

r

sf

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?

like image 573
radek Avatar asked Aug 07 '18 04:08

radek


1 Answers

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)
like image 81
TimSalabim Avatar answered Oct 22 '22 12:10

TimSalabim