1

Using the python console in QGis, I would like to interpolate several point files (txt x,y,z) to make rasters.

I have been trying this but it's not working and I don't know enough about python to make it work.

import qgis.core
import qgis.analysis

uri="file:///C:/test.txt?delimiter=,&xField=field_1&yField=field_2&crs=epsg:32755"
layer = QgsVectorLayer(uri, 'test', "delimitedtext")
layer_data = qgis.analysis.QgsInterpolator.LayerData()
layer_data.vectorLayer = layer
layer_data.zCoordInterpolation=False
layer_data.interpolationAttribute =2
layer_data.mInputType = 0


tin_interpolator = QgsTINInterpolator([layer_data])

export_path = "C:/test.asc"

rect = layer.extent()
res = 10
ncol = int( ( rect.xMaximum() - rect.xMinimum() ) / res )
nrows = int( (rect.yMaximum() - rect.yMinimum() ) / res)
output = QgsGridFileWriter(tin_interpolator,export_path,rect,ncol,nrows,res,res)
output.writeFile(True)

I keep getting this error: Traceback (most recent call last): File "", line 1, in File "C:/test.py", line 13, in tin_interpolator = QgsTINInterpolator([layer_data]) NameError: name 'QgsTINInterpolator' is not defined

Can anyone explain what this variable means layer_data.zCoordInterpolation=False, and whether I should put this to True?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Nuttieke
  • 85
  • 5
  • Have a read of https://gis.stackexchange.com/questions/103506/how-to-call-the-interpolation-plugin-from-the-python-console and see if that helps. – Michael Stimson Mar 14 '18 at 04:19
  • Yes, that's where I got most of the script from, but it's not working and I'm not sure how to fix it. Thanks – Nuttieke Mar 14 '18 at 06:08

1 Answers1

1

The error is due to the import statement, replace:

tin_interpolator = QgsTINInterpolator([layer_data])

with:

tin_interpolator = qgis.analysis.QgsTINInterpolator([layer_data])
Oscar Campo
  • 556
  • 2
  • 17