The deldir
package in R is a powerful tool for performing Delaunay triangulations and generating Voronoi diagrams. It is useful for spatial analysis and geometric modeling. In this article, I will provide an overview of its functionalities, how to use them, and an explanation of the concepts of Delaunay triangulation and Voronoi diagrams.
Voronoi Diagram:
A Voronoi diagram divides space into regions, where each region corresponds to a point in a set of points. All points within a region are closer to the corresponding point than to any other point.
Delaunay Triangulation:
Delaunay triangulation is a triangulation of a set of points that maximizes the minimum angle of all the triangle's angles, avoiding "thin" triangles. Each triangle has a circumscribed circle that does not contain other points in the set.
First, install and load the deldir package:
install.packages("deldir")
library(deldir)
The primary function to perform Delaunay triangulation and create a Voronoi diagram:
voronoi_data <- deldir(x, y)
Where x
and y
are vectors containing the coordinates of the points.
Extract Voronoi cells from the deldir object:
tiles <- tile.list(voronoi_data)
Plot the Voronoi diagram and/or the Delaunay triangulation:
plot(voronoi_data)
Converting to SpatialLinesDataFrame
:
tile.list
function is used to convert the voronoi_data
object into a list of polygons, where each polygon represents a Voronoi cell.voronoi_lines
list is created to store the polygon lines.Creating the SpatialLinesDataFrame
Object:
voronoi_tiles
list.voronoi_lines
list as a Lines
object.SpatialLines
object and finally into a SpatialLinesDataFrame
, with line IDs assigned automatically.Creating the Leaflet Mapa
library(leaflet)
map <- leaflet() %>%
addTiles() %>%
addProviderTiles(providers$Esri.WorldImagery) %>%
addCircles(lng = ignition_points$LONGITUDE, lat = ignition_points$LATITUDE, radius = 500, color = "red", fill = TRUE, fillOpacity = 0) %>%
addPolylines(data = voronoi_spdf, color = "yellow", weight = 1)
map
tile.list
converts the voronoi_data
object into a list of polygons, with each polygon representing a Voronoi cell.voronoi_lines
list as a Lines
object.SpatialLines
object and finally into a SpatialLinesDataFrame
, with IDs assigned automatically.addTiles()
to add a default set of base tiles.addProviderTiles(providers$Esri.WorldImagery)
.The map is displayed using the map
object, providing a clear visualization of the Voronoi diagram overlaid on a satellite map.
Ronaldo brings decades of expertise to the field of geotechnology. Now, he's sharing his vast knowledge through exclusive courses and in-depth e-books. Get ready to master spatial and statistical analysis techniques, and raise your professional level.