Getting layer extent in PyQGIS?
The answer is almost completely contained in a post I recently wrote.
The extent is returned as a QgsRectangle() object with the following code:
layer = iface.activeLayer() # load the layer as you want
ext = layer.extent()
For getting the coordinates of the vertices for the current layer, you may run this code:
xmin = ext.xMinimum()
xmax = ext.xMaximum()
ymin = ext.yMinimum()
ymax = ext.yMaximum()
coords = "%f,%f,%f,%f" %(xmin, xmax, ymin, ymax) # this is a string that stores the coordinates
Finally, you may run the following code for using the r.neighbors
module from the Python Console:
processing.runalg("grass7:r.neighbors",layer,0,3,False,False,"",coords,0,None)
you were on the right track you just need to go a step further. See the QGIS documentation for QgsRectangle
Basically, you do:
get the current Layer
layer = iface.activeLayer()
get the extent which is a QgsRectangle object
ex = layer.extent()
and there extract the Values with:
xmax = ex.xMaximum() ymax = ex.yMaximum() xmin = ex.xMinimum() ymin = ex.yMinimum()