import numpy as np import pyvista as pv from pyvista import examples from vtk.util.numpy_support import vtk_to_numpy from dash_vtk.utils import presets random.seed(42) def toDropOption(name): return {"label": name, "value": name} # Get point cloud data from PyVista uniformGrid = examples.download_crater_topo() subset = uniformGrid.extract_subset((500, 900, 400, 800, 0, 0), (5, 5, 1)) def updateWarp(factor=1): terrain = subset.warp_by_scalar(factor=factor) polydata = terrain.extract_geometry() points = polydata.points.ravel() polys = vtk_to_numpy(polydata.GetPolys().GetData()) elevation = polydata["scalar1of1"] min_elevation = np.amin(elevation) max_elevation = np.amax(elevation) return [points, polys, elevation, [min_elevation, max_elevation]] points, polys, elevation, color_range = updateWarp(1)
In this example, we demonstrate a simple way to make a 3D grid/mesh that follows a given topographic surface. In this example, it is important to note that the given digital elevation model (DEM) is structured (gridded and not triangulated): this is common for DEMs. """ import numpy as np # sphinx_gallery_thumbnail_number = 3 import pyvista as pv from pyvista import examples ############################################################################### # Download a gridded topography surface (DEM) dem = examples.download_crater_topo() dem ############################################################################### # Now let's subsample and extract an area of interest to make this example # simple (also the DEM we just load is pretty big). # Since the DEM we loaded is a :class:`pyvista.UniformGrid` mesh, we can use # the :func:`pyvista.UniformGridFilters.extract_subset` filter: subset = dem.extract_subset((500, 900, 400, 800, 0, 0), (5, 5, 1)) subset.plot(cpos="xy") ############################################################################### # Now that we have a region of interest for our terrain following mesh, lets # make a 3D surface of that DEM: terrain = subset.warp_by_scalar() terrain
""" Topographic Map ~~~~~~~~~~~~~~~ This is very similar to the :ref:`ref_texture_example` example except it is focused on plotting aerial imagery from a GeoTIFF on top of some topagraphy mesh. """ # sphinx_gallery_thumbnail_number = 4 import pyvista as pv from pyvista import examples # Load the elevation data as a surface elevation = examples.download_crater_topo().warp_by_scalar() # Load the topographic map from a GeoTiff topo_map = examples.download_crater_imagery() elevation ############################################################################### # Let's inspect the imagery that we just loaded import matplotlib.pyplot as plt import matplotlib as mpl mpl.rcParams['figure.dpi'] = 500 plt.imshow(topo_map.to_array()) ############################################################################### # Once you have a topography mesh loaded as a surface mesh # (we use a :class:`pyvista.StructuredGrid` here) and an image loaded as a