Skip to content
Prev 22792 / 29559 Next

Spatial overlay vs. extract and aggregation methods

P.S I found a solution which involves overlay and is faster than raster and
extract functions. I think it may be useful in situations when you try to
aggregate (many) small units over boundaries of some larger units,
conditioned on smaller units being completely nested within larger ones
(i.e there are no cases where a small unit falls in more than one larger
unit). I used this to recalculate boundaries between 2001 and 2011 UK
census, using 2001 Output Areas as spdf1 and electoral boundaries 2011 as
spdf2.

1) calculate centroids for spdf1, overlay with spdf2

nc.sids <- readShapeSpatial(system.file("shapes/sids.shp",
package="maptools")[1],
                            IDvar="FIPSNO", proj4string=CRS("+proj=longlat
+ellps=clrk66"))

nc.sids <- nc.sids[c("FIPSNO", "NAME" ,"BIR74")]

centroids = gCentroid(nc.sids,byid=TRUE)
overlay<-over(centroids, nc.sids)
sapply(over(nc.sids, geometry(centroids), returnList = TRUE), length)

vect<-(overlay[[1]])
for (i in 1:length(vect)){
  nc.sids$overlay[i]<-vect[i]
}

aggregated<-tapply(nc.sids at data$BIR74, nc.sids at data$overlay, sum)
cor(nc.sids at data$BIR74, aggregated)




On Tue, Apr 28, 2015 at 1:47 PM, Edzer Pebesma <
edzer.pebesma at uni-muenster.de> wrote:

            

  
  
Message-ID: <CAHMizkO4Hz0e8DAakEYWuSdL99uGrNSV+0REJBFOahhyZ_K4ow@mail.gmail.com>
In-Reply-To: <953e32ee-c98c-4dac-8113-290d30054b5f@HUB02.ad.oak.ox.ac.uk>