2

I'm making a plugin for QGIS and I'm trying to open the layers I've created on QGIS, but I only get to open the one called 'sinkhole raster' which is the input of the tool. I don't know what order should I write to open my output files. I need to open both Raster and Vector layers, the one called 'Hillshade' is a raster and the one called 'SSP' is a vector.
Any idea?

Here is the script:

def select_input_file(self):
    self.input=QFileDialog.getOpenFileName(self.dlg,"Input Layer ","",'*.*')
    self.dlg.select_input.setText(self.input)

def select_output_dir(self):
    self.output_dir=QFileDialog.getExistingDirectory(self.dlg,"Output layer ","")
    if os.path.exists(self.output_dir) and os.path.isdir(self.output_dir):
        self.dlg.select_output.setText(self.output_dir)
        self.Hillshade_path = os.path.join(self.output_dir, "Hillshade")
        self.SSP_path = os.path.join(self.output_dir, "SSP")
        self.Fill_path = os.path.join(self.output_dir, "Fill")
        self.Dolines_path = os.path.join(self.output_dir, "Dolines")
    else:
        self.output_dir = None
        self.dlg.select_output.clear()

def run(self):
    """Run method that performs all the real work"""

    # show the dialog
    self.dlg.show()
    # Run the dialog event loop
    result = self.dlg.exec_()
    # See if OK was pressed
    if result:
        # Do something useful here - delete the line containing pass and
        # substitute with your code.
        pass

def find_sinkholes(self):
    settings = QSettings()
    systemEncoding = settings.value('/UI/encoding', 'System')

    Input_DEM = self.iface.addRasterLayer(self.input, "sinkhole raster")
    Hillshade = self.Hillshade_path
    SSP = self.SSP_path
    Fill = self.Fill_path
    Dolines = self.Dolines_path

    ##Find Sinkholes_0.1=name
    ##Input_DEM=raster
    ##Hillshade=output raster
    ##SSP=output vector
    ##Fill=output vector
    ##Dolines=output vector

    #carreguem el DEM
    pas1=processing.getObject(self.input)
    #creem un mapa d'ombres
    pas2=processing.runalg('gdalogr:hillshade',self.input,1.0,False,True,1.0,1.0,315.0,45.0,Hillshade)
    #creem la capa de punts especifics
    pas3=processing.runalg('saga:surfacespecificpoints',self.input,2,2.0,None)
    pas45=processing.getObject(Hillshade)
    #fem una reclassificacio dels ssp
    pas4=processing.runalg('saga:reclassifygridvalues',pas3['RESULT'],0,8.0,8.0,0,0.0,0.0,0.0,0,'0,0,0,0,0,0,0,0,0',0,True,0.0,True,0.0,None)
    #passem a poligons els punts reclassificats
    pas5=processing.runalg('gdalogr:polygonize',pas4['RESULT'],'valor',None)
    #fem una seleccio per atributs per escollir els punts baixos
    pas6=processing.runalg('qgis:selectbyattribute',pas5['OUTPUT'],'valor',0,8.0)
    #guardem els punts seleccionats
    pas7=processing.runalg('qgis:saveselectedfeatures',pas5['OUTPUT'],None)
    #busquem el centroids dels poligons per fer una capa de punts amb els minims locals
    pas8=processing.runalg('qgis:polygoncentroids',pas7['OUTPUT_LAYER'],SSP)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.