title: How to coarse grain xy coordinates
body: <p>I have an xy array of gps coordinates that are not evenly sampled. That seems obvious but I would like to project it onto a grid. Here is my script for the context:</p>
  
  <pre><code>import numpy as np
  from matplotlib.mlab import griddata
  
  gps_track = np.array([[0,0],[1.2,2.3],[1.9,3],[3.2,4.3],[4,2.9],[6.5,3.1]])
  x = gps_track[:,0]
  y = gps_track[:,1]
  
  # define grid
  binsize = 1
  xmin, xmax = x.min(), x.max()
  ymin, ymax = y.min(), y.max()
  xi = np.arange(xmin, xmax+binsize, binsize)
  yi = np.arange(ymin, ymax+binsize, binsize)
  </code></pre>
  
  <p>How do I proceed from here to get the (xnew, ynew) values interpolated on the (xi, yi) grid given the (x, y) original coordinates?</p>
  
  <pre><code># grid the data
  xnew, ynew = grid(x, y, xi, yi)
  </code></pre>
  
  <p>I thought I would use something similar to the matplotlib function griddata:</p>
  
  <pre><code>zi = griddata(x, y, z, xi, yi)
  </code></pre>
  
  <p>Which I can't do; I want to grid the coordinates themselves, not the value z = f(x,y). Do you know of any fast solution that would do it?</p>
  
  <p>EDIT:
  It really helps. You guys rock! To be more accurate in my request, I have taken the plot you've generated and marked the (xnew, ynew) samples I am expecting to get with hollow circles. They fall on the (xi, yi) grid.</p>
  
  <p><img src="https://i.stack.imgur.com/ViC8E.png" alt="enter image description here"></p>