You could create a custom script, copy the source code for the Polygon from layer extent tool and modify it slightly to take a raster as input. You can create one from:
Processing Toolbox > Scripts > Tools > Create new script
Then use something like the following:
##Example=name
##Layer=raster
##Output=output vector
from qgis.core import QgsField, QgsPoint, QgsGeometry, QgsFeature, QGis
from PyQt4.QtCore import QVariant
layer = processing.getObject(Layer)
fields = [
QgsField('MINX', QVariant.Double),
QgsField('MINY', QVariant.Double),
QgsField('MAXX', QVariant.Double),
QgsField('MAXY', QVariant.Double),
QgsField('CNTX', QVariant.Double),
QgsField('CNTY', QVariant.Double),
QgsField('AREA', QVariant.Double),
QgsField('PERIM', QVariant.Double),
QgsField('HEIGHT', QVariant.Double),
QgsField('WIDTH', QVariant.Double),
]
rect = layer.extent()
minx = rect.xMinimum()
miny = rect.yMinimum()
maxx = rect.xMaximum()
maxy = rect.yMaximum()
height = rect.height()
width = rect.width()
cntx = minx + width / 2.0
cnty = miny + height / 2.0
area = width * height
perim = 2 * width + 2 * height
rect = [QgsPoint(minx, miny), QgsPoint(minx, maxy), QgsPoint(maxx, maxy), QgsPoint(maxx, miny), QgsPoint(minx, miny)]
geometry = QgsGeometry().fromPolygon([rect])
feat = QgsFeature()
feat.setGeometry(geometry)
attrs = [minx, miny, maxx, maxy, cntx, cnty, area, perim, height, width]
writer = processing.VectorWriter(Output, None, fields, QGis.WKBPolygon, layer.crs())
feat.setAttributes(attrs)
writer.addFeature(feat)
del writer
Make sure to save the script into your /.qgis2/processing/scripts
directory.
Example:
A simple model with a raster layer being used as an input to the script:
Here is the input raster:
Here is the result of the model:
You could take the output polygon and use that as input for another tool.
Best Answer
The trick is to create a function that access QGIS graphical interface, and that is piped to the query of the
select by expression
.select by expression
and useintersects($geometry,currentExtent())
(orwithin(..)
for entirely contained polygons)The same function can be used in a virtual layer as shown here, that you could eventually modify to compute the buffer.