如何根据已知的坡度和坡向值生成二维数组?
Given a dummy heightmap (or digital elevation model) stored as a Numpy array like this:
import numpy as np
import matplotlib.pyplot as plt
line = np.flip(np.arange(0, 10))
dem = np.tile(line, (10, 1))
I can calculate its slope and aspect like this:
x, y = np.gradient(dem)
slope = np.degrees(np.arctan(np.sqrt(x**2 + y**2)))
aspect = np.degrees(np.arctan2(x, -y))
And visualise it:
fig = plt.figure()
ax = fig.add_subplot(111, projection="3d")
y, x = np.mgrid[:10, :10]
ax.scatter(x, y, dem)
ax.set_title(f"Slope={np.mean(slope)}, Aspect={np.mean(aspect)}")
But how would I go the other way?
我想生成一个固定尺寸的空白2D numpy阵列,然后用遵循已知斜率和方面的值填充(从任意高程开始,例如0)。
Given a dummy heightmap (or digital elevation model) stored as a Numpy array like this:
import numpy as np
import matplotlib.pyplot as plt
line = np.flip(np.arange(0, 10))
dem = np.tile(line, (10, 1))
I can calculate its slope and aspect like this:
x, y = np.gradient(dem)
slope = np.degrees(np.arctan(np.sqrt(x**2 + y**2)))
aspect = np.degrees(np.arctan2(x, -y))
And visualise it:
fig = plt.figure()
ax = fig.add_subplot(111, projection="3d")
y, x = np.mgrid[:10, :10]
ax.scatter(x, y, dem)
ax.set_title(f"Slope={np.mean(slope)}, Aspect={np.mean(aspect)}")
But how would I go the other way?
I'd like to generate a blank 2D Numpy array of a fixed size, then fill it with values that follow a known slope and aspect (starting from an arbitrary elevation e.g. 0).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于
gradient
假设步长为1,因此用N
点和给定slope
和offset<制作一条线的一般公式/code>
所谓的斜率是梯度的大小,以角度的形式给出。您所说的坡向是 x 和 y 方向上部分坡度的比率,也以角度形式给出。您有以下非线性方程组:
幸运的是,您可以使用替换轻松解决此问题:
现在您需要做的就是取斜率
sx
和的两条线的外部总和sy
:这是一个示例:
输入:
渐变:
结果:
您的约定可能会因某个标志而偏离,您应该能够通过查看轻松修复该约定情节。
Since
gradient
assumes a step size of 1, the general formula for making a line withN
points and a givenslope
andoffset
isWhat you call Slope is the magnitude of the gradient, given as an angle. What you call Aspect is the ratio of partial slopes in the x- and y-directions, also given as an angle. You have the following system of non-linear equations:
Luckily, you can solve this pretty easily using substitution:
Now all you need to do is take the outer sum of two lines with slopes
sx
andsy
:Here is an example:
Inputs:
Gradient:
Result:
Your conventions may be off by a sign, which you should be able to fix easily by looking at the plot.