I wrote several python scripts called by my main.py script. In one of those scripts I create a vector layer by polygonizing a raster layer. As the layer is really heavy and as I don't need it as an output, I create it in memory.
result = processing.runalg('gdalogr:polygonize',layer,"lu_majorit", None)
polygonLayer = processing.getObject(result['OUTPUT'])
Then I can use the layer in my file. But I would like to use this layer from another script and I don't succeed.
Here is what I've tried :
in my first script :
result = processing.runalg('gdalogr:polygonize',layer,"lu_majorit", None)
polygonLayer = processing.getObject(result['OUTPUT'])
return polygonLayer
in my main:
polygonLayer=script1(...)
script2(polygonLayer,...)
in my second script :
cLayer =QgsVectorLayer("Polygon?crs=epsg:4326", "OUTPUT", "memory")
or:
cLayer =QgsVectorLayer("polygonLayer", "OUTPUT", "ogr")
Those two ways failed to load the layer.
I tried also by giving the path with : script 1 :
myfilepath= polygonLayer.dataProvider().dataSourceUri()
return myfilepath
script2:
cLayer =QgsVectorLayer(myfilepath, "OUTPUT", "ogr")
This way gives me an invalid syntax.
Does someone know how to do ?