VTK Learning Thirty-two - pyvista Topographic Map

影像疊加地形圖

  • 拉伸地形圖
    elevation = elevation_dataobj.warp_by_scalar() 地形圖按照高程屬性拉伸成曲面
  • 貼紋理
topo_map = pv.read_texture(image_filename)
# 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)

Code

"""
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

# load data from file
elevation_filename="D:\\codelearnning\\vtk-data-master\\Data\\Ruapehu_mag_dem_15m_NZTM.vtk"
elevation_dataobj= pv.read(elevation_filename, file_format=None)
print(elevation_dataobj.bounds)
print(elevation_dataobj.get_data_range())
print(elevation_dataobj.array_names)
# Load the elevation data as a surface
elevation = elevation_dataobj.warp_by_scalar()
# Load the topographic map from a GeoTiff
image_filename="D:\\codelearnning\\vtk-data-master\\Data\\BJ34_GeoTifv1-04_crater_clip.tif"
topo_map = pv.read_texture(image_filename)
###############################################################################
# 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
# :class:`pyvista.Texture` object using the :func:`pyvista.read_texture`
# method, then you can map that imagery to the surface mesh as follows:

# 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)

###############################################################################
# Now display it! Note that the imagery is aligned as we expect.
local.plot(texture=topo_map, cpos="xy")

###############################################################################
# And here is a 3D perspective!
local.plot(texture=topo_map)

###############################################################################
# We could also display the entire region by extracting the surrounding region
# and plotting the texture mapped local topography and the outside area

# 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., 5642142., 8168.),
                     (1820841., 5648745., 1104.),
                     (-0.435, 0.248, 0.865)]
p.show()

在這裏插入圖片描述

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章