8 Transforming spatial data to 3D forms

8.1 Questions

  • What tools exist to convert data to meshes in R?

8.2 Overview

  • Teaching: 10 min

8.3 Transforming Spatial Data using modular 3D tools

  1. Tell us if you use 3D visualization or meshes in analysis.

This is hard! There’s a few scattered tools.

8.4 On CRAN

  • rgl::triangulate and decido::earcut will triangulate polygons with holes but only suitable for plane-filling, because ugly triangles, no control over size and shape.

  • RTriangle::triangulate (and sfdct::ct_triangulate) do high-quality “near-Delaunay” triangulations

  • quadmesh::quadmesh to create rgl-ready mesh3d from a raster

  • mapview::cubeView does very compelling interactive raster-cube visualization

  • SymbolixAU/mapdeck

  • tylermorganwall/rayshader

Side note: there are many triangulation algorithms and many packages in R, but we need constrained triangulation to preserve all input edges - only a handful can do that, and RTriangle is the king (with a problematic license).

8.5 Quadmesh.

library(quadmesh)
quadmesh(anyRasterDEM, texture = anyRasterRGB)
rgl::shade3d()

## play with aspect3d, light3d, ...

Triangulations, sfdct is no good because it’s very inefficient. sf is simply not suitable for mesh (a.k.a. indexed) forms of data.

8.6 Stuff not on CRAN!

8.7 Triangles or quads in hypertidy (WIP)

This is my work-in-progress approach to meshing any data structure.

## devtools::install_github("hypertidy/anglr")
## devtools::install_github("hypertidy/silicate")
library(anglr)  
triangles <- copy_down(TRI(anySFpolygon), anyRasterDEM)

mesh <- plot3d(triangles)