1

I did a module in grass wich I called r.out.haralickFeatures.py. I did a .qgm. I can't get the parameters rigth.

#!/usr/bin/env python

#%module
#% description: Compute asm, contrast, var, idm and entr for each band of a TIFF file
#% keyword: raster
#% keyword: haralick
#% keyword: features
#%end

#%option G_OPT_F_BIN_INPUT
#% key: input
#% type: string
#% required : yes
#%end

#%option
#% key: size
#% type: integer
#% required: yes
#% multiple: no
#% key_desc: value
#% description: The size of moving window (odd and >= 3)
#% answer: 3
#%end

#%option
#% key: distance
#% type: integer
#% required: yes
#% multiple: no
#% key_desc: value
#% label: The distance between two samples (>= 1)
#% description: The distance must be smaller than the size of the moving window
#% answer: 1
#%end

#%option
#% key: categories
#% type: integer
#% description: Number of categories to rescale/recode the image
#% answer: 255
#% required : yes
#%end

#%flag
#% key: r
#% description: Rescales instead of recoding the image
#%end

#%option G_OPT_F_OUTPUT
#% key: output
#% type: string
#% required : no
#%end

import sys
import grass.script as gscript
from grass.pygrass.modules import Module, ParallelModuleQueue
from copy import deepcopy
from osgeo import gdal
import os
import time
import atexit

def main():
    options,flags = gscript.parser()
    inputFile = options['input']
    sizeMovingWindow = options['size']
    distance = options['distance']
    numCategories = options['categories']
    output = options['output']
    recode = flags['r']

    print options

    ...


if __name__ == '__main__':
    atexit.register(cleanup)
    main()

and the .qgm:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE qgisgrassmodule SYSTEM "http://mrcc.com/qgisgrassmodule.dtd">
<qgisgrassmodule label="Compute asm, contrast, var, idm and entr for each band of a TIFF file" module="r.out.haralickFeatures.py">
    <file key="input" />
    <option key="size" answer="3" type="integer" />
    <option key="distance" answer="1" type="integer" />
    <option key="categories" answer="255" type="integer" />
    <flag key="r" answer="off" />
    <file key="output" type="new" filters="Geo TIFF (*.tif *.tiff)"/>
</qgisgrassmodule>

The output i get after running it in qgis is:

C:/OSGEO4~1/apps/qgis-ltr/./grass/scripts/r.out.haralickFeatures.py 
input=C:/Users/Carolina/Documents/PPS/Informe/Landsat8-OLI.tif size=3 distance=1 categories=255 output=
{'input': '@ARGS_PARSED@', 'output': '', 'distance': '1', 'categories': '255', 'size': '3'}

ERROR: Unable to open file:  @ARGS_PARSED@

Successfully finished

Anybody knows why i get @ARGS_PARSED@ and not the parameters i'm supposed to get?

2

resolved this creating a .bat file with the line

@"%GRASS_PYTHON%" "%GISBASE%/scripts/r.out.haralickFeatures.py" %*

in the directory: C:\OSGeo4W64\apps\grass\grass-7.4.0\bin

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.