[R-sig-Geo] Distance-based neighbourhood statistics problem

Gellrich Mario mario.gellrich at env.ethz.ch
Thu Sep 11 12:12:01 CEST 2008


Hi,

I've got a question regarding distance-based neighbourhood statistics using two separate spatial data sets. What I have are municipalities and buildings within municipalities which both come with x- and y-coordinates. I merged the two datasets row-wise and used the following code to obtain aggregated values for the number of builings surrounding a municipality. The code hower doesn't work appropriately. Can anybody help?


d.geb <- read.table("gebaeuderecord_selection_test.csv", header=T, sep=";")
d.geb[1:10,]

     MUNICIP     NAME GEBID NUMBERGEB ABPER    LON    LAT
1          0 Gebaeude  4262         1     1 681864 225868
2          0 Gebaeude 14168         1     7 682190 224294
3          0 Gebaeude 33346         1     5 682176 224354
4          0 Gebaeude 44610         1    15 681571 225189
5          0 Gebaeude 62785         1     1 679800 226040
6          0 Gebaeude 72287         1     1 684619 224239
7          0 Gebaeude 83044         1     8 681701 224818
8          0 Gebaeude 84827         1     2 684878 230975
9          0 Gebaeude 86671         1     0 685733 227247
10         0 Gebaeude 88022         1     1 685691 230548


# Variable description:

# MUNICIP:   zero for buildings; one for municipalities
# NAME   :   if 'Gebaeude' == building; otherwise municipality name
# GEBID:     ID of building; -99 otherwise
# NUMBERGEB: number of buildings - one for each building-record; set to zero if record represents municipality
# ABWOW:     number of flats in a building


### Creates neighbourhood list and should provide aggregates values within a distance of 1 kilometer from a municipality for the variables NUMBERGEB or ABWOW

library(spdep)
geb.nb2   	<- dnearneigh(as.matrix(d.geb[,6:7]), 0, 1, longlat=TRUE)
d.geb$SUMGEB 	<- unlist(lapply(geb.nb2, function(x) ifelse(any(x==0), 0, sum(d.geb$ABPER[x])))) 

subset(d.geb, MUNICIP == 1)


Best regards,

Mario




More information about the R-sig-Geo mailing list