【问题标题】:Interpolation points data into 2-d shapefile with matplotlib使用 matplotlib 将数据插值到二维 shapefile
【发布时间】:2016-12-24 17:44:44
【问题描述】:

背景

用包含latlonconc(部分空气污染物浓度)的点csv数据代表监测点,我想将原始点数据插值成二维分布图。

这是我原来的点分布,是覆盖中国的空气质量监测网络。

颜色由每个监控站点的具体值决定。

我已经上传了csv数据here,有兴趣的可以下载。

散点的不同颜色表示这些站点之间的不同值。

shapefile可以下载here

我的尝试

为了实现从这些数据中获取二维分布图的目标,我使用了 scipy.interpolate 方法。

df = pd.read_csv("./the data file")
xt,yt = df["lon"].values, df['lat'].values
zt =  df['value'].values
hfunc = interpolate.interp2d(xt,yt,zt)

xx = np.linspace(110, 120, 40)
yy = np.linspace(25,45, 40)
sh = (40*40,2)
grids = np.zeros(40*40*2).reshape(*sh)
k = 0
for j in range(0,yy.shape[0],1):
    for i in range(0,xx.shape[0],1):
        grids[k] = np.array([xx[i],yy[j]])
        k+=1
xx,yy = zip(*grids)
CONC = np.zeros(len(xx))
for i,(x,y) in enumerate(zip(xx,yy)):
    CONC[i] = hfunc(x,y)

CONC = CONC.reshape(40,40) 

我已经测试了hfunc,但是有些值大于40000。原始最大值不大于400。我认为我的代码中一定有错误。

一个地方比任何地方都大。

任何建议或指导将不胜感激!

【问题讨论】:

    标签: python matplotlib gis interpolation


    【解决方案1】:

    您应该能够使用docs 中描述的 scipy griddata 函数。

    例如:

    from scipy.interpolate import griddata
    
    CONC = gridddata((xt,yt), zt, (xx, yy), method='cubic')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-06
      • 2017-04-28
      • 2013-02-16
      相关资源
      最近更新 更多