# Count the number of points in each Voronoi polygon

I have a Data.frame consisting of Longitude and Latitude called Points1, with which I use Voronoi polygon. I also have another Data.frame of Longitude and Latitude called Points2.

I then want to count the number of occurences of Points2 in each Voronoi Polygon. Regarding the plot, I want to count the occurences of triangles in each Polygon. Sample code:

``````library("deldir")
Points1 <- data.frame(x=runif(10), y=runif(10))
Points2 <- data.frame(x=runif(100), y=runif(100))
x=Points1\$x
y=Points1\$y

vtess <- deldir(x, y)

plot(x, y, type="n", asp=1)
points(x, y, pch=20, col="red", cex=0.5)
points(Points2\$x,Points2\$y,pch=2)
plot(vtess, wlines="tess", wpoints="none", number=FALSE, add=TRUE, lty=1)
``````
• Note that voronoi/delaunay/dirichlet operations from deldir (or spatstat) with lat-long coordinates assume the lat-longs to be a cartesian coordinate system, not spherical coordinates. In a small area, convert to a local metric coordinate system. Aug 6 '18 at 21:44

You can do this using `dirichlet` from `spatstat` package and then `quadratcount`:
``````> library(spatstat)