QGIS: can't run processing.algrun() in external Python application

المشرف العام

Administrator
طاقم الإدارة
I am trying to create an external Python application. I want to run this as a stand alone program in command line. I am trying to not use the QGIS console.

A first step is to clip a point shapefile using a polygon shapefile.

When I try to use processing.runalg("saga:clippointswithpolygons",...) nothing happens. There are no error messages or warnings. Nothing is written to the output shapefile.

import sys import urllib import pathlib from qgis.core import QgsApplication from qgis.core import QgsVectorLayer from qgis.core import QgsVectorFileWriter # Constants node_shape_path = r'C:\Temp\TMC_nodes.shp' clip_path = r'C:\Temp\clip.shp' # Path to clipping polygon out_shapefile_path = r"C:\Temp\TMC_Nodes_Clipped_2.shp" ## # Prepare the QGIS environment and framework ## # Prepare the QGIS environment qgis_prefix = u'C:/PROGRA~1/QGISPI~1/apps/qgis' app = QgsApplication([], True) QgsApplication.setPrefixPath(qgis_prefix, True) QgsApplication.initQgis() # Prepare the QGIS processing framework sys.path.append(plugins_path) #from processing.core.Processing import Processing import processing ## # Clip the nodes and write to a new shapefile ## processing.runalg("saga:clippointswithpolygons", node_shape_path, clip_path, "OBJECTID", 0, out_shapefile_path) I have tried different versions of the processing.runalg line where I use file path strings instead of layers. I even went so far as to take the point layer, made from the csv, write it to a shapefile, and then use that path.

I have used the processing toolbox GUI to successfully conduct the clip. The log file reads:

ALGORITHM|Mon Sep 21 2015 12:26:24| processing.runalg("saga:clippointswithpolygons","C:/Temp/TMC_nodes.shp","C:/Temp/FCMS_clip.shp","OBJECTID",0,"C:/Temp/TMC_Nodes_Clipped.shp") I have even tried pasting the command call from the log directly into my external script, but it still does not work.

Any suggestions about how to fix this are greatly appreciated.



أكثر...
 
أعلى