I need to write an interpolation script for QGIS. I want use TINInterpolation method from Interpolation plugin. I found class in API documentation but I don't know how to write QList object with attributes for interpolation. This is constructor from QGIS API.

QgsTINInterpolator (const QList< LayerData > &inputData, TIN_INTERPOLATION interpolation=Linear, bool showProgressDialog=false)

I cannot find any code snippet only this API documentation - https://qgis.org/api/classQgsTINInterpolator.html#a81c71e2be210a4b082ea807b0626a1bd

and QList documentation from Qt Api - http://doc.qt.io/qt-4.8/qlist.html#details

I tried to find any other code with QList class but I found only QgsVectorLayer and QgsRasterLayer everytime.

In the documentation is not available in Python bindings it means I can't use it with python or what does it mean? Got this from here: https://qgis.org/api/classQgsInterpolator.html

I'll be very glad for any help.


In QgsInterpolator.LayerData I don't understand why interpolationAttribute is integer. It is number of column? In Interpolation qgis plugin it is a name of column. It is just next question for discussion. Still don't know how to crete LayerData structure.

I got this error:

Traceback (most recent call last): File "", line 1, in TypeError: arguments did not match any overloaded call: QgsInterpolator.LayerData(): too many arguments QgsInterpolator.LayerData(QgsInterpolator.LayerData): argument 1 has unexpected type 'int'

when tried this line of code:

lay = QgsInterpolator.LayerData(8, "BREAK_LINES", layer2, True)

I want interpolate vector line data, then use Contour and select only one value from features, this all in script. I started write code to console, but this was first problem which I have. I never use python object programming just procedural. Basics of object programming should I have from Java but I don't understand that documentation. I don't know what means struct reference in python and how should I use it.


layer = QgsVectorLayer(pathToFile, 'test', "ogr")
ld1 = qgis.analysis.QgsInterpolator.LayerData()
ld1.vectorLayer=layer              #variable with vector layer
ld1.interpolationAttribute=7       #number of column with elevation value
ld1.mInputType=2                   #BREAK_LINES

...next two layers and LayerData object (ld2 and ld3)...

#TIN Interpolation
itp=qgis.analysis.QgsTINInterpolator([ld1, ld2, ld3])

rect = layer.extent()
res = 10
ncol = int( ( rect.xMaximum() - rect.xMinimum() ) / res )
test = qgis.analysis.QgsGridFileWriter(itp,pathToSave,rect,ncol,ncol,res,res)

Until this part I understand that, but when I start QgsTINInterpolator should take a long time for execution but it is too fast. It is weird...

Next code I don't understand, concretely what is zi variable? (line 693 on github)

  • Do you not know how to create a QList object, or do you just not know what the inputData should be?
    – BradHards
    Commented May 6, 2016 at 9:08
  • I don't know how to create QList with attributes for layers. I tried Interpolation in QGis Desktop so I suppose I will add QgsVectorLayers to QList with attributes somehow. Then probably I don't know first part of you question. Thanks for comment.
    – Bulva
    Commented May 6, 2016 at 9:11
  • qgis.org/api/structQgsInterpolator_1_1LayerData.html shows the LayerData structure. Do you know how to create that?
    – BradHards
    Commented May 6, 2016 at 9:18
  • I found this link, but I still don't understand how create object if there is no constructor. I tried this: qInt = QgsInterpolator.LayerData(1, POINTS, vectorLayerVariable, false) but console said NameError: name 'QgsInterpolator' is not defined.
    – Bulva
    Commented May 6, 2016 at 10:18
  • You aren't using the class correctly. This isn't really QGIS / GIS specific though, more a python programming issue. Are you not very familiar with coding? Perhaps you can rewrite your question with what your background is, what you've actually done, what worked, and what didn't work. Posting the code you have would be a good idea.
    – BradHards
    Commented May 6, 2016 at 11:49

1 Answer 1


Thanks to BradHards and ThomasG77 who sent link for interpolation code.

This is what I meant:

import qgis.analysis

layer = QgsVectorLayer(pathToFile, 'nameOfLayer','ogr')
ld1 = qgis.analysis.QgsInterpolator.LayerData()
ld1.vectorLayer = layer
ld1.InterpolationAttribute = 7      #column index, start with 0
ld1.mInputType = 1

'''Next ld2 and ld3 was created'''

itp = qgis.analysis.QgsTINInterpolator([ld1, ld2, ld3])

rect = layer.extent()
test = qgis.analysis.QgsGridFileWriter(itp,pathToAscFileSave,rect,89050, 104230,0.1,0.1)
test.writeFile(True)          #Creating .asc raster 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.