Ejemplo n.º 1
0
    def calc_10_cbesar(self, dir_output, dir_e_10, temp_folder,
                       val_attransmit1):
        self.dir_output = dir_output
        self.path = os.path.join(str(Path(dir_output).parent), 'temp_folder',
                                 '')

        self.temp_folder = temp_folder
        self.dir_e_10 = dir_e_10
        self.dir_output_temp = self.path + '10 - C besar.tif'

        self.val_attransmit1 = val_attransmit1

        entries = []

        e_10 = QgsRasterLayer(self.dir_e_10)
        ras = QgsRasterCalculatorEntry()
        ras.ref = '10 - e@1'
        ras.raster = e_10
        ras.bandNumber = 1
        entries.append(ras)

        if self.temp_folder == 'yes':
            calc = QgsRasterCalculator(
                '"10 - e@1" * ' + str(self.val_attransmit1),
                self.dir_output_temp, 'GTiff', e_10.extent(), e_10.width(),
                e_10.height(), entries)
            calc.processCalculation()
        elif self.temp_folder == 'no':
            calc = QgsRasterCalculator(
                '"10 - e@1" * ' + str(self.val_attransmit1), self.dir_output,
                'GTiff', e_10.extent(), e_10.width(), e_10.height(), entries)
            calc.processCalculation()
            iface.addRasterLayer(str(self.dir_output))
Ejemplo n.º 2
0
 def run_clicked(self):
     start = clock()
     self.setEnabled(False)
     input = self.layerPath
     if unicode(self.output.text()) == '':
         try:
             output = os.environ['temp']+'out'+unicode(int(clock()*10000))+'.tif'
         except:
             if os.access('/tmp/kuw_filter', os.F_OK)==False:
                 os.mkdir('/tmp/kuw_filter')
             output = '/tmp/kuw_filter/out'+unicode(int(clock()*10000))+'.tif'
     else:
        output = unicode(self.output.text())
     refb = int(self.refb.text())
     memuse = int(self.mem.text())
     self.setCursor(QCursor(Qt.WaitCursor))
     if dofilter(self, input, output, refb, memuse) :
         self.msgbox(QApplication.translate('kuw_filterdialog','Time elapsed:\n ', None, QApplication.UnicodeUTF8)+unicode(int((clock()-start)/3600))+'h'+unicode(int((clock()-start)/60))+'m'+unicode((0.5+clock()-start)%60)[0:5]+'s')
         if self.addout.isChecked():
             fileName = unicode(output)
             fileInfo = QFileInfo(fileName)
             baseName = fileInfo.baseName()
             iface.addRasterLayer(fileName, baseName)
     self.setCursor(QCursor(Qt.ArrowCursor))
     self.setEnabled(True)
     self.close()
 def run_clicked(self):
     self.setEnabled(False)
     input = self.inputbox.currentLayer().source()
     if str(self.output.text()) == '':
         try:
             output = os.environ['temp']+'out'+str(int(clock()*10000))+'.tif'
         except:
             if os.access('/tmp/kuw_filter', os.F_OK)==False:
                 os.mkdir('/tmp/kuw_filter')
             output = '/tmp/kuw_filter/out'+str(int(clock()*10000))+'.tif'
     else:
        output = str(self.output.text())
     self.setCursor(QCursor(Qt.WaitCursor))
     start = dt.datetime.now()
     if doFilter(self, input, output):
         elapsed = dt.datetime.now() - start
         elapsed = str(dt.timedelta(seconds=round(elapsed.total_seconds())))
         self.msgbox(QApplication.translate('kuw_filterdialog','Time elapsed:\n ')+elapsed)
         if self.addout.isChecked():
             fileName = str(output)
             fileInfo = QFileInfo(fileName)
             baseName = fileInfo.baseName()
             iface.addRasterLayer(fileName, baseName)
     self.setCursor(QCursor(Qt.ArrowCursor))
     self.setEnabled(True)
     self.close()
Ejemplo n.º 4
0
    def calc_11_d(self, dir_output, dir_e_11, temp_folder, val_attransmit2):
        self.dir_output = dir_output
        self.path = os.path.join(str(Path(dir_output).parent), 'temp_folder',
                                 '')

        self.temp_folder = temp_folder
        self.dir_e_11 = dir_e_11
        self.dir_output_temp = self.path + '11 - D.tif'

        self.val_attransmit2 = val_attransmit2

        entries = []

        e_11 = QgsRasterLayer(self.dir_e_11)
        ras = QgsRasterCalculatorEntry()
        ras.ref = '11 - e@1'
        ras.raster = e_11
        ras.bandNumber = 1
        entries.append(ras)

        if self.temp_folder == 'yes':
            calc = QgsRasterCalculator(
                '( 1 - ' + str(self.val_attransmit2) +
                ' )* ( 1 + ( 1 - "11 - e@1" ) * ' +
                str(self.val_attransmit2) + ')', self.dir_output_temp, 'GTiff',
                e_11.extent(), e_11.width(), e_11.height(), entries)
            calc.processCalculation()
        elif self.temp_folder == 'no':
            calc = QgsRasterCalculator(
                '( 1 - ' + str(self.val_attransmit2) +
                ' )* ( 1 + ( 1 - "11 - e@1" ) * ' + str(self.val_attransmit2) +
                ')', self.dir_output, 'GTiff', e_11.extent(), e_11.width(),
                e_11.height(), entries)
            calc.processCalculation()
            iface.addRasterLayer(str(self.dir_output))
Ejemplo n.º 5
0
    def calc_11_toa_L7(self, dir_output, dir_btir2, temp_folder):
        self.temp_folder = temp_folder
        self.dir_output = dir_output
        self.dir_btir2 = dir_btir2
        self.dir_output_temp = str(
            Path(dir_output).parent) + '\temp_folder\\11 - TOA.tif'

        entries = []

        band11 = QgsRasterLayer(self.dir_btir2)
        ras = QgsRasterCalculatorEntry()
        ras.ref = 'band11@1'
        ras.raster = band11
        ras.bandNumber = 1
        entries.append(ras)

        if self.temp_folder == 'yes':
            calc = QgsRasterCalculator(
                '((17.04 - 0) / (255 - 1)) * ("band11@1" - 1) + 0',
                self.dir_output_temp, 'GTiff', band11.extent(), band11.width(),
                band11.height(), entries)
            calc.processCalculation()
        elif self.temp_folder == 'no':
            calc = QgsRasterCalculator(
                '((17.04 - 0) / (255 - 1)) * ("band11@1" - 1) + 0',
                self.dir_output, 'GTiff', band11.extent(), band11.width(),
                band11.height(), entries)
            calc.processCalculation()
            iface.addRasterLayer(str(self.dir_output))
Ejemplo n.º 6
0
    def calc_10_toa(self, dir_output, dir_btir1, temp_folder, val_tir1_rmult,
                    val_tir1_radd):
        self.dir_output = dir_output
        self.path = os.path.join(str(Path(dir_output).parent), 'temp_folder',
                                 '')

        self.temp_folder = temp_folder
        self.dir_btir1 = dir_btir1
        self.dir_output_temp = self.path + '10 - TOA.tif'
        self.val_tir1_rmult = val_tir1_rmult
        self.val_tir1_radd = val_tir1_radd

        entries = []

        band10 = QgsRasterLayer(self.dir_btir1)
        ras = QgsRasterCalculatorEntry()
        ras.ref = 'band10@1'
        ras.raster = band10
        ras.bandNumber = 1
        entries.append(ras)

        if self.temp_folder == 'yes':
            calc = QgsRasterCalculator(
                str(self.val_tir1_rmult) + '* "band10@1" +' +
                str(self.val_tir1_radd), self.dir_output_temp, 'GTiff',
                band10.extent(), band10.width(), band10.height(), entries)
            calc.processCalculation()
        elif self.temp_folder == 'no':
            calc = QgsRasterCalculator(
                str(self.val_tir1_rmult) + '* "band10@1" +' +
                str(self.val_tir1_radd), self.dir_output, 'GTiff',
                band10.extent(), band10.width(), band10.height(), entries)
            calc.processCalculation()
            iface.addRasterLayer(str(self.dir_output))
Ejemplo n.º 7
0
 def run_clicked(self):
     start = clock()
     self.setEnabled(False)
     input = self.layerPath
     if unicode(self.output.text()) == '':
         try:
             output = os.environ['temp'] + 'out' + unicode(
                 int(clock() * 10000)) + '.tif'
         except:
             if os.access('/tmp/kuw_filter', os.F_OK) == False:
                 os.mkdir('/tmp/kuw_filter')
             output = '/tmp/kuw_filter/out' + unicode(int(
                 clock() * 10000)) + '.tif'
     else:
         output = unicode(self.output.text())
     refb = int(self.refb.text())
     memuse = int(self.mem.text())
     self.setCursor(QCursor(Qt.WaitCursor))
     if dofilter(self, input, output, refb, memuse):
         self.msgbox(
             QApplication.translate('kuw_filterdialog', 'Time elapsed:\n ',
                                    None, QApplication.UnicodeUTF8) +
             unicode(int((clock() - start) / 3600)) + 'h' +
             unicode(int((clock() - start) / 60)) + 'm' +
             unicode((0.5 + clock() - start) % 60)[0:5] + 's')
         if self.addout.isChecked():
             fileName = unicode(output)
             fileInfo = QFileInfo(fileName)
             baseName = fileInfo.baseName()
             iface.addRasterLayer(fileName, baseName)
     self.setCursor(QCursor(Qt.ArrowCursor))
     self.setEnabled(True)
     self.close()
Ejemplo n.º 8
0
    def calc_10_bt_L7(
        self,
        dir_output,
        dir_toa_10,
        temp_folder,
    ):
        self.temp_folder = temp_folder
        dir_output = self.dlg.fw_output.filePath()
        dir_toa_10 = str(
            Path(dir_output).parent) + '\\temp_folder\\10 - TOA.tif'
        dir_output_temp = str(
            Path(dir_output).parent) + '\\temp_folder\\10 - BT.tif'

        entries = []

        toa_10 = QgsRasterLayer(output_toa_10)
        ras = QgsRasterCalculatorEntry()
        ras.ref = '10 - TOA@1'
        ras.raster = toa_10
        ras.bandNumber = 1
        entries.append(ras)

        if self.temp_folder == 'yes':
            calc = QgsRasterCalculator(
                str(L_TIR1_K2_L7) + ' / ln ( ( ' + str(L_TIR1_K1_L7) +
                ' / "10 - TOA@1" ) + 1 )', output_bt_10, 'GTiff',
                toa_10.extent(), toa_10.width(), toa_10.height(), entries)
            calc.processCalculation()
        elif self.temp_folder == 'no':
            calc = QgsRasterCalculator(
                str(L_TIR1_K2_L7) + ' / ln ( ( ' + str(L_TIR1_K1_L7) +
                ' / "10 - TOA@1" ) + 1 )', output_bt_10, 'GTiff',
                toa_10.extent(), toa_10.width(), toa_10.height(), entries)
            calc.processCalculation()
            iface.addRasterLayer(str(self.dir_output))
Ejemplo n.º 9
0
 def finished(self, result):
     """This function is called automatically when the task is completed and is
     called from the main thread so it is safe to interact with the GUI etc here"""
     if result is False:
         iface.messageBar().pushMessage(QCoreApplication.translate('Task message','Task was cancelled'))
     else:
         iface.addRasterLayer(self.rasterAvalicaoPath)
         iface.messageBar().pushMessage(QCoreApplication.translate('Task message','Complete'))
Ejemplo n.º 10
0
    def calc_e1(self, dir_output, dir_D_11, dir_C_besar_10, dir_D_10, dir_E0,
                temp_folder):
        self.dir_output = dir_output
        self.path = os.path.join(str(Path(dir_output).parent), 'temp_folder',
                                 '')

        self.temp_folder = temp_folder
        self.dir_D_11 = dir_D_11
        self.dir_C_besar_10 = dir_C_besar_10
        self.dir_D_10 = dir_D_10
        self.dir_E0 = dir_E0
        self.dir_output_temp = self.path + 'E1.tif'

        entries = []

        D_11 = QgsRasterLayer(self.dir_D_11)
        ras = QgsRasterCalculatorEntry()
        ras.ref = '11 - D@1'
        ras.raster = D_11
        ras.bandNumber = 1
        entries.append(ras)

        C_besar_10 = QgsRasterLayer(self.dir_C_besar_10)
        ras = QgsRasterCalculatorEntry()
        ras.ref = '10 - C besar@1'
        ras.raster = C_besar_10
        ras.bandNumber = 1
        entries.append(ras)

        D_10 = QgsRasterLayer(self.dir_D_10)
        ras = QgsRasterCalculatorEntry()
        ras.ref = '10 - D@1'
        ras.raster = D_10
        ras.bandNumber = 1
        entries.append(ras)

        E0 = QgsRasterLayer(self.dir_E0)
        ras = QgsRasterCalculatorEntry()
        ras.ref = 'E0@1'
        ras.raster = E0
        ras.bandNumber = 1
        entries.append(ras)

        if self.temp_folder == 'yes':
            calc = QgsRasterCalculator(
                '"11 - D@1" * ( 1 - "10 - C besar@1" - "10 - D@1" ) / "E0@1"',
                self.dir_output_temp, 'GTiff', E0.extent(), E0.width(),
                E0.height(), entries)
            calc.processCalculation()
        elif self.temp_folder == 'no':
            calc = QgsRasterCalculator(
                '"11 - D@1" * ( 1 - "10 - C besar@1" - "10 - D@1" ) / "E0@1"',
                self.dir_output, 'GTiff', E0.extent(), E0.width(), E0.height(),
                entries)
            calc.processCalculation()
            iface.addRasterLayer(str(self.dir_output))
Ejemplo n.º 11
0
    def clipRaster(self, vec, path, forClip):

        gdal.UseExceptions()
        vecClip = vec
        ras = path
        output = forClip + "_clipped.tif"
        result = gdal.Warp(destNameOrDestDS=output, srcDSOrSrcDSTab=ras, cutlineDSName=vecClip)
        result = None
        QMessageBox.information(self.dlg, "Message", "clipRaster")
        iface.addRasterLayer(output)
Ejemplo n.º 12
0
 def densityInex_calc(self):
     layer_ndvi = self.dlg.Densitymcb_input_NDVI.currentLayer()
     layer_ndbi = self.dlg.Densitymcb_input_NDBI.currentLayer()
     outputCheckPath = self.dlg.DensityFile_output.filePath()
     save_file_path = outputCheckPath + '.tif'
     if self.outputCheck(outputCheckPath):
         entries = [
             self.addRasterCalculatorEntry("NDVI@1", layer_ndvi),
             self.addRasterCalculatorEntry("NDBI@2", layer_ndbi),
         ]
         self.runRasterCalculator('("NDBI@2" - "NDVI@1")', save_file_path, layer_ndvi, entries)
         QMessageBox.information(self.dlg, "Message", "densitiy Index CALC")
         iface.addRasterLayer(save_file_path)
Ejemplo n.º 13
0
def displayOnScreen(resultStates, filer):

    """
    Display generated outputs as layers on the interface
    """

    resultNames = []
    for res in resultStates:
        resultNames.append(res[1])

    for i in range(6):
        if resultStates[i][0]:
            iface.addRasterLayer(
                filer.generateFileName(resultNames[i], "TIF"), resultNames[i]
            )
Ejemplo n.º 14
0
    def workerFinished(self, ret):
        #Clean up the worker and thread
        self.worker.deleteLater()
        self.thread.quit()
        self.thread.wait()
        self.thread.deleteLater()

        #Remove widget from messagebar
        iface.messageBar().popWidget()
        if ret is not None:
            #Add the project to the map
            iface.addRasterLayer(ret, self.processName)
        else:
            #Notify the user that an error has occurred
            iface.messageBar().pushMessage("Error","Something went wrong! See the message log for more information")
Ejemplo n.º 15
0
def style_prod_state_emerg(outfile):
    # Significance layer
    layer = iface.addRasterLayer(outfile, 'Productivity state (emerging)')
    fcn = QgsColorRampShader()
    fcn.setColorRampType(QgsColorRampShader.EXACT)
    lst = [
        QgsColorRampShader.ColorRampItem(-2, QtGui.QColor(0, 0, 0), 'No data'),
        QgsColorRampShader.ColorRampItem(-1, QtGui.QColor(153, 51, 4),
                                         'Significant decrease'),
        QgsColorRampShader.ColorRampItem(0, QtGui.QColor(246, 246, 234),
                                         'No significant change'),
        QgsColorRampShader.ColorRampItem(1, QtGui.QColor(0, 140, 121),
                                         'Significant increase'),
        QgsColorRampShader.ColorRampItem(2, QtGui.QColor(58, 77, 214),
                                         'Water'),
        QgsColorRampShader.ColorRampItem(3, QtGui.QColor(192, 105, 223),
                                         'Urban land cover')
    ]
    fcn.setColorRampItemList(lst)
    shader = QgsRasterShader()
    shader.setRasterShaderFunction(fcn)
    pseudoRenderer = QgsSingleBandPseudoColorRenderer(layer.dataProvider(), 1,
                                                      shader)
    layer.setRenderer(pseudoRenderer)
    layer.triggerRepaint()
    iface.legendInterface().refreshLayerSymbology(layer)
Ejemplo n.º 16
0
def style_prod_traj_trend(outfile):
    # Trends layer
    layer_ndvi = iface.addRasterLayer(outfile, 'Productivity trajectory trend')
    provider = layer_ndvi.dataProvider()
    # Set a colormap centred on zero, going to the extreme value significant to
    # three figures
    stats = provider.bandStatistics(1, QgsRasterBandStats.All)
    #TODO: Make this a 2% stretch rather than simple linear stretch
    extreme = get_extreme(stats.minimumValue, stats.maximumValue)
    fcn = QgsColorRampShader()
    fcn.setColorRampType(QgsColorRampShader.INTERPOLATED)
    lst = [
        QgsColorRampShader.ColorRampItem(-extreme, QtGui.QColor(153, 51, 4),
                                         '-{} (declining)'.format(extreme)),
        QgsColorRampShader.ColorRampItem(0, QtGui.QColor(246, 246, 234),
                                         '0 (stable)'),
        QgsColorRampShader.ColorRampItem(extreme, QtGui.QColor(0, 140, 121),
                                         '{} (increasing)'.format(extreme))
    ]
    fcn.setColorRampItemList(lst)
    shader = QgsRasterShader()
    shader.setRasterShaderFunction(fcn)
    pseudoRenderer = QgsSingleBandPseudoColorRenderer(
        layer_ndvi.dataProvider(), 1, shader)
    layer_ndvi.setRenderer(pseudoRenderer)
    layer_ndvi.triggerRepaint()
    iface.legendInterface().refreshLayerSymbology(layer_ndvi)
Ejemplo n.º 17
0
def style_land_cover_land_deg(outfile):
    layer_deg = iface.addRasterLayer(
        outfile,
        QtGui.QApplication.translate('LDMPPlugin', 'Land cover (degradation)'))
    if not layer_deg.isValid():
        log('Failed to add layer')
        return None
    fcn = QgsColorRampShader()
    fcn.setColorRampType(QgsColorRampShader.EXACT)
    #TODO The GPG doesn't seem to allow for possibility of improvement...?
    lst = [
        QgsColorRampShader.ColorRampItem(
            -1, QtGui.QColor(153, 51, 4),
            QtGui.QApplication.translate('LDMPPlugin', 'Degradation')),
        QgsColorRampShader.ColorRampItem(
            0, QtGui.QColor(246, 246, 234),
            QtGui.QApplication.translate('LDMPPlugin', 'Stable')),
        QgsColorRampShader.ColorRampItem(
            1, QtGui.QColor(0, 140, 121),
            QtGui.QApplication.translate('LDMPPlugin', 'Improvement'))
    ]
    fcn.setColorRampItemList(lst)
    shader = QgsRasterShader()
    shader.setRasterShaderFunction(fcn)
    pseudoRenderer = QgsSingleBandPseudoColorRenderer(layer_deg.dataProvider(),
                                                      1, shader)
    layer_deg.setRenderer(pseudoRenderer)
    layer_deg.triggerRepaint()
    iface.legendInterface().refreshLayerSymbology(layer_deg)
Ejemplo n.º 18
0
def style_land_cover_lc_target(outfile):
    layer_lc_target = iface.addRasterLayer(outfile, 'Land cover (target)')
    fcn = QgsColorRampShader()
    fcn.setColorRampType(QgsColorRampShader.EXACT)
    lst = [
        QgsColorRampShader.ColorRampItem(1, QtGui.QColor('#a50f15'),
                                         'Cropland'),
        QgsColorRampShader.ColorRampItem(2, QtGui.QColor('#006d2c'),
                                         'Forest land'),
        QgsColorRampShader.ColorRampItem(3, QtGui.QColor('#d8d800'),
                                         'Grassland'),
        QgsColorRampShader.ColorRampItem(4, QtGui.QColor('#08519c'),
                                         'Wetlands'),
        QgsColorRampShader.ColorRampItem(5, QtGui.QColor('#54278f'),
                                         'Settlements'),
        QgsColorRampShader.ColorRampItem(6, QtGui.QColor('#252525'),
                                         'Other land')
    ]
    fcn.setColorRampItemList(lst)
    shader = QgsRasterShader()
    shader.setRasterShaderFunction(fcn)
    pseudoRenderer = QgsSingleBandPseudoColorRenderer(
        layer_lc_target.dataProvider(), 1, shader)
    layer_lc_target.setRenderer(pseudoRenderer)
    layer_lc_target.triggerRepaint()
    iface.legendInterface().refreshLayerSymbology(layer_lc_target)
Ejemplo n.º 19
0
    def calc_11_e(self, dir_output, dir_pv, dir_c_kecil_11, temp_folder,
                  val_tir2emissivitys, val_tir2emissivityv):
        self.dir_output = dir_output
        self.path = os.path.join(str(Path(dir_output).parent), 'temp_folder',
                                 '')

        self.temp_folder = temp_folder
        self.dir_pv = dir_pv
        self.dir_c_kecil_11 = dir_c_kecil_11
        self.dir_output_temp = self.path + '11 - e.tif'

        self.val_tir2emissivitys = val_tir2emissivitys
        self.val_tir2emissivityv = val_tir2emissivityv

        entries = []

        pv = QgsRasterLayer(self.dir_pv)
        ras = QgsRasterCalculatorEntry()
        ras.ref = 'Pv@1'
        ras.raster = pv
        ras.bandNumber = 1
        entries.append(ras)

        c_kecil_11 = QgsRasterLayer(self.dir_c_kecil_11)
        ras = QgsRasterCalculatorEntry()
        ras.ref = '11 - c kecil@1'
        ras.raster = c_kecil_11
        ras.bandNumber = 1
        entries.append(ras)

        if self.temp_folder == 'yes':
            calc = QgsRasterCalculator(
                str(self.val_tir2emissivityv) + ' * "Pv@1" + ' +
                str(self.val_tir2emissivitys) +
                ' * ( 1 - "Pv@1" ) + "11 - c kecil@1"', self.dir_output_temp,
                'GTiff', c_kecil_11.extent(), c_kecil_11.width(),
                c_kecil_11.height(), entries)
            calc.processCalculation()
        elif self.temp_folder == 'no':
            calc = QgsRasterCalculator(
                str(self.val_tir2emissivityv) + ' * "Pv@1" + ' +
                str(self.val_tir2emissivitys) +
                ' * ( 1 - "Pv@1" ) + "11 - c kecil@1"', self.dir_output,
                'GTiff', c_kecil_11.extent(), c_kecil_11.width(),
                c_kecil_11.height(), entries)
            calc.processCalculation()
            iface.addRasterLayer(str(self.dir_output))
Ejemplo n.º 20
0
 def ndvi_calc(self):
     layer_ndvi_nir = self.dlg.NDVImcb_input_NIR.currentLayer()
     layer_ndvi_red = self.dlg.NDVImcb_input_RED.currentLayer()
     forClip = self.dlg.NDVIFile_output.filePath()
     save_file_path = forClip + '.tif'
     vec = self.dlg.NDVIFile_vector.filePath()
     if self.outputCheck(forClip):
         entries = [
             self.addRasterCalculatorEntry("NIR@1", layer_ndvi_nir),
             self.addRasterCalculatorEntry("RED@2", layer_ndvi_red),
         ]
         self.runRasterCalculator('("NIR@1" - "RED@2") / ("NIR@1" + "RED@2")', save_file_path, layer_ndvi_nir,
                                  entries)
         if vec:
             self.clipRaster(vec, save_file_path, forClip)
         else:
             QMessageBox.information(self.dlg, "Message", "ndvi calc")
             iface.addRasterLayer(save_file_path)
Ejemplo n.º 21
0
    def calc_a0(self, dir_output, dir_E1, dir_E2, temp_folder, A10, A11):
        self.dir_output = dir_output
        self.path = os.path.join(str(Path(dir_output).parent), 'temp_folder',
                                 '')

        self.temp_folder = temp_folder
        self.dir_E1 = dir_E1
        self.dir_E2 = dir_E2
        self.dir_output_temp = self.path + 'A0.tif'

        self.A10 = A10
        self.A11 = A11

        entries = []

        E1 = QgsRasterLayer(self.dir_E1)
        ras = QgsRasterCalculatorEntry()
        ras.ref = 'E1@1'
        ras.raster = E1
        ras.bandNumber = 1
        entries.append(ras)

        E2 = QgsRasterLayer(self.dir_E2)
        ras = QgsRasterCalculatorEntry()
        ras.ref = 'E2@1'
        ras.raster = E2
        ras.bandNumber = 1
        entries.append(ras)

        if self.temp_folder == 'yes':
            calc = QgsRasterCalculator(
                '"E1@1" * ' + self.A10 + ' + "E2@1" * ' + self.A11,
                self.dir_output_temp, 'GTiff', E2.extent(), E2.width(),
                E2.height(), entries)
            calc.processCalculation()
        elif self.temp_folder == 'no':
            calc = QgsRasterCalculator(
                '"E1@1" * ' + self.A10 + ' + "E2@1" * ' + self.A11,
                self.dir_output, 'GTiff', E2.extent(), E2.width(), E2.height(),
                entries)
            calc.processCalculation()
            iface.addRasterLayer(str(self.dir_output))
Ejemplo n.º 22
0
    def pyratToLayer(layerid=None):
        """Exports a PyRAT-layer into QGIS"""
        if type(layerid) is str:
            pyrat.data.activateLayer(layerid)
        annotation = pyrat.data.getAnnotation()
        if 'info' in annotation:
            filename = path.join(pyrat.data.tmpdir,
                                 annotation['info'] + ".rat")
        else:
            filename = path.join(pyrat.data.tmpdir, "PyRAT.rat")

        filename, s = QFileDialog.getSaveFileName(iface.mainWindow(),
                                                  "Save the PyRAT-Layer",
                                                  filename, "RAT-File (*.rat)")

        if not s or filename == "":
            return

        pyrat.save.rat((filename, "rat"), geo_envi_hdr=True)
        iface.addRasterLayer(filename, path.basename(filename).split(".")[0])
Ejemplo n.º 23
0
 def final(self):
     if self.dlg.cb_ARVI.isChecked():
         self.calc_arvi()
         if self.dlg.cb_load.isChecked():
             out = iface.addRasterLayer(os.path.join(self.dlg.le_output.text(),"arvi.tif"))
     if self.dlg.cb_BRI.isChecked():
         self.calc_bri()
         if self.dlg.cb_load.isChecked():
             out = iface.addRasterLayer(os.path.join(self.dlg.le_output.text(),"bri.tif"))
     if self.dlg.cb_CVI.isChecked():
         self.calc_cvi()
         if self.dlg.cb_load.isChecked():
             out = iface.addRasterLayer(os.path.join(self.dlg.le_output.text(),"cvi.tif"))
     if self.dlg.cb_GCI.isChecked():
         self.calc_gci()
         if self.dlg.cb_load.isChecked():
             out = iface.addRasterLayer(os.path.join(self.dlg.le_output.text(),"gci.tif"))
     if self.dlg.cb_NBRI.isChecked():
         self.calc_nbri()
         if self.dlg.cb_load.isChecked():
             out = iface.addRasterLayer(os.path.join(self.dlg.le_output.text(),"nbri.tif"))
     if self.dlg.cb_GVMI.isChecked():
         self.calc_gvmi()
         if self.dlg.cb_load.isChecked():
             out = iface.addRasterLayer(os.path.join(self.dlg.le_output.text(),"gvmi.tif"))
     if self.dlg.cb_NDSI.isChecked():
         self.calc_ndsi()
         if self.dlg.cb_load.isChecked():
             out = iface.addRasterLayer(os.path.join(self.dlg.le_output.text(),"ndsi.tif"))
     if self.dlg.cb_NDVI.isChecked():
         self.calc_ndvi()
         if self.dlg.cb_load.isChecked():
             out = iface.addRasterLayer(os.path.join(self.dlg.le_output.text(),"ndvi.tif"))
     if self.dlg.cb_SAVI.isChecked():
         self.calc_savi()
         if self.dlg.cb_load.isChecked():
             out = iface.addRasterLayer(os.path.join(self.dlg.le_output.text(),"savi.tif"))
     if self.dlg.cb_SIPI.isChecked():
         self.calc_sipi()
         if self.dlg.cb_load.isChecked():
             out = iface.addRasterLayer(os.path.join(self.dlg.le_output.text(),"sipi.tif"))
Ejemplo n.º 24
0
    def calc_11_ckecil(self, dir_output, dir_pv, temp_folder,
                       val_tir2emissivitys, val_tir2emissivityv,
                       val_geometrical):
        self.dir_output = dir_output
        self.path = os.path.join(str(Path(dir_output).parent), 'temp_folder',
                                 '')

        self.temp_folder = temp_folder
        self.dir_pv = dir_pv
        self.dir_output_temp = self.path + '11 - c kecil.tif'

        self.val_tir2emissivitys = val_tir2emissivitys
        self.val_tir2emissivityv = val_tir2emissivityv
        self.val_geometrical = val_geometrical

        entries = []

        pv = QgsRasterLayer(self.dir_pv)
        ras = QgsRasterCalculatorEntry()
        ras.ref = 'Pv@1'
        ras.raster = pv
        ras.bandNumber = 1
        entries.append(ras)

        if self.temp_folder == 'yes':
            calc = QgsRasterCalculator(
                '( 1 - ' + str(self.val_tir2emissivitys) + ' ) * ' +
                str(self.val_tir2emissivityv) + ' * ' +
                str(self.val_geometrical) + ' * ( 1 - "Pv@1" )',
                self.dir_output_temp, 'GTiff', pv.extent(), pv.width(),
                pv.height(), entries)
            calc.processCalculation()
        elif self.temp_folder == 'no':
            calc = QgsRasterCalculator(
                '( 1 - ' + str(self.val_tir2emissivitys) + ' ) * ' +
                str(self.val_tir2emissivityv) + ' * ' +
                str(self.val_geometrical) + ' * ( 1 - "Pv@1" )',
                self.dir_output, 'GTiff', pv.extent(), pv.width(), pv.height(),
                entries)
            calc.processCalculation()
            iface.addRasterLayer(str(self.dir_output))
Ejemplo n.º 25
0
def style_prod_traj_trend(outfile):
    # Trends layer
    layer_ndvi = iface.addRasterLayer(
        outfile,
        QtGui.QApplication.translate(
            'LDMPPlugin',
            'Productivity trajectory trend\n(slope of NDVI * 10000)'))
    if not layer_ndvi.isValid():
        log('Failed to add layer')
        return None
    provider = layer_ndvi.dataProvider()

    # Set a colormap centred on zero, going to the extreme value significant to
    # three figures (after a 2 percent stretch)
    ds = gdal.Open(outfile)
    band1 = np.array(ds.GetRasterBand(1).ReadAsArray())
    band1[band1 >= 9997] = 0
    ds = None
    cutoffs = np.percentile(band1, [2, 98])
    extreme = get_extreme(cutoffs[0], cutoffs[1])

    fcn = QgsColorRampShader()
    fcn.setColorRampType(QgsColorRampShader.INTERPOLATED)
    lst = [
        QgsColorRampShader.ColorRampItem(
            -extreme, QtGui.QColor(153, 51, 4),
            QtGui.QApplication.translate('LDMPPlugin',
                                         '-{} (declining)').format(extreme)),
        QgsColorRampShader.ColorRampItem(
            0, QtGui.QColor(246, 246, 234),
            QtGui.QApplication.translate('LDMPPlugin', '0 (stable)')),
        QgsColorRampShader.ColorRampItem(
            extreme, QtGui.QColor(0, 140, 121),
            QtGui.QApplication.translate('LDMPPlugin',
                                         '{} (increasing)').format(extreme)),
        QgsColorRampShader.ColorRampItem(
            9997, QtGui.QColor(0, 0, 0),
            QtGui.QApplication.translate('LDMPPlugin', 'No data')),
        QgsColorRampShader.ColorRampItem(
            9998, QtGui.QColor(58, 77, 214),
            QtGui.QApplication.translate('LDMPPlugin', 'Water')),
        QgsColorRampShader.ColorRampItem(
            9999, QtGui.QColor(192, 105, 223),
            QtGui.QApplication.translate('LDMPPlugin', 'Urban land cover'))
    ]
    fcn.setColorRampItemList(lst)
    shader = QgsRasterShader()
    shader.setRasterShaderFunction(fcn)
    pseudoRenderer = QgsSingleBandPseudoColorRenderer(
        layer_ndvi.dataProvider(), 1, shader)
    layer_ndvi.setRenderer(pseudoRenderer)
    layer_ndvi.triggerRepaint()
    iface.legendInterface().refreshLayerSymbology(layer_ndvi)
Ejemplo n.º 26
0
    def calc_a1(self, dir_output, dir_A, dir_E1, temp_folder, B10):
        self.dir_output = dir_output
        self.path = os.path.join(str(Path(dir_output).parent), 'temp_folder',
                                 '')

        self.temp_folder = temp_folder
        self.dir_A = dir_A
        self.dir_E1 = dir_E1
        self.dir_output_temp = self.path + 'A1.tif'

        self.B10 = B10

        entries = []

        A = QgsRasterLayer(self.dir_A)
        ras = QgsRasterCalculatorEntry()
        ras.ref = 'A@1'
        ras.raster = A
        ras.bandNumber = 1
        entries.append(ras)

        E1 = QgsRasterLayer(self.dir_E1)
        ras = QgsRasterCalculatorEntry()
        ras.ref = 'E1@1'
        ras.raster = E1
        ras.bandNumber = 1
        entries.append(ras)

        if self.temp_folder == 'yes':
            calc = QgsRasterCalculator('1 + "A@1" + "E1@1" * ' + self.B10,
                                       self.dir_output_temp, 'GTiff',
                                       E1.extent(), E1.width(), E1.height(),
                                       entries)
            calc.processCalculation()
        elif self.temp_folder == 'no':
            calc = QgsRasterCalculator('1 + "A@1" + "E1@1" * ' + self.B10,
                                       self.dir_output, 'GTiff', E1.extent(),
                                       E1.width(), E1.height(), entries)
            calc.processCalculation()
            iface.addRasterLayer(str(self.dir_output))
Ejemplo n.º 27
0
    def calc_a2(self, dir_output, dir_A, dir_E2, temp_folder, B11):
        self.dir_output = dir_output
        self.path = os.path.join(str(Path(dir_output).parent), 'temp_folder',
                                 '')

        self.temp_folder = temp_folder
        self.dir_A = dir_A
        self.dir_E2 = dir_E2
        self.dir_output_temp = self.path + 'A2.tif'

        self.B11 = B11

        entries = []

        A = QgsRasterLayer(self.dir_A)
        ras = QgsRasterCalculatorEntry()
        ras.ref = 'A@1'
        ras.raster = A
        ras.bandNumber = 1
        entries.append(ras)

        E2 = QgsRasterLayer(self.dir_E2)
        ras = QgsRasterCalculatorEntry()
        ras.ref = 'E2@1'
        ras.raster = E2
        ras.bandNumber = 1
        entries.append(ras)

        if self.temp_folder == 'yes':
            calc = QgsRasterCalculator('"A@1" + "E2@1" * ' + self.B11 + ' ',
                                       self.dir_output_temp, 'GTiff',
                                       E2.extent(), E2.width(), E2.height(),
                                       entries)
            calc.processCalculation()
        elif self.temp_folder == 'no':
            calc = QgsRasterCalculator('"A@1" + "E2@1" * ' + self.B11 + ' ',
                                       self.dir_output, 'GTiff', E2.extent(),
                                       E2.width(), E2.height(), entries)
            calc.processCalculation()
            iface.addRasterLayer(str(self.dir_output))
Ejemplo n.º 28
0
 def finished(self, result):
     if result:
         QgsMessageLog.logMessage('Task "{name}" comleted'.format(name=self.description()))
         if self.elevation == True:
             iface.addRasterLayer(os.path.join(self.rasterDirectory,r'dem.tif'),"Dem")
         if self.infiltration == True:
             iface.addRasterLayer(os.path.join(self.rasterDirectory,r'infiltration.tif'),"Infiltration")
         if self.friction == True:
             iface.addRasterLayer(os.path.join(self.rasterDirectory,r'friction.tif'),"Friction")
         QMessageBox.information(
         None,
         "Build 2D model",
         "2D model successfuly generated. You can delete the hoogte,bodem-3di and fysiek-voorkomen rasters. Please carefully check the settings before using the model."
         )
     else:
         if self.exception is None:
             QgsMessageLog.logMessage(
                 'Task "{name}" not successful but without '\
                 'exception (probably the task was manually '\
                 'canceled by the user)'.format(
                     name=self.description()),
                 MESSAGE_CATEGORY, Qgis.Warning)
         else:
             QgsMessageLog.logMessage(
                 'Task "{name}" Exception: {exception}'.format(
                     name=self.description(),
                     exception=self.exception),
                 MESSAGE_CATEGORY, Qgis.Critical)
             raise self.exception
Ejemplo n.º 29
0
    def calc_pv(self, dir_output, dir_ndvi, temp_folder, val_ndvis, val_ndviv):
        self.dir_output = dir_output
        self.path = os.path.join(str(Path(dir_output).parent), 'temp_folder',
                                 '')

        self.temp_folder = temp_folder
        self.dir_ndvi = dir_ndvi
        self.dir_output_temp = self.path + 'Pv.tif'

        self.val_ndvis = val_ndvis
        self.val_ndviv = val_ndviv

        entries = []

        ndvi = QgsRasterLayer(self.dir_ndvi)
        ras = QgsRasterCalculatorEntry()
        ras.ref = 'ndvi@1'
        ras.raster = ndvi
        ras.bandNumber = 1
        entries.append(ras)

        if self.temp_folder == 'yes':
            calc = QgsRasterCalculator(
                '( ( "ndvi@1" - ' + str(self.val_ndvis) + ' ) / ( ' +
                str(self.val_ndviv) + ' - ' + str(self.val_ndvis) +
                ' ) ) * ( ( "ndvi@1" - ' + str(self.val_ndvis) + ' ) / ( ' +
                str(self.val_ndviv) + ' - ' + str(self.val_ndvis) + ' ) )',
                self.dir_output_temp, 'GTiff', ndvi.extent(), ndvi.width(),
                ndvi.height(), entries)
            calc.processCalculation()
        elif self.temp_folder == 'no':
            calc = QgsRasterCalculator(
                '( ( "ndvi@1" - ' + str(self.val_ndvis) + ' ) / ( ' +
                str(self.val_ndviv) + ' - ' + str(self.val_ndvis) +
                ' ) ) * ( ( "ndvi@1" - ' + str(self.val_ndvis) + ' ) / ( ' +
                str(self.val_ndviv) + ' - ' + str(self.val_ndvis) + ' ) )',
                self.dir_output, 'GTiff', ndvi.extent(), ndvi.width(),
                ndvi.height(), entries)
            calc.processCalculation()
            iface.addRasterLayer(str(self.dir_output))
Ejemplo n.º 30
0
    def calc_ndvi(self, dir_output, dir_bred, dir_bnir, temp_folder):
        self.dir_output = dir_output
        self.path = os.path.join(str(Path(dir_output).parent), 'temp_folder',
                                 '')

        self.temp_folder = temp_folder
        self.dir_bred = dir_bred
        self.dir_bnir = dir_bnir
        self.dir_output_temp = self.path + 'NDVI.tif'

        entries = []

        bred = QgsRasterLayer(self.dir_bred)
        ras = QgsRasterCalculatorEntry()
        ras.ref = 'bred@1'
        ras.raster = bred
        ras.bandNumber = 1
        entries.append(ras)

        bnir = QgsRasterLayer(self.dir_bnir)
        ras = QgsRasterCalculatorEntry()
        ras.ref = 'bnir@1'
        ras.raster = bnir
        ras.bandNumber = 1
        entries.append(ras)

        if self.temp_folder == 'yes':
            calc = QgsRasterCalculator('(bnir@1 - bred@1)/(bnir@1 + bred@1)',
                                       self.dir_output_temp, 'GTiff',
                                       bnir.extent(), bnir.width(),
                                       bnir.height(), entries)
            calc.processCalculation()
        elif self.temp_folder == 'no':
            calc = QgsRasterCalculator(
                '(band5@1 - band4@1)/(band5@1 + band4@1)', self.dir_output,
                'GTiff', bnir.extent(), bnir.width(), bnir.height(), entries)
            calc.processCalculation()
            iface.addRasterLayer(str(self.dir_output))
Ejemplo n.º 31
0
    def calcular(self):
        RED = QgsRasterLayer(
            self.carga_RED.filePath())  #Se guarda en la variable RED
        NIR = QgsRasterLayer(
            self.carga_NIR.filePath())  #Se guarda en la variable NIR

        # SE COMPRUEBA QUE LAS IMAGENES DE ENTRADA TENGAN LAS MISMAS DIMENSIONES
        if RED.width() == NIR.width() and RED.height() == NIR.height():
            continuar = True
        else:
            ctypes.windll.user32.MessageBoxW(
                0,
                "¡Las imágenes no tienen las mismas dimensiones!. Carguelas de nuevo",
                "Error!!", 1)
            continuar = False

        # SI LAS IMAGENES DE ENTRADA TIENEN LAS MISMAS DIMENSIONES SE EJECUTA
        if continuar == True:
            iface.addRasterLayer(str(self.carga_RED.filePath())
                                 )  # Se carga en QGIS, en el espaio de trabajo
            iface.addRasterLayer(str(self.carga_NIR.filePath())
                                 )  # Se carga en QGIS, en el espaio de trabajo
            # Definicion de los paramentros necesarios para la aplicacion de  QgsRasterCalculator
            output = self.txt_ruta.text()
            entries = []
            #BANDA RED
            ras = QgsRasterCalculatorEntry()
            ras.ref = 'ras@1'
            ras.raster = RED
            ras.bandNumber = 1
            entries.append(ras)
            #BANDA NIR
            ras = QgsRasterCalculatorEntry()
            ras.ref = 'ras@2'
            ras.raster = NIR
            ras.bandNumber = 1
            entries.append(ras)

            #DEPENDIENDO DEL ÍNDICE DE VEGETACIÓN SELECCIONADO EJECUTA UN CÁLCULO U OTRO
            if self.rb_AVI.isChecked() == True:
                calc = QgsRasterCalculator(
                    '("ras@2"*(1-"ras@1")*("ras@2"-"ras@1"))^(1/3)', output,
                    'GTiff', RED.extent(), RED.width(), RED.height(), entries)
                calc.processCalculation()
            if self.rb_NDVI.isChecked() == True:
                calc = QgsRasterCalculator(
                    '("ras@2"-"ras@1")/("ras@2"+"ras@1")', output, 'GTiff',
                    RED.extent(), RED.width(), RED.height(), entries)
                calc.processCalculation()
            if self.rb_SAVI.isChecked() == True:
                calc = QgsRasterCalculator(
                    '(("ras@2"-"ras@1")/("ras@2"+"ras@1"+0.5))*1.5', output,
                    'GTiff', RED.extent(), RED.width(), RED.height(), entries)
                calc.processCalculation()

            iface.addRasterLayer(
                output)  # Se carga en QGIS el Output, en el espaio de trabajo
Ejemplo n.º 32
0
    def calc_11_bt(self, dir_output, dir_toa_11, temp_folder, val_l_tir2_k1,
                   val_l_tir2_k2):
        self.dir_output = dir_output
        self.path = os.path.join(str(Path(dir_output).parent), 'temp_folder',
                                 '')

        self.temp_folder = temp_folder
        self.dir_toa_11 = dir_toa_11
        self.dir_output_temp = self.path + '11 - BT.tif'

        self.val_l_tir2_k1 = val_l_tir2_k1
        self.val_l_tir2_k2 = val_l_tir2_k2

        entries = []

        toa_11 = QgsRasterLayer(self.dir_toa_11)
        ras = QgsRasterCalculatorEntry()
        ras.ref = '10 - TOA@1'
        ras.raster = toa_11
        ras.bandNumber = 1
        entries.append(ras)

        if self.temp_folder == 'yes':
            calc = QgsRasterCalculator(
                str(self.val_l_tir2_k2) + ' / ln ( ( ' +
                str(self.val_l_tir2_k1) + ' / "10 - TOA@1" ) + 1) ',
                self.dir_output_temp, 'GTiff', toa_11.extent(), toa_11.width(),
                toa_11.height(), entries)
            calc.processCalculation()
        elif self.temp_folder == 'no':
            calc = QgsRasterCalculator(
                str(self.val_l_tir2_k2) + ' / ln ( ( ' +
                str(self.val_l_tir2_k1) + ' / "10 - TOA@1" ) + 1) ',
                self.dir_output, 'GTiff', toa_11.extent(), toa_11.width(),
                toa_11.height(), entries)
            calc.processCalculation()
            iface.addRasterLayer(str(self.dir_output))