将U和V矢量文件另存为形状文件(.shp)

时间:2018-04-10 06:01:29

标签: python numpy matplotlib shapefile

我有四个二维数组由一个向量的u,v分量和相应的坐标组成。我可以通过'箭头图'绘制这些矢量,并能够保存为png,jpg等。但我想将其保存为矢量文件(.shp,.evf等)。为了理解,我创建了两个示例u和v向量并绘制我想保存为shapefile的结果。我试过,但没有找到运气与pyshp python包。

import numpy as np
import matplotlib.pyplot as plt

u = np.zeros(shape=(4,4))
u[0] = [0.0,0.5,0.4,0.1]
u[1] = [0.2,0.4,-0.2,0.3]
u[2] = [0.3,0.0,0.4,0.1]
u[3] = [0.6,0.4,0.2,0.3]

v = np.zeros(shape=(4,4))
v[0] = [-0.4,0.3,0.0,0.1]
v[1] = [0.1,0.3,0.2,0.4]
v[2] = [0.4,0.3,0.3,0.1]
v[3] = [0.0,0.1,0.3,0.2]

x,y = np.meshgrid(np.linspace(0,3,4), np.linspace(3,0,4))

plt.figure();
plt.title('Velocity Field')
plt.xlim(-1,4)
plt.ylim(-1,4)
plt.quiver(x, y, u, v, color='r', scale = 1, angles = 'xy', units='xy', scale_units='xy') 
plt.show()
#plt.savefig('sample.png', dpi=150, bbox_inches='tight', pad_inches=0)

非常感谢任何帮助/建议。

0 个答案:

没有答案