title: Interpolate irregular 3d data from a XYZ file to a regular grid
body: <p>I have a xyz file containing a lot of 3D coordinates like so:</p>
  
  <pre><code> 370373.771    6535261.431      2.908       
   370373.788    6535261.441      2.911       
   370373.787    6535261.442      2.909       
   370373.809    6535261.449      2.908       
   370373.810    6535261.439      2.909       
   370373.743    6535261.466      2.922       
   370373.584    6535261.455      2.915       
   370373.559    6535261.471      2.898       
   370373.544    6535261.559      2.887       
   370373.552    6535261.538      2.866       
   370373.797    6535261.486      2.876       
   370373.795    6535261.557      2.892       
   ..........    ...........      .....
  </code></pre>
  
  <p>This file is quite dense and irregular, and I would like to interpolate these coordinates on a regular grid with a point each 5m for example.</p>
  
  <p>Here is what I tried so far:</p>
  
  <pre><code>import numpy as np
  from scipy.interpolate import griddata
  
  coord_x = []
  coord_y = []
  coord_z = []
  coord_xy = []
  
  xyzfile = open("xyzfile.txt")
  for line in xyzfile:
      x,y,z = line.split()
      coord_x.append(float(x))
      coord_y.append(float(y))
      coord_xy.append([float(x),float(y)])
      coord_z.append(float(z))
  xyzfile.close()
  
  lon = np.linspace(min(coord_x), max(coord_x), 200)
  lat = np.linspace(min(coord_y), max(coord_y), 200)
  X, Y = np.meshgrid(lon, lat)
  
  grid = griddata(np.array(coord_xy), coord_z, (X, Y), method='nearest')
  </code></pre>
  
  <p>Unfortunately I get an error : </p>
  
  <pre><code>TypeError: only integer arrays with one element can be converted to an index
  </code></pre>
  
  <p>I'm also not sure how to get a 5m spacing between each point in the regular grid. How can I do this ?</p>
  
  <p>Second question, say I have 6 known points on this grid, how to extract the z value on this regular 5m spaced grid for these 6 points.</p>
  
  <p>Thank you</p>