You may continue using the memory layer by loading it as an object. Before doing this, you need to know how the output from the algorithm is called, so typing these lines in the Python Console:
import processing
processing.alghelp('gdalogr:clipvectorsbypolygon')
you will see that the output's name is OUTPUT_LAYER
:
ALGORITHM: Clip vectors by polygon
INPUT_LAYER <ParameterVector>
CLIP_LAYER <ParameterVector>
OPTIONS <ParameterString>
OUTPUT_LAYER <OutputVector>
This means that you will be able to use it if you add a new variable and call it in this way:
# change 'my_algorithm' name as you want
my_algorithm = general.runalg('gdalogr:clipvectorsbypolygon', 'lokale_orte.shp', 'kleine_kreise.shp', None, None)
# change 'my_output' name as you want
my_output = processing.getObject(my_algorithm['OUTPUT_LAYER'])
By now, my_output
will be the object to use for calling the layer returned by the clip operation and you are ready to do something with it.
EDIT For getting your script working, you may try using the following code (slightly different from yours):
import sys
from qgis.core import *
import qgis.utils
qgs = QApplication([], True)
QgsApplication.setPrefixPath("/usr", True)
QgsApplication.initQgis()
# Prepare processing framework
sys.path.append('/usr/share/qgis/python/plugins') # Dir where Processing is located
from processing.core.Processing import Processing
from processing.tools import *
Processing.initialize()
# load base layer
blayer = QgsVectorLayer("path/to/the/shapefile/lokale_orte.shp", "lokale_orte", "ogr")
if not blayer.isValid():
print "Layer failed to load!"
else:
print "success: load layer"
# load clip layer
clayer = QgsVectorLayer("path/to/the/shapefile/kleine_kreise.shp", "kleine_kreise", "ogr")
if not clayer.isValid():
print "Layer failed to load!"
else:
print "success: load layer"
# run clip
# change 'my_algorithm' name as you want
my_algorithm = general.runalg('gdalogr:clipvectorsbypolygon', 'lokale_orte.shp', 'kleine_kreise.shp', None, None)
# change 'my_output' name as you want
my_output = processing.getObject(my_algorithm['OUTPUT_LAYER'])
QgsApplication.exitQgis()
qgs.exit()
Best Answer
In case you do not know a name or id, you can use:
to search for it. In your case its
native:countpointsinpolygon