La capacidad para escribir y ejecutar cruz de la plataforma de secuencias de comandos para QGIS usando python es EXCEPCIONAL! Sin embargo, cuando intento ejecutar la SAGA:MERGESHAPESLAYERS algoritmo a partir de una secuencia de comandos de python funciona bien en windows, pero no devuelve resultados de forma cuando lo ejecuto en ubuntu. Yo estoy usando QGIS 2.4 en ubuntu.
Estoy seguro de que tengo la SAGA de 2.1 en el sistema ubuntu porque puedo ejecutar correctamente el casco convexo algoritmo.
Para ilustrar el problema que he escrito las siguientes secuencias de comandos. La primera de las cuales se crea un par de archivos shape en el directorio temp, a continuación, el segundo de los intentos de aplicar la mencionada SAGA de los algoritmos. Usted debe ser capaz de easilty cortar y pegar las secuencias de comandos en el QGIS consola de python con el fin de ilustrar la cuestión.
Primera secuencia de comandos que crea algunos archivos de forma en el directorio temp:
#BUILD EXAMPLE SHAPE FILES TO ILLUSTRATE THE ISSUE
from qgis import core
from qgis.utils import iface
import os
import tempfile
import sys
epsg=4326
my_crs =core.QgsCoordinateReferenceSystem(epsg,core.QgsCoordinateReferenceSystem.EpsgCrsId)
iface.mapCanvas().mapRenderer().setDestinationCrs(my_crs)
vlayer01=QgsVectorLayer("Polygon?crs=epsg:"+str(epsg)+"&field=id:integer&field=name:string(20)&index=yes","polygon_01","memory")
bbl_dp = vlayer01.dataProvider()
vlayer01.startEditing()
feature_01_01 = QgsFeature()
feature_01_01.setGeometry(QgsGeometry.fromPolygon(\
[[QgsPoint(0,100),QgsPoint(0,110), QgsPoint(10,110),QgsPoint(10,100)]]))
feature_01_02 = QgsFeature()
feature_01_02.setGeometry(QgsGeometry.fromPolygon(\
[[QgsPoint(-10,100),QgsPoint(-10,110), QgsPoint(-20,110),QgsPoint(-20,100)]]))
(res, outFeats) = vlayer01.dataProvider().addFeatures([feature_01_01,feature_01_02])
vlayer01.commitChanges()
QgsMapLayerRegistry.instance().addMapLayer(vlayer01)
vlayer01_path=os.path.join(tempfile.gettempdir(),"vlayer_01.shp")
write_error = \
QgsVectorFileWriter.writeAsVectorFormat(vlayer01, \
vlayer01_path, "system", \
QgsCoordinateReferenceSystem(epsg), \
"ESRI Shapefile")
vlayer02=QgsVectorLayer("Polygon?crs=epsg:"+str(epsg)+"&field=id:integer&field=name:string(20)&index=yes","polygon_02","memory")
bbl_dp = vlayer02.dataProvider()
vlayer02.startEditing()
feature_02_01 = QgsFeature()
feature_02_01.setGeometry(QgsGeometry.fromPolygon(\
[[QgsPoint(20,110),QgsPoint(20,120), QgsPoint(30,120),QgsPoint(30,110)]]))
(res, outFeats) = vlayer02.dataProvider().addFeatures([feature_02_01])
vlayer02.commitChanges()
QgsMapLayerRegistry.instance().addMapLayer(vlayer02)
vlayer02_path=os.path.join(tempfile.gettempdir(),"vlayer_02.shp")
write_error = \
QgsVectorFileWriter.writeAsVectorFormat(vlayer02, \
vlayer02_path, "system", \
QgsCoordinateReferenceSystem(epsg), \
"ESRI Shapefile")
vlayer03=QgsVectorLayer("Polygon?crs=epsg:"+str(epsg)+"&field=id:integer&field=name:string(20)&index=yes","polygon_03","memory")
bbl_dp = vlayer03.dataProvider()
vlayer03.startEditing()
feature_03_01 = QgsFeature()
feature_03_01.setGeometry(QgsGeometry.fromPolygon(\
[[QgsPoint(3,103),QgsPoint(3,113), QgsPoint(13,113),QgsPoint(13,103)]]))
(res, outFeats) = vlayer03.dataProvider().addFeatures([feature_03_01])
vlayer03.commitChanges()
QgsMapLayerRegistry.instance().addMapLayer(vlayer03)
vlayer03_path=os.path.join(tempfile.gettempdir(),"vlayer_03.shp")
write_error = \
QgsVectorFileWriter.writeAsVectorFormat(vlayer03, \
vlayer03_path, "system", \
QgsCoordinateReferenceSystem(epsg), \
"ESRI Shapefile")
qgis.utils.iface.setActiveLayer(vlayer01)
qgis.utils.iface.zoomToActiveLayer()
El segundo script que soluciona el problema
###SAGA PROCESSING ALGORITHM ISSUE STARTS HERE###
import processing
alg_list=[]
alg_list.append("qgis:mergevectorlayers")
alg_list.append("saga:mergeshapeslayers")
alg_list.append("saga:convexhull")
for alg in alg_list:
if alg=="saga:convexhull":
SHAPES=vlayer01_path
POLYPOINTS=0
HULLS=os.path.join(tempfile.gettempdir(),"output_saga_convexhull.shp")
BOXES=""
processing_result=processing.runalg(alg,SHAPES,POLYPOINTS,HULLS,BOXES)
print alg+" was "+str(processing_result)
resultlayer = QgsVectorLayer(HULLS, "saga:convexhull", "ogr")
QgsMapLayerRegistry.instance().addMapLayer(resultlayer)
qgis.utils.iface.setActiveLayer(resultlayer)
qgis.utils.iface.zoomToActiveLayer()
if alg=="saga:mergeshapeslayers":
MAIN=vlayer01_path
LAYERS=vlayer02_path+";"+vlayer03_path
OUT=os.path.join(tempfile.gettempdir(),"output_saga_mergeshapeslayers.shp")
processing_result=processing.runalg(alg,MAIN,LAYERS,OUT)
print alg+" was "+str(processing_result)
resultlayer = QgsVectorLayer(OUT, "saga:mergeshapeslayers", "ogr")
QgsMapLayerRegistry.instance().addMapLayer(resultlayer)
qgis.utils.iface.setActiveLayer(resultlayer)
qgis.utils.iface.zoomToActiveLayer()
if alg=="qgis:mergevectorlayers":
LAYER1=vlayer01_path
LAYER2=vlayer02_path
SAVENAME=os.path.join(tempfile.gettempdir(),"output_qgis_mergevectorlayers.shp")
processing_result=processing.runalg(alg,LAYER1,LAYER2,SAVENAME)
print alg+" was "+str(processing_result)
resultlayer = QgsVectorLayer(SAVENAME, "qgis:mergevectorlayers", "ogr")
QgsMapLayerRegistry.instance().addMapLayer(resultlayer)
qgis.utils.iface.setActiveLayer(resultlayer)
qgis.utils.iface.zoomToActiveLayer()
El algoritmo de combinación sólo funciona en windows y el convex hull algoritmo funciona tanto en windows como en ubuntu. Realmente me gustaría que la SAGA:MERGESHAPESLAYERS algoritmo de trabajo de la plataforma de la cruz, como se pretendía.
Gracias por mirar!