-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
11 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
assign_voro <- function(pop, centers, crs) { | ||
pob_s <- SpatialPoints(pop[ ,1:2], proj4string = crs)## transform pop to spatial object | ||
centers_s <- SpatialPoints(centers[ ,1:2], crs)## transform centers to spatial object | ||
VP_centers1 <- voronoipolygons(centers_s, crs)## generate voronoipoligons of centers | ||
centers$poligono <- over(VP_centers1, centers_s, returnList = FALSE)## assign centers info to voronoipoligons | ||
ab <- as.data.frame(over(pob_s, VP_centers1))## intersects the population with the voronoi polygons of the centers | ||
names(ab) <- "poligono" | ||
pop <- cbind(pop, ab) | ||
pop <- merge(pop, centers, by = "poligono") | ||
pop <- rename(pop[ ,!colnames(pop)=="poligono"], c(x.x="x_pop",y.x="y_pop",x.y="x_center",y.y="y_center")) | ||
} |