[Qgis-user] Find and filter points within a variable radius

Niccolò Marchi sciurusurbanus at hotmail.it
Fri Aug 12 04:18:54 PDT 2016


Hi all,

I have a set of projected spatial points (id, x, y, 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 the one with the maximum value or, if duplicated, keeping just one.

I tried to check the available tools and I found out what follows:

-          A simpler possibility would be to use the “Select by expression”, but I’m not that familiar with the syntax and I ended up with [clearly non-working]: CASE WHEN distance($currentfeature)<”dist” THEN max(“value”) END

-          Another possibility would be to improve the following R code, available online (thanks to the author)

Any (R, Python, else) suggestion?





##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

Thank you in advance for your help!

All the best,

Nic








-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20160812/232e8805/attachment.html>


More information about the Qgis-user mailing list