[Qgis-developer] Error import Processing

Ivan sarteguas ivansarteguas at hotmail.com
Fri Feb 6 03:55:44 PST 2015


Hi
I am working with QGIS Valmiera 2.2.0 in a Windows 7.
I need import the library Processing, but I can't load. My code is as follow:
import sysimport qgisfrom qgis.core import *from qgis.utils import *from qgis.gui import *from PyQt4.QtCore import *from PyQt4.QtGui import *app = QApplication([])QgsApplication.setPrefixPath("C:\\Users",True)QgsApplication.initQgis()import processingfrom processing.core.Processing import Processingprocessing.initialize()from processing.lidar.lastools.LAStoolsUtils import LAStoolsUtilsProcessing.initialize()processing.alglist('lasview')import osimport subprocessimport csvprint "Cargamos as librerias"
if len(sys.argv) <3:    print "Faltan parametros de entrada"else:    temporal=sys.argv[2]    ficheros=[]    t=0    for p in range(3,len(sys.argv)):        ficheros.insert(t,sys.argv[p])        t=t+1
    ficherosTemp = os.listdir(temporal)    if('procesado.txt' in ficherosTemp):        lista_input=os.path.join(temporal,'procesado.txt')        lista=open(lista_input,'r')        lista_txt=lista.readlines()        for t in range(len(lista_txt)):            lista_txt[t]=lista_txt[t].replace('\n','')        lista.close()        imag2=list(set(ficheros)-set(lista_txt))        lista_output=temporal+os.sep+"procesado.txt"        lista=open(lista_output,'w')        lista.writelines('\n'.join(lista_txt+imag2))        lista.close()    else:	print "no existe el fichero procesado.txt"        lista_output=temporal+os.sep+"procesado.txt"        lista=open(lista_output,'w')        lista.writelines('\n'.join(ficheros))        lista.close()        imag2=ficheros        
    for archivo1 in imag2:        (Ruta,arch)=os.path.split(archivo1)        output_file=os.path.join(temporal,'ground'+arch)        processing.runalg('lidartools:lasground','False',archivo1,'False','False','True',1,1,output_file)        input_file=output_file        output_file=os.path.join(temporal,'height'+arch)        processing.runalg('lidartools:lasheight','False',input_file,'False',output_file)        os.remove(input_file)        input_file=output_file        output_file=os.path.join(temporal,'classify'+arch)        processing.runalg('lidartools:lasclassify','False',input_file,'False','False',output_file)        os.remove(input_file)        input_file=output_file.split(os.sep)        input_file='/'.join(input_file)        output_file=temporal.split(os.sep)        output_file='/'.join(output_file)+'/'+arch+'out1.LAS'        commands=[LAStoolsUtils.LAStoolsPath()+'/bin/lasheight','-i',input_file,'-o',output_file,'-classify_between','15','55','8','-ignore_class','2','5','6','-scale_u','1.0']        commandline=" ".join(commands)        proc=subprocess.Popen(commandline,shell=True,stdout=subprocess.PIPE,stdin=subprocess.PIPE,stderr=subprocess.STDOUT,universal_newlines=False)        proc.stdout.read()        proc.stdout.close()        os.remove(input_file)        input_file=output_file        output_file=temporal.split(os.sep)        output_file='/'.join(output_file)+'/'+arch+'out.txt'        commands=[LAStoolsUtils.LAStoolsPath()+'/bin/las2txt','-i',input_file,'-o',output_file,'-keep_class','8','-parse','xyzu']         commandline=" ".join(commands)        proc=subprocess.Popen(commandline,shell=True,stdout=subprocess.PIPE,stdin=subprocess.PIPE,stderr=subprocess.STDOUT,universal_newlines=False)        proc.stdout.read()        proc.stdout.close()            for archivo1 in imag2:        (Ruta,arch)=os.path.split(archivo1)        file_delete=temporal.split(os.sep)        file_delete='/'.join(file_delete)+'/'+arch+'out1.LAS'        os.remove(file_delete)
    print "hemos eliminado los archivos sobrantes"    if('out.txt' in ficherosTemp):        txt_file=temporal+os.sep+"out.txt"        output=open(txt_file,'a')        out_txt=csv.writer(output,delimiter=";")        for archivo2 in imag2:            (Ruta,arch2)=os.path.split(archivo2)            input_file=os.path.join(temporal,arch2+'out.txt')            input=open(input_file,'r')            in_txt=csv.reader(input,delimiter=' ')            file_list=list(in_txt)            for row in file_list:                out_txt.writerow(row)            input.close()            os.remove(input_file)        output.close()    else:        txt_file=temporal+os.sep+"out.txt"
        output=open(txt_file,'w')        out_txt=csv.writer(output,delimiter=";")        nombres=['X','Y','Elevacion','Altura']        out_txt.writerow(nombres)        for archivo2 in imag2:            (Ruta,arch2)=os.path.split(archivo2)            input_file=os.path.join(temporal,arch2+'out.txt')            input=open(input_file,'r')            in_txt=csv.reader(input,delimiter=' ')            file_list=list(in_txt)            for row in file_list:                out_txt.writerow(row)            input.close()            os.remove(input_file)        output.close()                    csv_file=temporal+os.sep+"out.csv"    output=open(csv_file,'wb')    out_csv=csv.writer(output,delimiter=";")    input=open(temporal+os.sep+"out.txt",'rb')    in_csv=csv.reader(input,delimiter=' ')    file_list=list(in_csv)    for row in file_list:        out_csv.writerow(row)
    input.close()    output.close()
print "Hemos escrito los valores y acabado la ejecucion"QgsApplication.exitQgis()QApplication.exit()
When I run this code, the program does nothing and doesn't gives errors. But i've been running slowly code and I have found that the statement fails is "import Processing".attached a image  when show an execution of the program:
              

thanks for the helpIván
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20150206/d37148cf/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Captura.PNG
Type: image/png
Size: 10912 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20150206/d37148cf/attachment-0001.png>


More information about the Qgis-developer mailing list