Ejemplo n.º 1
0
 def run(self):
     logger.debug("run, processing name" + str(self.processing_name))
     logger.debug("self.arg" + str(self.arg))
     output_filename = ""
     if "NDVI" in self.processing_name:
         output_filename = terre_image_processing.ndvi(self.layer, self.working_directory, self.iface)
     if "NDTI" in self.processing_name:
         output_filename = terre_image_processing.ndti(self.layer, self.working_directory, self.iface)
     if "Indice de brillance" in self.processing_name:
         output_filename = terre_image_processing.brightness(self.layer, self.working_directory, self.iface)
     if "Angle Spectral" in self.processing_name:
         self.rubberband = QgsRubberBand(self.canvas, QGis.Point)
         self.rubberband.setWidth(10)
         self.rubberband.setColor(QColor(Qt.yellow))
         if not self.arg:
             from spectral_angle import SpectralAngle
             self.angle_tool = SpectralAngle(self.iface, self.working_directory, self.layer, self.mirrormap_tool, self.rubberband)
             logger.debug("self.angle_tool" + str(self.angle_tool))
             QObject.connect(self.angle_tool, SIGNAL("anglesComputed(PyQt_PyObject)"), self.display)
             self.angle_tool.get_point_for_angles(self.layer)
             # spectral_angles(self.layer, self.working_directory, self.iface)
         else:
             output_filename = self.arg
     if "KMEANS" in self.processing_name:
         if self.arg:
             output_filename = terre_image_processing.kmeans(self.layer, self.working_directory, self.iface, self.arg)
         else:
             output_filename = terre_image_processing.kmeans(self.layer, self.working_directory, self.iface)
     if "Seuillage" in self.processing_name and self.arg:
         logger.debug("this is thrshold")
         output_filename = terre_image_processing.threshold(self.layer, self.working_directory, self.arg)
     if output_filename:
         OTBApplications.compute_overviews(output_filename)
         logger.debug(output_filename)
         self.display(output_filename)
Ejemplo n.º 2
0
 def run(self):
     logger.debug("run, processing name" + str(self.processing_name))
     logger.debug("self.arg" + str(self.arg))
     output_filename = ""
     if "NDVI" in self.processing_name:
         output_filename = terre_image_processing.ndvi(
             self.layer, self.working_directory, self.iface)
     if "NDTI" in self.processing_name:
         output_filename = terre_image_processing.ndti(
             self.layer, self.working_directory, self.iface)
     if "Indice de brillance" in self.processing_name:
         output_filename = terre_image_processing.brightness(
             self.layer, self.working_directory, self.iface)
     if "Angle Spectral" in self.processing_name:
         self.rubberband = QgsRubberBand(self.canvas, QGis.Point)
         self.rubberband.setWidth(10)
         self.rubberband.setColor(QColor(Qt.yellow))
         if not self.arg:
             from spectral_angle import SpectralAngle
             self.angle_tool = SpectralAngle(self.iface,
                                             self.working_directory,
                                             self.layer,
                                             self.mirrormap_tool,
                                             self.rubberband)
             logger.debug("self.angle_tool" + str(self.angle_tool))
             QObject.connect(self.angle_tool,
                             SIGNAL("anglesComputed(PyQt_PyObject)"),
                             self.display)
             self.angle_tool.get_point_for_angles(self.layer)
             # spectral_angles(self.layer, self.working_directory, self.iface)
         else:
             output_filename = self.arg
     if "KMEANS" in self.processing_name:
         if self.arg:
             output_filename = terre_image_processing.kmeans(
                 self.layer, self.working_directory, self.iface, self.arg)
         else:
             output_filename = terre_image_processing.kmeans(
                 self.layer, self.working_directory, self.iface)
     if "Seuillage" in self.processing_name and self.arg:
         logger.debug("this is thrshold")
         output_filename = terre_image_processing.threshold(
             self.layer, self.working_directory, self.arg)
     if output_filename:
         OTBApplications.compute_overviews(output_filename)
         logger.debug(output_filename)
         self.display(output_filename)
Ejemplo n.º 3
0
def get_workinglayer_on_opening(iface):
    settings = QSettings()
    last_folder = settings.value("terre_image_last_folder")

    if last_folder:
        path = last_folder
    else:
        path = QDir.currentPath()

    file_opened = QFileDialog.getOpenFileName(None, "Selectionner un fichier raster", path)

    settings.setValue("terre_image_last_folder", os.path.dirname(file_opened))
    settings.sync()

    if file_opened:
        #         try:
        #             str(file_opened)
        #         except UnicodeEncodeError:
        #             QMessageBox.warning( None , "Erreur", u'L\'image que vous essayez d\'ouvrir contient un ou des caractères spéciaux. \
        # La version actuelle du plugin ne gère pas ce type de fichiers. \
        # Veuillez renommer le fichier et ou les répertoires le contenant.', QMessageBox.Ok )
        #             return None, None
        #         else:
        #             if file_opened.find(" ") != -1:
        #                 QMessageBox.warning( None , "Attention", u'L\'image que vous essayez d\'ouvrir contient un ou plusieurs espaces. Les traitements sur cette image provoqueront une erreur.'.encode('utf8'), QMessageBox.Ok )

        if file_opened.endswith(".qgs"):
            # open new qgis project
            pass
        else:
            raster_layer = manage_QGIS.get_raster_layer(file_opened, os.path.splitext(os.path.basename(file_opened))[0])
            if not os.name == "posix":
                terre_image_run_process.set_OTB_PATH()
            type_image = terre_image_processing.get_sensor_id(file_opened)
            logger.debug("type_image " + str(type_image))
            layer = WorkingLayer(file_opened, raster_layer)
            layer.set_type(type_image)
            # self.layer = self.canvas.currentLayer()
            if layer:
                # self.define_bands(self.layer)
                # manage_bands()
                # self.red, self.green, self.blue, self.pir, self.mir = manage_bands().get_values()
                red, green, blue, pir, mir, type_satellite = manage_bands(type_image, layer.get_band_number()).get_values()

                if red != -1 or green != -1 or blue != -1 or pir != -1 or mir != -1:
                    all_set = True
                    bands = {'red': red, 'green': green, 'blue': blue, 'pir': pir, 'mir': mir}
                    for i in range(1, layer.get_band_number() + 1):
                        if i not in bands.values():
                            all_set = False
                    if all_set:
                        layer.set_bands(bands)
                        if layer.type is None:
                            layer.set_type(type_satellite)

                        logger.debug(str(red) + " " + str(green) + " " + str(blue) + " " + str(pir) + " " + str(mir))

                        cst = TerreImageConstant()
                        cst.index_group = cst.iface.legendInterface().addGroup("Terre Image", True, None)

                        manage_QGIS.add_qgis_raser_layer(raster_layer, iface.mapCanvas(), bands)
                        OTBApplications.compute_overviews(file_opened)
                        return layer, bands
                    else:
                        QMessageBox.warning(None, "Erreur",
                                            u'Il y a un problème dans la définition des bandes spectrales.',
                                            QMessageBox.Ok)
                        return None, None
                else:
                    return None, None
    else:
        return None, None