1

According to the following conversation: Using r.mapcalculator in Python console?

I tried:

##NoData Background=name
##RASTERLAYER_BAND=raster
##nodatabackground=output raster

import processing

ext = RASTERLAYER_BAND.extent() 
a = str(ext.xMinimum()) 
b = str(ext.xMaximum()) 
c = str(ext.yMinimum()) 
d = str(ext.yMaximum()) 
size = a + ',' + b + ',' + c + ',' + d

nodatabackground=processing.runalg('grass:r.mapcalculator', RASTERLAYER_BAND,None,None,None,None,None,'A/A*A',size,0.0,nodatabackground)

But it doesn't work to me. I get the following message: AttributeError: 'unicode' object has no attribute 'extent'

Any idea to solve it?

1 Answer 1

3

You probably need to add something like

raster = processing.getObject(RASTERLAYER_BAND)

and remove

nodatabackground=processing.runalg(...)

The following works for me:

##NoData Background=name
##RASTERLAYER_BAND=raster
##nodatabackground=output raster

import processing

raster = processing.getObject(RASTERLAYER_BAND)
ext = raster.extent() 
a = str(ext.xMinimum()) 
b = str(ext.xMaximum()) 
c = str(ext.yMinimum()) 
d = str(ext.yMaximum()) 
size = a + ',' + b + ',' + c + ',' + d

processing.runalg('grass:r.mapcalculator', raster,None,None,None,None,None,'A/A*A',size,0.0,nodatabackground)
3
  • 1
    Yes. Indeed, it works like that also to me. Great!!
    – Nico_77
    Commented May 19, 2016 at 11:42
  • @Nico_77 - Brilliant, glad it worked ;)
    – Joseph
    Commented May 19, 2016 at 11:43
  • The problem is solved with the solution provided by Joseph
    – Nico_77
    Commented Jun 3, 2016 at 5:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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