Sunday 19 November 2017

qgis - Run ftools multiparts to singleparts from PYQGIS


Is it possible to run the multiparts to singleparts function from the console with the processing_runalg function?


Or is there another way?



Answer



Yes:


1) The proposed solution (Using processing algorithms from the console)


 import processing

# find the algorithm
processing.alglist("Multipart to singleparts")
Multipart to singleparts----------------------------->qgis:multiparttosingleparts
# help
processing.alghelp("qgis:multiparttosingleparts")
ALGORITHM: Multipart to singleparts
INPUT
OUTPUT

So the command is



processing.runalg("qgis:multiparttosingleparts","shape1.shp","shape2.shp")

2) an easiest solution


Each time you execute a Processing algorithm,the complete runalg command with values are saved in the .../.qgis2/processing/processing.log file


Execute the algorithm with a test layer and look at the last line of this file:


ALGORITHM|Mon Apr 14 2014    
17:13:45|processing.runalg("qgis:multiparttosingleparts","/Users/shape1.shp","/Users/shape2.shp")

and you have the syntax of the command.


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...