I have a problem with the grass function r.mfilter outputting an empty file. I'm running the tool from qgis processing standalone.
My system:
OS: Ubuntu 16.04.2 LTS
Saga: 2.2.3
Grass: 7.0.3
QGIS: 2.18.4
Saga installed as per instructions in this question
The script:
from qgis.core import *
from qgis.gui import *
import os
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import Qt
app = QgsApplication(sys.argv, True)
QgsApplication.initQgis();
QgsApplication.setPrefixPath('/usr', True)
sys.path.append('/usr/share/qgis/python/plugins')
from processing.core.Processing import Processing
import processing.tools.general as processing
Processing.initialize()
# Processing directory
cwd = os.getcwd()
procdir = cwd + '/LST-trad/hojd/'
tmpdir = cwd + '/LST-trad/Test2/'
outdir = cwd + '/LST-trad/treecover2/'
filter = cwd + "/LST-trad/qgis5x5filter_1or0_div1.txt"
files = os.listdir(procdir)
# Filter files
filefilt =[]
for f in files:
if f.endswith(".tif"):
filefilt.append(f)
print "help:"
#processing.alghelp("saga:rastercalculator")
processing.alghelp("grass:r.mfilter")
# Coordinates
arglist = []
for file in filefilt:
x1 = int(file[7] + file[11:13]+"000")
x2 = x1 + 25000
y1 = int(file[4:6] + file[9:11] +"000")
y2 = y1 + 25000
coords = str(x1) + "," + str(x2) + "," + str( y1) + "," + str(y2)
outfile = "COV_" + file[4:]
arglist.append([procdir+file, coords, outdir+outfile, outfile])
#print arglist
formula1 =('ifelse(a > 50, 1, 0)')
formula2 = ('a * 4')
for arg in arglist:
tmp1 = tmpdir + "t1_" + arg[3]
tmp2 = tmpdir + "t2_" + arg[3]
print "saga"
processing.runalg("saga:rastercalculator", arg[0], None, formula1, True, 1, tmp1)
print "grass"
processing.runalg("grass:r.mfilter", tmp1, filter,1,False,arg[1], 0, tmp2)
print "rascal"
processing.runalg("saga:rastercalculator", tmp2, None, formula2, True, 1, arg[2])
QgsApplication.exitQgis();
The filter file:
MATRIX 5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
DIVISOR 1
TYPE P
output form alghelp(r.mfilter):
ALGORITHM: r.mfilter - Performs raster map matrix filter.
input <ParameterRaster>
filter <ParameterFile>
repeat <ParameterNumber>
-z <ParameterBoolean>
GRASS_REGION_PARAMETER <ParameterExtent>
GRASS_REGION_CELLSIZE_PARAMETER <ParameterNumber>
output <OutputRaster>
One thing that confuses me is that the parameters listed here does not match the parameters listed in the grass documentation