I would like to calculate zonal histograms (number of raster cells of each type contained in a polygon) using the RQGIS3
package in R. The problem is that I can't seem to find the algorithm name for zonal histograms. For example, if I want zonal statistics, I might do something like:
args <- get_args_man(alg="qgis:zonalstatistics")
args$INPUT_RASTER <- someraster
args$INPUT_VECTOR <- somevector
args$output <- file.path(tempdir(), "out.shp")
out<- run_qgis(alg = "qgis:zonalstatistics", params = args,
load_output = TRUE,
show_output_paths = FALSE,
qgis_env = qgis_env)
But for zonal histograms, I don't know the name of the algorithm to specify, or if I can do this at all from R (it is easily done from within QGIS 3.4).
If I run the following in the Python console in QGIS, I can't seem to find an algorithm name for zonal statistics:
for alg in QgsApplication.processingRegistry().algorithms():
print(alg.id(), "->", alg.displayName())
Can I do zonal histograms from within R, using the RQGIS3
package?
My motivation is that I want to be able to generate various polygon grids in R and calculate the zonal histograms on the fly. I could do it in R (without QGIS
, but QGIS
seems much faster than the native R functions.
find_algorithms()
?find_algorithms()[grep("histogram",find_algorithms()]
to sort through the very long list of algorithms. And then I found it easily - it isnative:zonalhistogram
rather thanqgis:zonalhistogram
. I'll provide this as an answer below.