Hi,


I have created a SpatialPolygons object of a urban task which corresponds
to buildings buffered to 50 meters.

I wanted to extract all the areas within this urban task that have not been
built yet. These correspond to holes.

I have developped a code to extract these holes but I do not find it very
elegant.

I know there are many skilled hackers on this list. Maybe anyone has an
idea on making it nicer?


library(rgdal)
library(maptools)

setwd("C:/~METHODES/dentsCreuses")
pol <- readOGR(".", "dentsCreuses")

out <- vector(mode="list")

nPols <- length(pol@polygons)
for (i in 1:nPols) {
  print(i)
  for (Pol in pol@polygons[[i]]@Polygons) {
    if (Pol@hole) out[i] <- Pol
  }
}

out <- unlist(out)

Pols <- lapply(1:length(out), function(x) Polygons(list(out[[x]]),
ID=as.character(x)))
spPols <- SpatialPolygons(Pols)

	[[alternative HTML version deleted]]

