Let me give a R perspective, if i got the problem correctly. if (!require(sp)) install.packages("sp",repos="http://cran.r-project.org");library(sp) if (!require(maptools)) install.packages("maptools",repos="http://cran.r-project.org");library(maptools) if (!require(ggplot2)) install.packages("ggplot2",repos="http://cran.r-project.org");library(ggplot2) #! == Reading Shapefiles =============== #! === Areas === areas <- readShapeSpatial('D:/R/Areas.shp') #! read shapefile areasCentroids <- data.frame(coordinates(areas)) #! get centroids - just for ploting reasons areasID <- data.frame(areas@data,idI=seq(1:nrow(areas@data))) #! Dataframe com a ordem ads quadículas na shapefile e o respectivo ID (código) str(areasID) #! verify dataframe structure #areasID <- cbind(areasID,areasCentroide) #plot(grelhaID$X1,grelhaID$X2);text(grelhaID$X1,grelhaID$X2,labels=grelhaID$Codigo) #! === Points === houses <- readShapeSpatial('D:/R/Houses.shp') #! read shapefile houses$houseID <- row.names(houses) #! add an ID for each entry of the dataframe plot(areas);plot(houses,add=T);text(areasCentroids,labels=areasID$Name,col="red");text(houses@ coords+8,labels=houses$houseID) #! ploting #! == Overlay ========================== ##Note: #### points on a polygon boundary and points corresponding to a polygon vertex are considered to be #### inside the polygon cross <- overlay(areas, houses);cross$houseID <- row.names(cross) #! Overlay points to areas cross_house <- merge(cross,houses,by="houseID",all=T) #! associate houses data to overlay table cross_house <- cross_house[order(cross_house$Name,cross_house$Year),] #! ordering things cross_house #str(cross_house) #! == Cummulative Sums of houses by area along the years === TNumb <- ddply(cross_house,c("Name", "Year"),summarise,Numb=length(Name)) cum_Sum <- ddply(TNumb, "Name", transform, NT = cumsum(Numb))
|