I would like to create a vector layer, add a point to it and then use it in qgis algorithms.

This is what I wrote :

#create temporary layer containing center point
    pointlayer=QgsVectorLayer("Point?crs=epsg:2154", "temporary_points", "memory")

    #intersection between point layer and polygon layers to get names codes
    fieldname_vector=processing.runalg('qgis:intersection', parcel, pointlayer, False, None)

But when the algorithm runs, it returns

    Unable to execute algorithm
Wrong parameter value: Point?crs=epsg:2154

Is there a way to use my layer without saving it, knowing that I'll erase it in the future ?


You need to add the memory layer to the QgsMapLayerRegistry before you can use it in processing. But you can add it without it being shown in the Layers Panel by using:

QgsMapLayerRegistry.instance().addMapLayer(pointlayer, False)

When finished, you can then do some cleanup by removing and deleting it:

del pointlayer
  • 4
    In QGIS 3 the QgsMapLayerRegistry has been removed but the layer can be added via QgsProject.instance().addMapLayer(pointlayer, False). – Orienteerix Dec 31 '19 at 11:28
  • @Orienteerix - Thanks for the extra info :) – Joseph Jan 6 '20 at 10:42

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.