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?

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)
  • 1
    Yes. Indeed, it works like that also to me. Great!! – Nico_77 May 19 '16 at 11:42
  • @Nico_77 - Brilliant, glad it worked ;) – Joseph May 19 '16 at 11:43
  • The problem is solved with the solution provided by Joseph – Nico_77 Jun 3 '16 at 5:44

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.