Skip to main content
added 34 characters in body
Source Link
xunilk
  • 30.2k
  • 4
  • 43
  • 82

No results by using different 'Distance Coefficients' is because layer_data has not 'setDistanceCoefficient' method. Desired method is in idw_interpolator.

So, by using same code in your previous question about QgsIDWInterpolator, I had to add only one code line:

.
.
.
idw_interpolator.setDistanceCoefficient(10)
.
.
.

for producing desired result in following code:

layer = iface.activeLayer() 
layer_data = QgsInterpolator.LayerData()
layer_data.source = layer
layer_data.zCoordInterpolation = False
layer_data.interpolationAttribute = 1  # the 2nd field in the layer contains the data to interpolate
layer_data.mInputType = 1


idw_interpolator = QgsIDWInterpolator([layer_data])
idw_interpolator.setDistanceCoefficient(10) #added line

rasOut = r"/home/zeito/pyqgis_data/BiomassNOx_Emissions_tpa2.tif"

export_path = rasOut # e.g. r"C:\Temp\AnalysisResults\BiomassNOx_Emissions_tpa.tif" 

rect = layer.extent()
res = 10
ncols = int( ( rect.xMaximum() - rect.xMinimum() ) / res )
nrows = int( (rect.yMaximum() - rect.yMinimum() ) / res)

output = QgsGridFileWriter(idw_interpolator,export_path,rect,ncols,nrows)
output.writeFile()

for producing visible changes in interpolated raster layer.

After running above code with same point layer in your previous question, I got result observed in following image (different of my answer in your previous question):

enter image description here

So, you should modify your code as follows:

.
.
.
idw_interpolator = QgsIDWInterpolator([layer_data])
idw_interpolator.setDistanceCoefficient(10)
.
.
.

for obtaining an equivalent result.

No results by using different 'Distance Coefficients' is because layer_data has not 'setDistanceCoefficient' method. Desired method is in idw_interpolator.

So, by using same code in your previous question about QgsIDWInterpolator, I had to add only one code line:

.
.
.
idw_interpolator.setDistanceCoefficient(10)
.
.
.

for producing desired result in following code:

layer = iface.activeLayer() 
layer_data = QgsInterpolator.LayerData()
layer_data.source = layer
layer_data.zCoordInterpolation = False
layer_data.interpolationAttribute = 1  # the 2nd field in the layer contains the data to interpolate
layer_data.mInputType = 1


idw_interpolator = QgsIDWInterpolator([layer_data])
idw_interpolator.setDistanceCoefficient(10) #added line

rasOut = r"/home/zeito/pyqgis_data/BiomassNOx_Emissions_tpa2.tif"

export_path = rasOut # e.g. r"C:\Temp\AnalysisResults\BiomassNOx_Emissions_tpa.tif" 

rect = layer.extent()
res = 10
ncols = int( ( rect.xMaximum() - rect.xMinimum() ) / res )
nrows = int( (rect.yMaximum() - rect.yMinimum() ) / res)

output = QgsGridFileWriter(idw_interpolator,export_path,rect,ncols,nrows)
output.writeFile()

After running above code with same point layer in your previous question, I got result observed in following image (different of my answer in your previous question):

enter image description here

So, you should modify your code as follows:

.
.
.
idw_interpolator = QgsIDWInterpolator([layer_data])
idw_interpolator.setDistanceCoefficient(10)
.
.
.

for obtaining an equivalent result.

No results by using different 'Distance Coefficients' is because layer_data has not 'setDistanceCoefficient' method. Desired method is in idw_interpolator.

So, by using same code in your previous question about QgsIDWInterpolator, I had to add only one code line:

.
.
.
idw_interpolator.setDistanceCoefficient(10)
.
.
.

in following code:

layer = iface.activeLayer() 
layer_data = QgsInterpolator.LayerData()
layer_data.source = layer
layer_data.zCoordInterpolation = False
layer_data.interpolationAttribute = 1  # the 2nd field in the layer contains the data to interpolate
layer_data.mInputType = 1


idw_interpolator = QgsIDWInterpolator([layer_data])
idw_interpolator.setDistanceCoefficient(10) #added line

rasOut = r"/home/zeito/pyqgis_data/BiomassNOx_Emissions_tpa2.tif"

export_path = rasOut # e.g. r"C:\Temp\AnalysisResults\BiomassNOx_Emissions_tpa.tif" 

rect = layer.extent()
res = 10
ncols = int( ( rect.xMaximum() - rect.xMinimum() ) / res )
nrows = int( (rect.yMaximum() - rect.yMinimum() ) / res)

output = QgsGridFileWriter(idw_interpolator,export_path,rect,ncols,nrows)
output.writeFile()

for producing visible changes in interpolated raster layer.

After running above code with same point layer in your previous question, I got result observed in following image (different of my answer in your previous question):

enter image description here

So, you should modify your code as follows:

.
.
.
idw_interpolator = QgsIDWInterpolator([layer_data])
idw_interpolator.setDistanceCoefficient(10)
.
.
.

for obtaining an equivalent result.

Source Link
xunilk
  • 30.2k
  • 4
  • 43
  • 82

No results by using different 'Distance Coefficients' is because layer_data has not 'setDistanceCoefficient' method. Desired method is in idw_interpolator.

So, by using same code in your previous question about QgsIDWInterpolator, I had to add only one code line:

.
.
.
idw_interpolator.setDistanceCoefficient(10)
.
.
.

for producing desired result in following code:

layer = iface.activeLayer() 
layer_data = QgsInterpolator.LayerData()
layer_data.source = layer
layer_data.zCoordInterpolation = False
layer_data.interpolationAttribute = 1  # the 2nd field in the layer contains the data to interpolate
layer_data.mInputType = 1


idw_interpolator = QgsIDWInterpolator([layer_data])
idw_interpolator.setDistanceCoefficient(10) #added line

rasOut = r"/home/zeito/pyqgis_data/BiomassNOx_Emissions_tpa2.tif"

export_path = rasOut # e.g. r"C:\Temp\AnalysisResults\BiomassNOx_Emissions_tpa.tif" 

rect = layer.extent()
res = 10
ncols = int( ( rect.xMaximum() - rect.xMinimum() ) / res )
nrows = int( (rect.yMaximum() - rect.yMinimum() ) / res)

output = QgsGridFileWriter(idw_interpolator,export_path,rect,ncols,nrows)
output.writeFile()

After running above code with same point layer in your previous question, I got result observed in following image (different of my answer in your previous question):

enter image description here

So, you should modify your code as follows:

.
.
.
idw_interpolator = QgsIDWInterpolator([layer_data])
idw_interpolator.setDistanceCoefficient(10)
.
.
.

for obtaining an equivalent result.