[R-sig-Geo] calculate the area of an alpha shape

Ashton Shortridge ashton at msu.edu
Mon Nov 4 14:34:52 CET 2013


Dear André,

There may be a more elegant solution, but this works fine:
library(sp)
bds <- achull.obj$ashape.obj$x  # matrix of coordinates in ashape
bds <- rbind(bds, bds[1,])          # close the ring
ashape <- Polygon(bds)            # convert to sp Polygon  
print(ashape at area)



On Monday, November 04, 2013 11:58:26 AM Proosdij, Andre van wrote:
> Dear colleagues,
> 
> I wish to calculate the area covered by the alpha shape based on a sample of
> points in a 2D plane. For the alpha-convex hull this works fine using the
> function ahull in the alphahull package. However, I want to get the area of
> the slightly different alpha shape. How can I do this? Below a short
> example.
> 
> Many thanks in advance for your answers and ideas!
> 
> 
> André
> 
> 
> 
> x <- c(1,1,1.5,2.8,3,3)
> y <- c(1,3,2,3,4,1)
> z <- cbind(x,y)
> plot(z)
> 
> ### Calculate the alpha-convex hull
> library(alphahull)
> alpha <- 3 # Define alpha > 0
> achull.obj <- ahull(z, alpha = alpha)
> 
> ### Plot the sampled points and the alpha-convex hull object
> plot(achull.obj, add = TRUE, col = "blue")
> 
> ### Get the length of the alpha-convex hull
> achulllength <- achull.obj$length
> achulllength
> 
> ### Get the area of the alpha-convex hull
> achullarea <- areaahull(achull.obj)
> achullarea
> 
> ### Plot the alpha shape
> plot(achull.obj$ashape.obj, add = TRUE, col = "red")
> 
> ### Get the length of the alpha shape
> ashapelength <- achull.obj$ashape.obj$length
> ashapelength
> 
> 
> 
> 
> 
> Ir. A.S.J. van Proosdij
> PhD Student
> t   +31 317 48 1198
> e  andre.vanproosdij at wur.nl<mailto:andre.vanproosdij at wur.nl>
> 
> Naturalis Biodiversity Center, section NHN
> Biosystematics Group, Wageningen University
> Gen. Foulkesweg 37, 6703 BL Wageningen, the Netherlands
> 
> www.bis.wur.nl<http://www.bis.wur.nl/>
> 
> 
> 	[[alternative HTML version deleted]]

-----
Ashton Shortridge
Associate Professor			ashton at msu.edu
Dept of Geography			http://www.msu.edu/~ashton
235 Geography Building		ph (517) 432-3561
Michigan State University		fx (517) 432-1671



More information about the R-sig-Geo mailing list