1

In QGIS 2.14.5 I would like to create a model that determines a statistics for a raster layers' unique values (Tool Raster layer statistics) and does some further computations with the result.

I think, the output of this tool must be ##output=html, according to the documentation http://docs.qgis.org/2.14/de/docs/user_manual/processing/scripts.html?highlight=script.

The question is, when writing a geoprocessing script that computes this html output, what is the corresponding input?

Since there is no ##input=html, I tried ##input=file and ##input=longstring as well, but I'am not able to connect the output of the above mentioned tool to my script.

1

I think the output html parameter is only used to display information as it seems to just read the data which you can see from the script: RasterLayerStatistics.py.

You could create a custom script and apply a similar method as in the script by taking the relevant statistical values directly from the raster and apply further calculations. I tend to use something like:

##Example=name
##Layer=raster

from qgis.core import QgsRasterBandStats

layer = processing.getObject(Layer)
provider = layer.dataProvider()
ext = layer.extent()
stats = provider.bandStatistics(1,QgsRasterBandStats.All,ext,0)

valid_cells = stats.elementCount
nodata_cells = stats.None
minimum_value = stats.minimumValue
maximum_value = stats.maximumValue
sum = stats.sum
mean = stats.mean
std_dev = stats.stdDev

# Print above statistics or use them as input for calculations
print "Valid cells: ", valid_cells
print "No-data cells:", nodata_cells
print "Minimum value: ", minimum_value
print "Maximum value: ", maximum_value
print "Sum: ", sum
print "Mean value: ", mean
print "Standard deviation: ", std_dev

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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