I try to create a interpolation with the follow script, the problem is that when the program tries to write QgsGridFileWriter, qgis crashes. The problem is that the different examples are to lower version for qgis, and this script is to qgis3, someone knows if i have to write some parameter in output.writeFile(), like boolean of other versions?
#Generation Interpolate data#
uri="file:///Z:/DataScience/TragsaMoscaOlivo2017/Tutoriales QGIS/Capa
Predicciones/PREDICCION_oriental_I_S1.csvxField=LONG&yField=LAT&
delimiter=%s"%(",")
lyr=QgsVectorLayer(uri, 'Prediction','delimitedtext')
values = (
('Low',0,0,'green'),
('Medium',1,1, 'yellow'),
('Large',2,2,'red'))
QgsProject.instance().addMapLayer(lyr)
# create a category for each item in values
ranges = []
for label,lower,upper,color in values:
symbol = QgsSymbol.defaultSymbol(lyr.geometryType())
symbol.setColor(QColor(color))
rng = QgsRendererRange(lower, upper, symbol, label)
ranges.append(rng)
# create the renderer and assign it to a layer
expression = 'pred_C' # field name
renderer = QgsGraduatedSymbolRenderer(expression, ranges)
lyr.setRenderer(renderer)
lyr.triggerRepaint()
#######################################################################
#Interpolation generation
layer_data=QgsInterpolator.LayerData()
layer_data.vectorLayer=lyr
layer_data.zCoordInterpolation=False
layer_data.interpolationAttribute=2 #Field
layer_data.mInputType=0 #points
tin_interpolator=QgsTinInterpolator([layer_data])
export_path ="Z:/DataScience/TragsaMoscaOlivo2017/Tutoriales
QGIS/pythoninterpolation/output4656.asc"
rect = layer2.extent()
res = 10
#ncol =int((rect.xMaximum() - rect.xMinimum())/res)
#nrows = int( (rect.yMaximum() - rect.yMinimum() ) / res)
#Grid generation and write
output = QgsGridFileWriter(tin_interpolator,export_path,rect,300,300)
print(output)
output.writeFile()