注釈
Go to the end to download the full example code.
地形図#
これは テクスチャを適用する の例と非常に似ていますが,地形メッシュの上にGeoTIFFからの航空画像をプロットすることに焦点を当てています.
from __future__ import annotations
import matplotlib as mpl
import matplotlib.pyplot as plt
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()
topo_map = topo_map.flip_y() # flip to align to our dataset
elevation
先ほど読み込んだイメージを点検してみましょう.
mpl.rcParams['figure.dpi'] = 500
plt.imshow(topo_map.to_array())

<matplotlib.image.AxesImage object at 0x7f6fed5c8890>
サーフェスメッシュ(ここでは pyvista.StructuredGrid
を使います)として地形メッシュをロードし, pyvista.read_texture()
を使用して:class:pyvista.Texture としてイメージをロードしたら,次のようにイメージをサーフェスメッシュにマッピングできます.
# Bounds of the aerial imagery - given to us
bounds = (1818000, 1824500, 5645000, 5652500, 0, 3000)
# Clip the elevation dataset to the map's extent
local = elevation.clip_box(bounds, invert=False)
# Apply texturing coordinates to associate the image to the surface
local.texture_map_to_plane(use_bounds=True, inplace=True)
表示します.イメージが予想どおりに調整されていることに注意してください.
local.plot(texture=topo_map, cpos='xy')

これが3 D遠近法です.
local.plot(texture=topo_map)

また,周辺領域を抽出し,テクスチャマッピングされた局所的な地形と外部領域をプロットすることによって,領域全体を表示することもできます.
# Extract surrounding region from elevation data
surrounding = elevation.clip_box(bounds, invert=True)
# Display with a shading technique
p = pv.Plotter()
p.add_mesh(local, texture=topo_map)
p.add_mesh(surrounding, color='white')
p.enable_eye_dome_lighting()
p.camera_position = [
(1831100.0, 5642142.0, 8168.0),
(1820841.0, 5648745.0, 1104.0),
(-0.435, 0.248, 0.865),
]
p.show()

Total running time of the script: (0 minutes 33.929 seconds)