1

I have a relatively large (spatially) irregular grid. It consists of multiple curvilinear grids (see example) of which I have all the x, y coordinates and the z-value (height) of the individual cells.

These cells can be in the order of 50m x 50m.

I would like to interpolate this to a 1m x 1m grid, how would one do such a thing efficiently in python?

If possible I would like to not create a grid which also spans the regions without grid cells since I think it is likely that the interpolated dataset will be quite large.

grid example

EDIT: tried to do 2D interpolation in python but cant get it to work I found this script: http://scipy-cookbook.readthedocs.io/items/Matplotlib_Gridding_irregularly_spaced_data.html

From this example I tried to do the same but get only nan values. The script:

XZ2 = XZ[XZ != 0.].ravel()
YZ2 = YZ[YZ != 0.].ravel()
dps2 = dps[XZ != 0.].ravel()

# define grid.
xi = np.arange(math.floor(min(XZ2)), math.ceil(max(XZ2))+1, 1)
yi = np.arange(math.floor(min(YZ2)), math.ceil(max(YZ2))+1, 1)

# grid the data.
zi = griddata((XZ2, YZ2), dps, (xi[None,:], yi[:,None]), method='linear')

Any idea why?

I didn't do it in QGis because I feel I should be able to do this in python..

Thanks

Yorian
  • 2,002
  • 5
  • 34
  • 60
  • Looks like a good use case for quantum gis (where you can easily do boolean operations with polygons), you are likely to get a better answer crossposting this to http://gis.stackexchange.com/ – Paulo Scardine Nov 24 '16 at 15:51
  • I understand QGIS is also written in python, but I do need to do this interpolation on a very regular basis (i.e. automated), wouldn't it be better to do this with Scipy or numpy in python? – Yorian Nov 24 '16 at 15:56
  • See [Running and Scheduling QGIS Processing Jobs](http://www.qgistutorials.com/en/docs/running_qgis_jobs.html), if it is not enough then yes, do it using Scipy. – Paulo Scardine Nov 24 '16 at 16:04
  • Possible duplicate of [Interpolation over an irregular grid](https://stackoverflow.com/questions/3242382/interpolation-over-an-irregular-grid) – Till Hoffmann Dec 23 '17 at 13:00
  • @TillHoffmann Not really since I wanted to interpolate to a rectangular grid but had difficulty with the size of the grid to interpolate to, where as the question you are citing does not look for a solution to create a rectangular grid. Anyways, I accepted the shortcoming of the computer and solved by interpolating to a 5m x 5m grid instead. – Yorian Dec 27 '17 at 12:32

1 Answers1

1

The script above does work, it just creates lots of nan values, giving the impression that the result is incorrect..

Yorian
  • 2,002
  • 5
  • 34
  • 60