Is there a way to call the clip function in QQGIS from the python console? It is found under geoprocessing tools in the vector menu.
Sure You can get the function from the processing toolbox. Here's how to use it: As per http://docs.qgis.org/2.8/en/docs/user_manual/processing/console.html
From the console you can get a list of all the algorithms available which contain the word "clip" by typing:
import processing processing.alglist("clip")
Then you could find out how to use what appears the most appropriate function with:
Then simply use the algorithm in your script as follows:
Note: The algorithm will work only on slected features"
Note above code is invalid for 3.0+ for the alglist example you can do:
print([a.id() for a in gsApplication.processingRegistry().algorithms() if "clip" in a.id()])
for the alghelp example you can do:
For QGIS3 see this question:
Assuming that you have a layer called "overlay" and another one called "layer_to_clip" loaded.
# get the overlay layer in the console overlay_layer = [x for x in iface.legendInterface().layers() if x.name() == 'overlay'] # get the layer to clip in the console layer_to_clip = [x for x in iface.legendInterface().layers() if x.name() == 'layer_to_clip'] # run the algorithm and output the results in /tmp/output.shp processing.runalg("qgis:clip", overlay_layer, layer_to_clip, "/tmp/output.shp")