R area within individual closed contours

243 Views Asked by At

Using R - I am hoping to calculate the area enclosed within a particular closed contour level (to form polygons). This has been addressed elsewhere but I am looking to also calculate the area separately if these closed contours are isolated from one another.

An example:

library(splancs)
x <- c(1,0,0,1,1,1.5,1.5,3,3,1)
y <- c(0,0,1,1,0,0,2,2,0,0)
m <- cbind(x, y)

plot(m, type="b")
areapl(m)

This gives an area=4 .... however I would like to have the output as a list of areas c(1,3) corresponding to the separate areas of each isolated polygons.

This is just a toy example. In my real data I do not first know the coordinates of the polygons AND I do not know how many isolated polygons there will be.

Any ideas would be great - I am open to using other R spatial packages.

1

There are 1 best solutions below

0
On

I was able to solve this by converting to raster and using clump from raster package:

r <- raster(ncols=12, nrows=12)
set.seed(0)
r[] <- round(runif(ncell(r))*0.7 )
rc <- clump(r) 
freq(rc)
plot(r)
plot(rc)

This example is directly from the raster package - I have posted it as it may be relevant to others!