# [R-sig-Geo] polygon intersecting with point question

rundel rundel at gmail.com
Sat Dec 11 06:52:26 CET 2010

```One quick suggestion I have is when you use the gBuffer function use
byid=TRUE as this will result in three separate polygons and not one
multipolygon. This is true for all of the rgeos functions, byid indicates if
the input object should be treated as a geometry collection (when FALSE) or
as a multigeometry (when TRUE).

In order to get the number of point intersections with each geometry you can
also use rgeos and the gIntersects function. An example of something
similar:

library(rgeos)
pts = SpatialPoints(data.frame(x=c(1,1,2,2),y=c(1,2,1,2)))
polys = gBuffer(pts,byid=TRUE,width=0.45,quadsegs=10)

plot(c(0,3),c(0,3),type='n')
plot(polys)
plot(pts,pch=names(polys),add=T) #Label polygons

set.seed(0)
x=runif(25,0,3)
y=runif(25,0,3)
rand.pts = SpatialPoints(data.frame(x=x,y=y))

plot(rand.pts,add=T)

# this is a logical matrix indicating which polygons intersect with which
points
its = gIntersects(polys,rand.pts,byid=TRUE)

# summing over the columns gives us the number of points that intersect with
each polygon
apply(its,2,sum)

-Colin
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/polygon-intersecting-with-point-question-tp5821233p5825458.html
Sent from the R-sig-geo mailing list archive at Nabble.com.

```

More information about the R-sig-Geo mailing list