pyvista-support
pyvista-support copied to clipboard
How to get the Z value of a point on the surface mesh
Description
I have learn pyvista for weeks, it's powerful!
But I don't know how to get the Z value of a point on the surface, for example, I want know the elevation value of a point on a topographic map.
There are some similar approach, such as plot over line
, Ray Tracing
,but both of them can't satisfy the needs.
Example Data
This is an instance
import random
import numpy as np
import pyvista as pv
# create a structured surface
x = np.arange(-10, 10, 0.25)
y = np.arange(-10, 10, 0.25)
x, y = np.meshgrid(x, y)
r = np.sqrt(x ** 2 + y ** 2)
z = np.sin(r)
# get the grid
curvsurf = pv.StructuredGrid(x, y, z)
# get some random points
point_x = [random.uniform(-10,10) for i in range(10)]
point_y = [random.uniform(-10,10) for i in range(10)]
point_xy = np.c_[point_x, point_y]
# how can I get the Z value of points on the surface if we don't know how to generate the grid data?
curvsurf.plot()
You can get all of the nodes of the mesh by the .points
property. The third column are the z values
Does this help? What exactly do you need to get?
You can get all of the nodes of the mesh by the
.points
property. The third column are the z valuesDoes this help? What exactly do you need to get?
You misunderstand. The mesh has a lot of points, and they formed the surface by interpolation. This means they can't mach a random point because they might not have the same x and y coordinate.
So if I got some random points which only have x and y coordinate, and I need to map them onto the surface, I need get the Z values of the points on the surface. This is my question.
In fact, the operation is vary meaningful on a topographic map, because the geology always need to map some lines and surface onto ground and check their tend.
You can get all of the nodes of the mesh by the
.points
property. The third column are the z valuesDoes this help? What exactly do you need to get?
Just like this. The surface under the ground has it's shape and structure, but I want to see it's trend on the topographic map, so I cant analysis height and any other things.
I got some points' coordinate by nurbs interpolation, but they only have x and y coordinate. So I don't know how to map the points onto topographic map.
About this picture, I plot it with pyvista, and I use a blue surface to represent the tend on the ground. But it's not correct and clear.
I'm having a similar issue where I need to get the surface elevation of the mesh at random points. I'm using sample() from the rasterio package to get an elevation but when I try to find_closest_cell, some values are -1 because the elevation doesn't match the surface of my mesh. Wondering if pyvista can do something similar to sample() in the rasterio package. I think this is similar to what Peanutchun is looking for.
Hi! I want to follow up on this issue, as I'm facing the same problem without succeeding. Thanks in advance!
Please open a new discussion at https://github.com/pyvista/pyvista/discussions