[GRASS5] counting number of vector points in same position?

Markus Neteler neteler at itc.it
Thu Aug 11 09:50:07 EDT 2005


On Wed, Aug 10, 2005 at 07:21:12PM +0200, Roger Bivand wrote:
> On Wed, 10 Aug 2005, Markus Neteler wrote:
> 
> > Hi,
> > 
> > I have to transform a vector points map of disease reports.
> > Often more than one report falls into the same location as
> > reports were done/geocoded based on cities. This results into
> > a vector map with often several vector falling into the
> > same coodinate pair.
> > 
> > I have to transform this map into a new vector map with
> > single point per coordinate pair and number of cases as
> > attribute.
> > 
> > How to do that?
> > 
> > I was thinking of v.distance -a to calculate zero-distances.
> > This requires to exclude that the points "see" themselves.
> > But then, I am not sure how to transform this into a map.
> > Maybe with some SQL fun (distinct() operator or so)?
> > 
> > Suggestions welcome. This functionality appears to me to
> > be needed for GRASS. I darkly remember that it was asked
> > time ago, but cannot find the mail(s).
> > 
> 
> If you can move the points into R:
> 
> > xcoord <- runif(300)
> > ycoord <- runif(300)
> > reps <- 1+rbinom(300, 3, 0.3)
> > table(reps)
> reps
>   1   2   3   4 
>  96 132  66   6 
> > crds <- cbind(rep(xcoord, reps), rep(ycoord, reps))
> > crds_s <- crds[sample(nrow(crds)),]
> 
> replicates your problem, here 582 points for 300 unique locations, in 
> random order.
> 
> > u_crds_s <- unique(crds_s)
> > cnts <- integer(nrow(u_crds_s))
> > for (i in 1:nrow(u_crds_s)) cnts[i] <- length(which(apply(crds_s, 1, 
> +   function(x) identical(x, u_crds_s[i,]))))
> > table(cnts)
> cnts
>   1   2   3   4 
>  96 132  66   6 
> > res <- cbind(u_crds_s, cnts)
> 
> then export res back to GRASS maybe as a shapefile. If the coordinates 
> have ID tags, matching would be easier, but this works for non-fuzzy 
> coordinates. If the coordinates need snapping, all.equal() with a 
> tolerance could be used instead of identical, but it is much slower.
> 
> Hope this helps,

Thanks, Roger.

I have tried your example successfully. On the (new) destination
machine I still have to install R to perform it there.

Markus




More information about the grass-dev mailing list