# Creating polygon grid of triangles with R?

I wish to create a polygon grid such as the image below.

Is it possible to do with the st_voronoi from SF package using R?

I'm interested in a polygon grid.

Based on mdsummer comments, I want to clarify that I'm seeking just a spatial triangles polygon grid so that I can perform geoprocessing tasks. It would be ideal that it would be denser at the center. • See icosa package. You can't really use sf for this as it's not really going to respect the geocentric coordinates (though it's probably partly possible) You could also use geometry::delaunayn on points distributed on the sphere, here's an example: rpubs.com/cyclemumner/277849 Happy to help but need more information, i.e. why the centre is so much denser, is it denser on the other side as well? – mdsumner May 18 '17 at 15:30
• It is denser in the center because it is applied in a meteorology model that resolves the equations in a continuous model (without borders problem) with higher resolution in some area of interest. Thanks – Sergio May 19 '17 at 16:22
• Is that relevant to the question? Include it with specifics. Do you want that meteorology model specifically, or just "how to create a mesh"? No one can look at that picture and generate that, details are needed. – mdsumner May 20 '17 at 3:02
• You are truth but I actually I want a polygon grid of triangles as a vector. So that I can perform spatial class with SF – Sergio May 20 '17 at 4:13
• This question is not answerable as is then. sf cannot have a connected mesh of triangles in this way. If you provide more details on what you need to do and how then maybe we can help. – mdsumner May 20 '17 at 4:42

Here's a minimal example with the `icosa` package.

``````library(icosa)
g <- icosa::trigrid(tessellation = 6)
plot3d(g, guides = FALSE, sphere = FALSE)
``````

There is a lot to explore here, and you can do almost anything but it won't be obvious at first. The mesh itself is simply vertices in 3D geometry with an accompanying index that links the vertices in triplets. That generic structure can be used more directly by `rgl`, to plot surfaces and can include texture mapped images.

For direct use in rgl, get the vertices and the character-named indexes like this:

``````## geocentric vertices, use output = "polar" for long-lat
v <- vertices(g, output = "")
f <- faces(g)
## note we need to treat the colours in triplets explicitly to match
## the face index
rgl::rgl.triangles(v[t(f), ], col = rep(c("firebrick", "darkgrey", "dodgerblue"), each = 3))
``````

This is a special, regular case of the Delaunay triangulation, which is the same as the convex hull in 3D. The triangulation is a 2D topology represented within a 3D geometric space, and can also be generated with "geometry::convhulln", but icosa provides very good tools for evenly distributed points.

• This approach is quite cool. I generate hexagons and triangles using "spsample" to create points, that act as nodes, and then connect the dots, so to speak. – Jeffrey Evans May 18 '17 at 15:58