I have a set of points in .shp (ESRI, available here: http://ulozto.cz/xGqRVFrR/voronoi-zip). I would like to calculate Voronoi tesselation from the points, thus create polygons. So far, so good. However, points attribute table is not transferred automatically in R to Voronoi tesselation polygons during calculation (as is the case in ArcGIS).
Thus, depending points' spatial location I want to add points' attributes to my new Voronoi's polygons. I tried to used function
over(diagram.poly, bod.sp)
but it creates data.frame, not polygon.
Please,
- how to automatically add points' attributes to Voronoi polygon OR
- how to use resulting data.frame as my polygon's attribute table?
I'm sure it is pretty trivial task but I still can't find my answer!
my code:
# exemple with my data
library(spatstat)
library(sp)
library(deldir)
library(rgdal)
library(maptools)
# set directory
wd<- setwd("C:/Users/***/voronoi")
# read point shp, considered as SpatialPointsDataFrame
bod<-readOGR(dsn=setwd("C:/Users/***/voronoi"), layer="voronoi_tess")
# convert firstly to ppp (Spatial point pattern (object of class "ppp")
bod.ppp<-as.ppp(bod)
# calculate Voronoi tesselation
diagram<-dirichlet(bod.ppp)
# convert diagram to SpatialPolygon
diagram.poly=as(diagram, "SpatialPolygons")
# use CRS from "bod"
proj=CRS(proj4string(bod))
# define diagram CRS
proj4string(diagram.poly)=proj
# check if projections are identical
identical(proj4string(bod), proj4string(diagram.poly))
# plot the result
plot(diagram.poly, border = "darkgrey")
points(bod, col = "red", pch = 16)
# try to apply over{sp} function, producing data.frame
over(diagram.poly, bod)