def run(self):
 

        #UBACIVANJE RASTERA I TOCAKA (mora biti ovdje ili se barem pozvati odavde)
        myLayers = []
        iface = self.iface
        #clear combos        
        self.dlg.ui.cmbRaster.clear();self.dlg.ui.cmbPoints.clear();self.dlg.ui.cmbPointsTarget.clear()
        #add an empty value to optional combo
        self.dlg.ui.cmbPointsTarget.addItem('',0)
        #add layers to combos
        for i in range(len(iface.mapCanvas().layers())):
            myLayer = iface.mapCanvas().layer(i)
            if myLayer.type() == myLayer.RasterLayer:

                #provjera da li je DEM 1 band .... !!!
                self.dlg.ui.cmbRaster.addItem(myLayer.name(),myLayer.id())

            elif myLayer.geometryType() == QGis.Point: 
                self.dlg.ui.cmbPoints.addItem(myLayer.name(),myLayer.id())
                self.dlg.ui.cmbPointsTarget.addItem(myLayer.name(),myLayer.id())

        #allAttrs = layer.pendingAllAttributesList()
       
                
        # show the dialog
        self.dlg.show()
        # Run the dialog event loop
        result = self.dlg.exec_()

        l = self.dlg.ui.cmbPoints.itemData(self.dlg.ui.cmbPoints.currentIndex())
        ly_name = str(l)
      #  QMessageBox.information(self.iface.mainWindow(), "drugi", str(ly_name))

        # See if OK was pressed
        
        if result == 1:
            outPath = ViewshedAnalysisDialog.returnOutputFile(self.dlg)
            ly_obs = ViewshedAnalysisDialog.returnPointLayer(self.dlg)
            ly_target = ViewshedAnalysisDialog.returnTargetLayer(self.dlg)
            ly_dem = ViewshedAnalysisDialog.returnRasterLayer(self.dlg)

            z_obs = ViewshedAnalysisDialog.returnObserverHeight(self.dlg) 
            z_obs_field = self.dlg.ui.cmbObsField.itemData(
                self.dlg.ui.cmbObsField.currentIndex())#table columns are indexed 0-n 

            z_target = ViewshedAnalysisDialog.returnTargetHeight(self.dlg) 
            z_target_field =self.dlg.ui.cmbTargetField.itemData(
                self.dlg.ui.cmbTargetField.currentIndex())       
            
            Radius = ViewshedAnalysisDialog.returnRadius(self.dlg)

            Algo = ViewshedAnalysisDialog.returnAlgorithm(self.dlg)

            search_top_obs = ViewshedAnalysisDialog.returnSearchTopObserver(self.dlg)
            search_top_target = ViewshedAnalysisDialog.returnSearchTopTarget(self.dlg)
            
            output_options = ViewshedAnalysisDialog.returnOutputOptions(self.dlg)
                
            curv=ViewshedAnalysisDialog.returnCurvature(self.dlg)
            refraction = curv[1] if curv else 0 
            
            if not output_options [0]:
                QMessageBox.information(self.iface.mainWindow(), "Error!", str("Select an output option")) 
                return 
             #   LOADING CSV
             # uri = "file:///some/path/file.csv?delimiter=%s&crs=epsg:4723&wktField=%s" \
             # % (";", "shape")

            out_raster = Viewshed(ly_obs, ly_dem, z_obs, z_target, Radius,outPath,
                                  output_options,
                                  ly_target, search_top_obs, search_top_target,
                                  z_obs_field, z_target_field, curv, refraction,
                                  Algo)
            
            for r in out_raster:
                #QMessageBox.information(self.iface.mainWindow(), "debug", str(r))
                lyName = os.path.splitext(os.path.basename(r))
                layer = QgsRasterLayer(r, lyName[0])
                #if error -> it's shapefile, skip rendering...
                if not layer.isValid():
                    layer= QgsVectorLayer(r,lyName[0],"ogr")
                    
                else: 
                    layer.setContrastEnhancement(QgsContrastEnhancement.StretchToMinimumMaximum)
                    
                QgsMapLayerRegistry.instance().addMapLayer(layer)
    def run(self):
 

        #UBACIVANJE RASTERA I TOCAKA (mora biti ovdje ili se barem pozvati odavde)
        myLayers = []
        iface = self.iface
        #clear combos        
        self.dlg.ui.cmbRaster.clear();self.dlg.ui.cmbPoints.clear();self.dlg.ui.cmbPointsTarget.clear()
        #add an empty value to optional combo
        self.dlg.ui.cmbPointsTarget.addItem('',0)
        #add layers to combos
        for i in range(len(iface.mapCanvas().layers())):
            myLayer = iface.mapCanvas().layer(i)
            if myLayer.type() == myLayer.RasterLayer:

                #provjera da li je DEM 1 band .... !!!
                self.dlg.ui.cmbRaster.addItem(myLayer.name(),myLayer.id())

            elif myLayer.geometryType() == QGis.Point: 
                self.dlg.ui.cmbPoints.addItem(myLayer.name(),myLayer.id())
                self.dlg.ui.cmbPointsTarget.addItem(myLayer.name(),myLayer.id())

        #allAttrs = layer.pendingAllAttributesList()
       
                
        # show the dialog
        self.dlg.show()
        # Run the dialog event loop
        result = self.dlg.exec_()

        l = self.dlg.ui.cmbPoints.itemData(self.dlg.ui.cmbPoints.currentIndex())
        ly_name = str(l)
      #  QMessageBox.information(self.iface.mainWindow(), "drugi", str(ly_name))

        # See if OK was pressed
        
        if result == 1:
            outPath = ViewshedAnalysisDialog.returnOutputFile(self.dlg)
            ly_obs = ViewshedAnalysisDialog.returnPointLayer(self.dlg)
            ly_target = ViewshedAnalysisDialog.returnTargetLayer(self.dlg)
            ly_dem = ViewshedAnalysisDialog.returnRasterLayer(self.dlg)

            z_obs = ViewshedAnalysisDialog.returnObserverHeight(self.dlg) 
            z_obs_field = self.dlg.ui.cmbObsField.itemData(
                self.dlg.ui.cmbObsField.currentIndex())#table columns are indexed 0-n 

            z_target = ViewshedAnalysisDialog.returnTargetHeight(self.dlg) 
            z_target_field =self.dlg.ui.cmbTargetField.itemData(
                self.dlg.ui.cmbTargetField.currentIndex())       
            
            Radius = ViewshedAnalysisDialog.returnRadius(self.dlg)

            search_top_obs = ViewshedAnalysisDialog.returnSearchTopObserver(self.dlg)
            search_top_target = ViewshedAnalysisDialog.returnSearchTopTarget(self.dlg)
            
            output_options = ViewshedAnalysisDialog.returnOutputOptions(self.dlg)
                
            curv=ViewshedAnalysisDialog.returnCurvature(self.dlg)
            refraction = curv[1] if curv else 0 
            
            if not output_options [0]:
                QMessageBox.information(self.iface.mainWindow(), "Error!", str("Select an output option")) 
                return 
             #   LOADING CSV
             # uri = "file:///some/path/file.csv?delimiter=%s&crs=epsg:4723&wktField=%s" \
             # % (";", "shape")

            out_raster = Viewshed(ly_obs, ly_dem, z_obs, z_target, Radius,outPath,
                                  output_options,
                                  ly_target, search_top_obs, search_top_target,
                                  z_obs_field, z_target_field, curv, refraction)
            
            for r in out_raster:
                #QMessageBox.information(self.iface.mainWindow(), "debug", str(r))
                lyName = os.path.splitext(os.path.basename(r))
                layer = QgsRasterLayer(r, lyName[0])
                #if error -> it's shapefile, skip rendering...
                if not layer.isValid():
                    layer= QgsVectorLayer(r,lyName[0],"ogr")
                    
                else:
##                    #rlayer.setColorShadingAlgorithm(QgsRasterLayer.UndefinedShader)
##
##                    #from linfinity.com
##                    extentMin, extentMax = layer.computeMinimumMaximumFromLastExtent( band )
##
##                    # For greyscale layers there is only ever one band
##                    band = layer.bandNumber( layer.grayBandName() ) # base 1 counting in gdal
##                    # We don't want to create a lookup table
##                    generateLookupTableFlag = False
##                    # set the layer min value for this band
##                    layer.setMinimumValue( band, extentMin, generateLookupTableFlag )
##                    # set the layer max value for this band
##                    layer.setMaximumValue( band, extentMax, generateLookupTableFlag )
##
##                    # let the layer know that the min max are user defined
##                    layer.setUserDefinedGrayMinimumMaximum( True )
##
##                    # make sure the layer is redrawn
##                    layer.triggerRepaint()

                    #NOT WORKING 
                    
##                    x = QgsRasterTransparency.TransparentSingleValuePixel()
##                    x.pixelValue = 0
##                    x.transparencyPercent = 100
##                    layer.setTransparentSingleValuePixelList( [ x ] )
                    
                    layer.setContrastEnhancement(QgsContrastEnhancement.StretchToMinimumMaximum)

                    #rlayer.setDrawingStyle(QgsRasterLayer.SingleBandPseudoColor)
                    #rlayer.setColorShadingAlgorithm(QgsRasterLayer.PseudoColorShader)
                    #rlayer.setContrastEnhancementAlgorithm(QgsContrastEnhancement.StretchToMinimumMaximum, False)
                    #rlayer.setTransparency(200)
                    #rlayer.setNoDataValue(0.0)
                    
                QgsMapLayerRegistry.instance().addMapLayer(layer)
예제 #3
0
    def run(self):

        #UBACIVANJE RASTERA I TOCAKA (mora biti ovdje ili se barem pozvati odavde)
        myLayers = []
        iface = self.iface
        #clear combos
        self.dlg.ui.cmbRaster.clear()
        self.dlg.ui.cmbPoints.clear()
        self.dlg.ui.cmbPointsTarget.clear()
        #add an empty value to optional combo
        self.dlg.ui.cmbPointsTarget.addItem('', 0)
        #add layers to combos
        for i in range(len(iface.mapCanvas().layers())):
            myLayer = iface.mapCanvas().layer(i)
            if myLayer.type() == myLayer.RasterLayer:

                #provjera da li je DEM 1 band .... !!!
                self.dlg.ui.cmbRaster.addItem(myLayer.name(), myLayer.id())

            elif myLayer.geometryType() == QGis.Point:
                self.dlg.ui.cmbPoints.addItem(myLayer.name(), myLayer.id())
                self.dlg.ui.cmbPointsTarget.addItem(myLayer.name(),
                                                    myLayer.id())

        #allAttrs = layer.pendingAllAttributesList()

        # show the dialog
        self.dlg.show()
        # Run the dialog event loop
        result = self.dlg.exec_()

        l = self.dlg.ui.cmbPoints.itemData(
            self.dlg.ui.cmbPoints.currentIndex())
        ly_name = str(l)
        #  QMessageBox.information(self.iface.mainWindow(), "drugi", str(ly_name))

        # See if OK was pressed

        if result == 1:
            outPath = ViewshedAnalysisDialog.returnOutputFile(self.dlg)
            ly_obs = ViewshedAnalysisDialog.returnPointLayer(self.dlg)
            ly_target = ViewshedAnalysisDialog.returnTargetLayer(self.dlg)
            ly_dem = ViewshedAnalysisDialog.returnRasterLayer(self.dlg)

            z_obs = ViewshedAnalysisDialog.returnObserverHeight(self.dlg)
            z_obs_field = self.dlg.ui.cmbObsField.itemData(
                self.dlg.ui.cmbObsField.currentIndex()
            )  #table columns are indexed 0-n

            z_target = ViewshedAnalysisDialog.returnTargetHeight(self.dlg)
            z_target_field = self.dlg.ui.cmbTargetField.itemData(
                self.dlg.ui.cmbTargetField.currentIndex())

            Radius = ViewshedAnalysisDialog.returnRadius(self.dlg)

            search_top_obs = ViewshedAnalysisDialog.returnSearchTopObserver(
                self.dlg)
            search_top_target = ViewshedAnalysisDialog.returnSearchTopTarget(
                self.dlg)

            output_options = ViewshedAnalysisDialog.returnOutputOptions(
                self.dlg)

            curv = ViewshedAnalysisDialog.returnCurvature(self.dlg)
            refraction = curv[1] if curv else 0

            if not output_options[0]:
                QMessageBox.information(self.iface.mainWindow(), "Error!",
                                        str("Select an output option"))
                return
            #   LOADING CSV
            # uri = "file:///some/path/file.csv?delimiter=%s&crs=epsg:4723&wktField=%s" \
            # % (";", "shape")

            out_raster = Viewshed(ly_obs, ly_dem, z_obs, z_target, Radius,
                                  outPath, output_options, ly_target,
                                  search_top_obs, search_top_target,
                                  z_obs_field, z_target_field, curv,
                                  refraction)

            for r in out_raster:
                #QMessageBox.information(self.iface.mainWindow(), "debug", str(r))
                lyName = os.path.splitext(os.path.basename(r))
                layer = QgsRasterLayer(r, lyName[0])
                #if error -> it's shapefile, skip rendering...
                if not layer.isValid():
                    layer = QgsVectorLayer(r, lyName[0], "ogr")

                else:
                    ##                    #rlayer.setColorShadingAlgorithm(QgsRasterLayer.UndefinedShader)
                    ##
                    ##                    #from linfinity.com
                    ##                    extentMin, extentMax = layer.computeMinimumMaximumFromLastExtent( band )
                    ##
                    ##                    # For greyscale layers there is only ever one band
                    ##                    band = layer.bandNumber( layer.grayBandName() ) # base 1 counting in gdal
                    ##                    # We don't want to create a lookup table
                    ##                    generateLookupTableFlag = False
                    ##                    # set the layer min value for this band
                    ##                    layer.setMinimumValue( band, extentMin, generateLookupTableFlag )
                    ##                    # set the layer max value for this band
                    ##                    layer.setMaximumValue( band, extentMax, generateLookupTableFlag )
                    ##
                    ##                    # let the layer know that the min max are user defined
                    ##                    layer.setUserDefinedGrayMinimumMaximum( True )
                    ##
                    ##                    # make sure the layer is redrawn
                    ##                    layer.triggerRepaint()

                    #NOT WORKING

                    ##                    x = QgsRasterTransparency.TransparentSingleValuePixel()
                    ##                    x.pixelValue = 0
                    ##                    x.transparencyPercent = 100
                    ##                    layer.setTransparentSingleValuePixelList( [ x ] )

                    layer.setContrastEnhancement(
                        QgsContrastEnhancement.StretchToMinimumMaximum)

                    #rlayer.setDrawingStyle(QgsRasterLayer.SingleBandPseudoColor)
                    #rlayer.setColorShadingAlgorithm(QgsRasterLayer.PseudoColorShader)
                    #rlayer.setContrastEnhancementAlgorithm(QgsContrastEnhancement.StretchToMinimumMaximum, False)
                    #rlayer.setTransparency(200)
                    #rlayer.setNoDataValue(0.0)

                QgsMapLayerRegistry.instance().addMapLayer(layer)