| 1 |
""" |
| 2 |
.. _topo_map_example: |
| 3 |
|
| 4 |
Topographic Map |
| 5 |
~~~~~~~~~~~~~~~ |
| 6 |
|
| 7 |
This is very similar to the :ref:`texture_example` example except it is |
| 8 |
focused on plotting aerial imagery from a GeoTIFF on top of some topography |
| 9 |
mesh. |
| 10 |
|
| 11 |
""" |
| 12 |
|
| 13 |
# sphinx_gallery_thumbnail_number = 4 |
| 14 |
import matplotlib as mpl |
| 15 |
import matplotlib.pyplot as plt |
| 16 |
import pyvista as pv |
| 17 |
from pyvista import examples |
| 18 |
|
| 19 |
# %% |
| 20 |
# Start by loading the elevation data and a topographic map. |
| 21 |
|
| 22 |
# Load the elevation data as a surface |
| 23 |
topo = examples.download_crater_topo().resample(0.5, anti_aliasing=True) |
| 24 |
elevation = topo.warp_by_scalar() |
| 25 |
# Load the topographic map from a GeoTiff |
| 26 |
topo_map = examples.download_crater_imagery() |
| 27 |
topo_map.to_image().resample(0.5, anti_aliasing=True, inplace=True) |
| 28 |
topo_map = topo_map.flip_y() # flip to align to our dataset |
| 29 |
|
| 30 |
elevation |
| 31 |
|
| 32 |
# %% |
| 33 |
# Let's inspect the imagery that we just loaded. |
| 34 |
|
| 35 |
mpl.rcParams['figure.dpi'] = 500 |
| 36 |
plt.imshow(topo_map.to_array()) |
| 37 |
|
| 38 |
|
| 39 |
# %% |
| 40 |
# Once you have a topography mesh loaded as a surface mesh |
| 41 |
# (we use a :class:`pyvista.StructuredGrid` here) and an image loaded as a |
| 42 |
# :class:`pyvista.Texture` using :func:`pyvista.read_texture`, |
| 43 |
# then you can map that imagery to the surface mesh as follows: |
| 44 |
|
| 45 |
# Bounds of the aerial imagery - given to us |
| 46 |
bounds = (1818000, 1824500, 5645000, 5652500, 0, 3000) |
| 47 |
# Clip the elevation dataset to the map's extent |
| 48 |
local = elevation.clip_box(bounds, invert=False) |
| 49 |
# Apply texturing coordinates to associate the image to the surface |
| 50 |
local.texture_map_to_plane(use_bounds=True, inplace=True) |
| 51 |
|
| 52 |
# %% |
| 53 |
# Now display it. Note that the imagery is aligned as we expect. |
| 54 |
local.plot(texture=topo_map, cpos='xy') |
| 55 |
|
| 56 |
# %% |
| 57 |
# And here is a 3D perspective. |
| 58 |
local.plot(texture=topo_map) |
| 59 |
|
| 60 |
# %% |
| 61 |
# We could also display the entire region by extracting the surrounding region |
| 62 |
# and plotting the texture mapped local topography and the outside area |
| 63 |
|
| 64 |
# Extract surrounding region from elevation data |
| 65 |
surrounding = elevation.clip_box(bounds, invert=True) |
| 66 |
|
| 67 |
# Display with a shading technique |
| 68 |
pl = pv.Plotter() |
| 69 |
pl.add_mesh(local, texture=topo_map) |
| 70 |
pl.add_mesh(surrounding, color='white') |
| 71 |
pl.enable_eye_dome_lighting() |
| 72 |
pl.camera_position = pv.CameraPosition( |
| 73 |
position=(1831100.0, 5642142.0, 8168.0), |
| 74 |
focal_point=(1820841.0, 5648745.0, 1104.0), |
| 75 |
viewup=(-0.435, 0.248, 0.865), |
| 76 |
) |
| 77 |
pl.show() |
| 78 |
# %% |
| 79 |
# .. tags:: plot |