4

I have a SpatialPolygonsDataframe with multiple polygons, some of these have multiple parts (blue shapes below). In GIS-land it would be easy to get the areas of the individual parts of a multi-part polygon but it seems difficult to do this in R?

5

Here is a very simple and generic example. You need to access the relevant slots of the individual polygons. If you provide a data sample that better fits your situation I can try and be more specific.

mp <- readWKT("MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))")

# total area
sapply(slot(mp, "polygons"), slot, "area")

# get list of individual polys
p <- lapply(mp@polygons , slot , "Polygons")

# areas of individual polygons
lapply(p[[1]], function(x) slot(x, "area"))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.