1

I have a set of projected spatial points (x,y,id,dist,value) that needs to be filtered. For each point I have to find the other ones falling within a variable distance. For each selection, I need only those with the maximum value or, if duplicated, keeping just one. How is it possible to achieve this or how can I implement this kind of selection on the following R code? I'm working on QGIS, so R or Python suggestions will be more useful.

##Layer=vector
##ID=Field Layer
##distance= Field Layer
##Output= output vector
library(rgeos)
library(sp)
library(spdep)

coordi <- as.matrix(coordinates(Layer))
tram_nb <- dnearneigh(coordi, d1 = 0, d2 = distance,row.names=Layer[[ID]])
tram_nb<-as.data.frame(card(tram_nb))
tram<-cbind(as.vector(Layer[[ID]]), tram_nb)
Coord<-cbind()
n<-length(Layer[[ID]])
for(i in 1:n){
   if (tram[i,2]!=0 ){ Coord <-rbind(Coord,cbind(coordi[i,1], coordi[i,2],as.vector(Layer[[ID]])[i]))
}
}
x<-as.numeric(Coord[,1])
y<-as.numeric(Coord[,2])
X<-cbind(x,y)
matrix<-as.matrix(X)
matrix<-SpatialPointsDataFrame(matrix,as.data.frame(Coord),proj4string=CRS(Layer))
Output=matrix

Here some data:

ID; XCOORD; YCOORD; dist_m; value
0;789027.250000;5185814.750000;2.283;15.981
1;789018.250000;5185815.250000;2.479;17.353
2;789018.750000;5185815.250000;2.479;17.353
3;789031.250000;5185815.250000;3.494;24.458
4;789031.750000;5185815.250000;3.494;24.458
5;789025.750000;5185815.750000;2.426;16.982
6;789026.750000;5185815.750000;2.446;17.122
7;789021.750000;5185816.750000;3.485;24.395
8;789022.250000;5185816.750000;3.485;24.395
9;789018.750000;5185817.250000;2.450;17.150
10;789019.250000;5185817.250000;2.450;17.150
11;789021.750000;5185817.250000;3.485;24.395
12;789022.250000;5185817.250000;3.485;24.395
13;789022.750000;5185817.250000;3.485;24.395
14;789018.750000;5185817.750000;2.450;17.150
15;789019.250000;5185817.750000;2.450;17.150
16;789020.750000;5185818.250000;2.485;17.395
17;789028.250000;5185818.250000;1.777;12.439
18;789029.250000;5185818.750000;1.816;12.712
19;789016.250000;5185819.750000;3.267;22.869
20;789024.750000;5185820.250000;2.044;14.308
21;789021.250000;5185821.250000;2.910;20.370
22;789016.250000;5185821.750000;3.564;24.948
23;789028.750000;5185822.750000;3.771;26.397
24;789029.250000;5185822.750000;3.771;26.397
25;789020.750000;5185823.250000;3.298;23.086
26;789021.750000;5185824.250000;3.519;24.633
27;789016.750000;5185824.750000;3.060;21.420
28;789021.250000;5185824.750000;3.519;24.633
29;789021.750000;5185824.750000;3.519;24.633
30;789029.250000;5185824.750000;3.336;23.352
31;789029.250000;5185825.750000;2.370;16.590
32;789029.250000;5185826.750000;2.604;18.228
33;789019.750000;5185829.250000;3.713;25.991
34;789019.750000;5185829.750000;3.713;25.991
35;789031.750000;5185830.250000;3.394;23.758
36;789023.750000;5185830.750000;4.327;30.289
37;789023.750000;5185831.250000;4.327;30.289
  • This is a simple problem, but you do not provide (create) example data, so how can I show you how to solve it? – Robert Hijmans Jun 9 '16 at 17:48
  • @RobertH I updated the post with some data – Nico Jun 17 '16 at 9:02

Your Answer

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

Browse other questions tagged or ask your own question.