Friday, 4 September 2015

How to use Memory layers in QGIS plugin to store results of Geoprocessing tools


I'm building a plugin to perform Multi Criteria Analysis (yes another one...). As part of my workflow intersecting vectorlayers is needed. I use QgsOverlayAnalyzer.intersection (a pity union is not yet supported as far as I know).


Because intersection is limited to 2 layers a number of inbetween results is generated. Until now I create these inbetween results as shapefiles, add them to the TOC, use them in another intersection step and eventually remove them later.


Sample code (path, intersectionlayer1 and 2 are defined)


productname= "intersection_output1" # first inbetween result


product = QFileDialog.getSaveFileName(self.pluginGui,"Save inbetween result as", path, "shapefiles (*.shp)")

QgsOverlayAnalyzer().intersection(intersectionlayer1, intersectionlayer2, product, 0)

self.iface.addVectorLayer(product, productname, 'ogr')

Not very elegant and therefore I have a few questions:



  • how to bypass adding the inbetween results to the TOC (QgsMapLayerRegistry requires them isn't it) ? Just using disk as storage is an improvement.


  • how to store these inbetween results in memory (Plugin) layers ? This would improve processing speed and removal of inbetween results is easy.




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...