Example #1
0
    def threshold_on_histogram(self, forms):
        logger.debug("QObject.sender() " + str(QtCore.QObject.sender(self)))
        logger.debug("do processing args " + str(forms))
        who = QtCore.QObject.sender(self)

        if "Seuillage" in ProcessingManager().get_processings_name():
            processings_seuillage = ProcessingManager().processing_from_name(
                "Seuillage")
            if processings_seuillage:
                processings_seuillage[0].mirror.close()
                try:
                    QgsMapLayerRegistry.instance().removeMapLayer(
                        processings_seuillage[0].output_working_layer.
                        qgis_layer.id())
                except RuntimeError:
                    pass

        self.set_working_message(True)
        my_processing = TerreImageProcessing(
            self.iface, self.qgis_education_manager.working_directory,
            who.layer, self.qgis_education_manager.mirror_map_tool,
            "Seuillage", forms)
        self.qgis_education_manager.value_tool.set_layers(
            ProcessingManager().get_working_layers())
        self.set_working_message(False)
Example #2
0
    def display_metadata(self):
        # get image size and resolution
        dataset = gdal.Open(ProcessingManager().working_layer.source_file)
        if dataset is not None:
            total_size_x = dataset.RasterXSize
            total_size_y = dataset.RasterYSize
            geotransform = dataset.GetGeoTransform()
            pixel_size_x = geotransform[1]
            pixel_size_y = geotransform[5]

        list_to_display = [(u"Satellite",
                            ProcessingManager().working_layer.type),
                           (u"Lieu", "TO BE DEFINED"),
                           (u"Lignes", str(total_size_x)),
                           (u"Colonnes", str(total_size_y)),
                           (u"Résolution", "TOBEDEFINED" + str(pixel_size_x))]
        # QTreeWidget
        self.treeWidget.clear()
        header = QtGui.QTreeWidgetItem([u"Métadonnée", "Valeur"])
        self.treeWidget.setHeaderItem(header)

        root = QtGui.QTreeWidgetItem(self.treeWidget, ["Image de travail"])
        for key, value in list_to_display:
            A = QtGui.QTreeWidgetItem(root, [key, str(value)])
        self.treeWidget.resizeColumnToContents(0)
        self.treeWidget.resizeColumnToContents(1)

        #         A = QtGui.QTreeWidgetItem(root, ["A"])
        #
        #         barA = QtGui.QTreeWidgetItem(A, ["bar", "i", "ii"])
        #         bazA = QtGui.QTreeWidgetItem(A, ["baz", "a", "b"])
        root.setExpanded(True)
Example #3
0
    def layer_deleted(self, layer_id):

        # logger.debug( str(layer_id) + " deleted")
        # print str(layer_id) + " deleted"
        layer_id = layer_id.encode('utf-8')

        if "Angle_Spectral" in str(layer_id):
            # delete rubberband
            for item in self.iface.mapCanvas().scene().items():
                if isinstance(item, QgsRubberBand):
                    item.reset(QGis.Point)
            # hide legend
            self.label_a_s.hide()
            self.label_a_s_img.hide()

        if self.qgis_education_manager:
            # logger.debug( "ProcessingManager().working_layer.get_qgis_layer().id(): " +  str(ProcessingManager().working_layer.get_qgis_layer().id()))
            if ProcessingManager().working_layer.get_qgis_layer().id(
            ) == layer_id:
                self.disconnect_interface()

        ProcessingManager().remove_process_from_layer_id(layer_id)
        ProcessingManager().remove_displays_from_layer_id(layer_id)

        try:
            self.qgis_education_manager.value_tool.set_layers(
                ProcessingManager().get_working_layers())
        except AttributeError:
            pass

        self.set_combobox_histograms()
Example #4
0
    def set_combobox_histograms(self):
        """
        Updates the list of available histograms
        """
        if self.qgis_education_manager:
            if ProcessingManager().working_layer:
                process = ["Histogrammes", "Image de travail"] + [
                    x for x in ProcessingManager().get_processings_name()
                    if x not in ["KMEANS", "Seuillage"]
                ]
                logger.debug("process {}".format(process))

                self.comboBox_histogrammes.clear()
                m2 = self.toolButton_histograms.menu()
                m2.clear()
                for i, item in enumerate(process):
                    self.comboBox_histogrammes.insertItem(i, process[i])
                    action_h = QtGui.QAction(
                        QtGui.QIcon(
                            ":/plugins/qgiseducation/img/mActionFullHistogramStretch.png"
                        ), item, self.iface.mainWindow())
                    action_h.setWhatsThis(item)
                    m2.addAction(action_h)
                    if i == 0:
                        self.toolButton_histograms.setDefaultAction(action_h)
                logger.debug("Connect combo box histogram")
Example #5
0
 def main_histogram(self):
     """
     Display the histogram of the working image
     """
     self.set_working_message(True)
     if ProcessingManager().processings:
         message = "Veuillez fermer les vues de traitement avant de lancer l'histogramme de l'image de travail"
         QtGui.QMessageBox.warning(self, "Attention", message)
     else:
         if not self.dock_histo_opened:
             self.hist = TerreImageHistogram_multiband(
                 ProcessingManager().working_layer, self.canvas)
             self.histodockwidget = Terre_Image_Dock_widget(
                 "Histogrammes", self.iface.mainWindow())
             self.histodockwidget.setObjectName("Histogrammes")
             self.histodockwidget.setWidget(self.hist)
             self.iface.addDockWidget(QtCore.Qt.LeftDockWidgetArea,
                                      self.histodockwidget)
             QtCore.QObject.connect(
                 self.hist, QtCore.SIGNAL("threshold(PyQt_PyObject)"),
                 self.histogram_threshold)
             QtCore.QObject.connect(self.histodockwidget,
                                    QtCore.SIGNAL("closed(PyQt_PyObject)"),
                                    self.histogram_closed)
             self.dock_histo_opened = True
     self.set_working_message(False)
Example #6
0
 def do_display_one_band(self, who, qgis_layer, working_directory, mirror_tool):
     logger.debug("who {}".format(who))
     # manage_QGIS.display_one_band(self.qgis_education_manager.layer, who, self.iface)
     if qgis_layer:
         my_process = TerreImageDisplay(self.iface, working_directory, ProcessingManager().working_layer, mirror_tool, who, None, qgis_layer)
     else:
         my_process = TerreImageDisplay(self.iface, working_directory, ProcessingManager().working_layer, mirror_tool, who)
     # ProcessingManager().add_processing(my_process)
     self.educationWidget.set_combobox_histograms()
Example #7
0
    def do_manage_histograms(self, text_changed):
        logger.debug("text changed histogram: {}".format(text_changed))
        if text_changed == "Image de travail":
            self.main_histogram()
        elif text_changed != "Histogrammes" and text_changed != "":
            # find the layer corresponding to the name
            process = ProcessingManager().processing_from_name(text_changed)
            if process:
                process = process[0]
                specific_band = -1

                if text_changed == "Couleurs naturelles":
                    logger.debug("text changed couleurs naturelles")
                    self.set_working_message(True)
                    if not process.histogram:
                        hist = TerreImageHistogram_multiband(
                            ProcessingManager().working_layer, self.canvas, 3,
                            process)
                        process.histogram = hist
                        self.histogram(process.output_working_layer, process,
                                       specific_band, hist)
                else:
                    logger.debug("working layer")
                    bs = ["rouge", "verte", "bleue", "pir", "nir"]
                    corres = {
                        "rouge": process.layer.red,
                        "verte": process.layer.green,
                        "bleue": process.layer.blue,
                        "pir": process.layer.pir,
                        "mir": process.layer.mir
                    }
                    logger.debug("corres: " + str(corres))

                    for item in bs:
                        if item in text_changed:
                            logger.debug("bande à afficher : " +
                                         str(corres[item]))
                            specific_band = corres[item]

                    logger.debug("specific band: " + str(specific_band))

                    if not process.histogram:
                        # display the histogram of the layer
                        hist = self.histogram(process.output_working_layer,
                                              process, specific_band)
                        process.histogram = hist
                    else:
                        hist = self.histogram(process.output_working_layer,
                                              process, specific_band,
                                              process.histogram)
        self.comboBox_histogrammes.setCurrentIndex(0)
Example #8
0
    def set_comboBox_sprectral_band_display(self):
        """
        Creates the list of available display
        """
        m3 = self.toolButton_display_bands.menu()

        if ProcessingManager().working_layer:
            bands = ProcessingManager().working_layer.bands
            corres = {
                'red': "Afficher la bande rouge",
                'green': "Afficher la bande verte",
                'blue': "Afficher la bande bleue",
                'pir': "Afficher la bande pir",
                'mir': "Afficher la bande mir"
            }

            self.comboBox_sprectral_band_display.clear()
            self.comboBox_sprectral_band_display.insertItem(
                0, "Affichage des bandes spectrales...")

            if ProcessingManager().working_layer.has_natural_colors():
                logger.debug("couleurs naturelles")
                text = "Afficher en couleurs naturelles"
                self.comboBox_sprectral_band_display.insertItem(1, text)
                action_d = QtGui.QAction(
                    QtGui.QIcon(
                        ":/plugins/qgiseducation/img/mActionInOverview.png"),
                    text, self.iface.mainWindow())
                action_d.setWhatsThis(text)
                m3.addAction(action_d)

            for i in range(
                    ProcessingManager().working_layer.get_band_number()):
                y = [x for x in bands if bands[x] == i + 1]
                if y:
                    text = corres[y[0]]
                    self.comboBox_sprectral_band_display.insertItem(
                        i + 2, text)
                    action_d = QtGui.QAction(
                        QtGui.QIcon(
                            ":/plugins/qgiseducation/img/mActionInOverview.png"
                        ), text, self.iface.mainWindow())
                    action_d.setWhatsThis(text)
                    m3.addAction(action_d)
                    if i == 0:
                        self.toolButton_display_bands.setDefaultAction(
                            action_d)
            self.comboBox_sprectral_band_display.currentIndexChanged[
                str].connect(self.do_manage_sprectral_band_display)
            self.toolButton_display_bands.triggered.connect(
                self.do_manage_actions_for_display)
Example #9
0
 def view_closed(self, name_of_the_closed_view):
     # print str(name_of_the_closed_view) + " has been closed"
     logger.debug(str(name_of_the_closed_view) + " has been closed")
     process = ProcessingManager().processing_from_name(name_of_the_closed_view)
     # print process
     if process:
         try:
             # WARNING Comment this line to make the plugin work on Windows
             if process[0].output_working_layer.qgis_layer.id() in self.canvas.layers():
                 QgsMapLayerRegistry.instance().removeMapLayer(process[0].output_working_layer.qgis_layer.id())
             ProcessingManager().remove_processing(process[0])
             ProcessingManager().remove_display(process[0])
         except KeyError:
             pass
Example #10
0
 def status(self):
     """
     Function for debug
     """
     print "############# Status #############"
     print(self.qgis_education_manager)
     print("self.qgis_education_manager.mirror_map_tool.dockableMirrors " +
           str(self.qgis_education_manager.mirror_map_tool.dockableMirrors)
           ) + "\n"
     print ProcessingManager()
     print ProcessingManager().get_processings_name()
     print "layers value tool "
     print self.qgis_education_manager.value_tool.layers_to_display
     print "##########################"
Example #11
0
    def set_current_layer(self):
        self.layer, bands = terre_image_utils.get_workinglayer_on_opening(self.iface)
        if self.layer:
            self.working_directory = os.path.join(os.path.dirname(self.layer.source_file), "working_directory")
            terre_image_utils.update_subdirectories(self.working_directory)
            if not os.path.exists(self.working_directory):
                os.makedirs(self.working_directory)
            ProcessingManager().working_layer = self.layer
            self.classif_tool.set_layers(ProcessingManager().get_qgis_working_layers(), self.layer.get_qgis_layer(), self.layer.band_invert)
            self.classif_tool.set_directory(self.working_directory)
            self.classif_tool.setupUi()
        # self.layers_for_value_tool.append(self.layer ) #.get_qgis_layer())
        logger.debug("working directory")

        return self.layer, bands
Example #12
0
 def plugin_classification(self):
     """
     Opens the classification plugin
     """
     self.qgis_education_manager.classif_tool.show()
     self.qgis_education_manager.classif_tool.update_layers(
         ProcessingManager().get_qgis_working_layers())
Example #13
0
 def status(self):
     """
     Function for debug
     """
     logger.info("############# Status #############")
     logger.info(self.qgis_education_manager)
     logger.info(
         "self.qgis_education_manager.mirror_map_tool.dockableMirrors {} \n"
         .format(
             str(self.qgis_education_manager.mirror_map_tool.dockableMirrors
                 )))
     logger.info(ProcessingManager())
     logger.info(ProcessingManager().get_processings_name())
     logger.info("layers value tool ")
     logger.info(self.qgis_education_manager.value_tool.layers_to_display)
     logger.info("##########################")
Example #14
0
    def run(self):
        self.freezeCanvas(True)
        logger.debug("self.who {}".format(self.who))
        if not self.r_layer:
            result_layer = manage_QGIS.display_one_band(self.layer, self.who, self.iface)
        else:
            result_layer = self.r_layer
        if result_layer:
            self.output_working_layer = WorkingLayer(self.layer.source_file, result_layer)
            self.mirror = self.mirrormap_tool.runDockableMirror(self.processing_name)
            logger.debug(self.mirror)
            self.mirror.mainWidget.addLayer(result_layer.id())
            self.mirror.mainWidget.onExtentsChanged()

            iface_legend = self.iface.legendInterface()
            iface_layers = QgsMapLayerRegistry.instance().mapLayers()
            logger.debug("ifacelayers {}".format(iface_layers))
            # id_layer = result_layer.id()
            # logger.debug( "id_layer" + str( id_layer ))
            # logger.debug( "result layer" + str( result_layer ))
            # QgsMapLayerRegistry.instance().mapLayers()
            # {u'QB_1_ortho20140521141641682': <qgis.core.QgsRasterLayer object at 0x6592b00>,
            # u'QB_1_ortho_bande_bleue20140521141927295': <qgis.core.QgsRasterLayer object at 0x6592950>}
            iface_legend.setLayerVisible(result_layer, False)
            self.iface.mapCanvas().refresh()
            logger.debug(iface_legend.isLayerVisible(result_layer))

            ProcessingManager().add_display(self)
            # thaw the canvas
            self.freezeCanvas(False)
Example #15
0
 def restore_processing_manager(self, filename, bands, layer_type,
                                working_dir):
     self.layer, bands = terre_image_utils.restore_working_layer(
         filename, bands, layer_type)
     ProcessingManager().working_layer = self.layer
     # self.layers_for_value_tool.append(self.layer )
     self.working_directory = working_dir
     return self.layer, bands
Example #16
0
 def display_values(self):
     if self.valuedockwidget is None:
         self.set_value_tool_dock_widget()
     logger.debug("dispkay values 123456789")
     self.valuedockwidget.show()
     self.value_tool.changeActive(QtCore.Qt.Checked)
     self.value_tool.cbxActive.setCheckState(QtCore.Qt.Checked)
     self.value_tool.set_layers(ProcessingManager().get_working_layers())
Example #17
0
    def view_closed(self, name_of_the_closed_view):

        logger.debug("Manager 2 {}".format(id(self)))
        # logger.debug("{} has been closed".format(str(name_of_the_closed_view)))
        logger.debug("{} has been closed".format(name_of_the_closed_view))
        process = ProcessingManager().processing_from_name(
            name_of_the_closed_view)
        logger.debug("{}".format(process))
        if process:
            try:
                ProcessingManager().remove_processing(process[0])
                ProcessingManager().remove_display(process[0])
            except KeyError:
                pass
            else:
                logger.debug("Trying to emit something")
                self.processings_updated.emit()
                logger.debug("ProcessingChanged signal emitted")
Example #18
0
 def kmeans(self, menu=False):
     self.set_working_message(True)
     if ProcessingManager().working_layer == None:
         logger.debug("Aucune layer selectionnée")
     else:
         if menu:
             nb_class = None
         else:
             nb_class = self.spinBox_kmeans.value()
         logger.debug("nb_class from spinbox: " + str(nb_class))
         my_processing = TerreImageProcessing(
             self.iface, self.qgis_education_manager.working_directory,
             ProcessingManager().working_layer,
             self.qgis_education_manager.mirror_map_tool, "KMEANS",
             nb_class)
         self.set_combobox_histograms()
         self.qgis_education_manager.value_tool.set_layers(
             ProcessingManager().get_working_layers())
         self.set_working_message(False)
Example #19
0
    def show_education_widget(self, bands, working_dir):
        if ProcessingManager().working_layer and bands:

            if not self.dockOpened:
                # create the widget to display information
                self.educationWidget = QGISEducationWidget(self.iface)
                QObject.connect(self.educationWidget, SIGNAL("terminated()"),
                                self.unload_interface)
                # self.educationWidget.qgis_education_manager = self.qgis_education_manager
                self.educationWidget.qgis_education_manager = TerreImageManager(
                    self.iface)
                self.educationWidget.qgis_education_manager.working_directory = working_dir
                self.educationWidget.lineEdit_working_dir.setText(working_dir)

                self.educationWidget.qgis_education_manager.classif_tool.set_layers(
                    ProcessingManager().get_qgis_working_layers(),
                    ProcessingManager().working_layer.get_qgis_layer(),
                    ProcessingManager().working_layer.band_invert)
                self.educationWidget.qgis_education_manager.classif_tool.set_directory(
                    working_dir)
                self.educationWidget.qgis_education_manager.classif_tool.setupUi(
                )

                # create the dockwidget with the correct parent and add the valuewidget
                self.qgisedudockwidget = Terre_Image_Main_Dock_widget(
                    "Terre Image", self.iface.mainWindow(), self.iface)
                self.qgisedudockwidget.setObjectName("Terre Image")
                self.qgisedudockwidget.setWidget(self.educationWidget)
                QObject.connect(self.qgisedudockwidget,
                                SIGNAL("closed(PyQt_PyObject)"),
                                self.close_dock)

                # add the dockwidget to iface
                self.iface.addDockWidget(Qt.RightDockWidgetArea,
                                         self.qgisedudockwidget)
                self.educationWidget.set_comboBox_sprectral_band_display()

            text = "Plan R <- BS_PIR \nPlan V <- BS_R \nPlan B <- BS_V"

            self.qgisedudockwidget.show()
            self.dockOpened = True
Example #20
0
    def display_metadata(self):

        sat = ProcessingManager().working_layer.type
        list_to_display = terre_image_utils.get_info_from_metadata(
            ProcessingManager().working_layer.source_file, sat)

        # QTreeWidget
        self.treeWidget.clear()
        header = QtGui.QTreeWidgetItem([u"Métadonnée", "Valeur"])
        self.treeWidget.setHeaderItem(header)

        root = QtGui.QTreeWidgetItem(self.treeWidget, ["Image de travail"])
        for key, value in list_to_display:
            A = QtGui.QTreeWidgetItem(root, [key, value])
        self.treeWidget.resizeColumnToContents(0)
        self.treeWidget.resizeColumnToContents(1)

        #         A = QtGui.QTreeWidgetItem(root, ["A"])
        #
        #         barA = QtGui.QTreeWidgetItem(A, ["bar", "i", "ii"])
        #         bazA = QtGui.QTreeWidgetItem(A, ["baz", "a", "b"])
        root.setExpanded(True)
Example #21
0
 def do_manage_sprectral_band_display(self, text_changed):
     logger.debug("Combobox histogram changed")
     do_it = True
     if text_changed and text_changed != "Affichage des bandes spectrales...":
         band_to_display = None
         corres = {
             'nat': "Afficher en couleurs naturelles",
             'red': "Afficher la bande rouge",
             'green': "Afficher la bande verte",
             'blue': "Afficher la bande bleue",
             'pir': "Afficher la bande pir",
             'mir': "Afficher la bande mir"
         }
         corres_name_view = {
             'nat': "Couleurs naturelles",
             'red': "Bande rouge",
             'green': "Bande verte",
             'blue': "Bande bleue",
             'pir': "Bande pir",
             'mir': "Bande mir"
         }
         for key in corres:
             if corres[key] == text_changed:
                 who = key
                 logger.debug("do_manage_sprectral_band_display who: " +
                              str(who))
                 if corres_name_view[who] in ProcessingManager(
                 ).get_processings_name():
                     do_it = False
                 if do_it:
                     my_processing = TerreImageDisplay(
                         self.iface,
                         self.qgis_education_manager.working_directory,
                         ProcessingManager().working_layer,
                         self.qgis_education_manager.mirror_map_tool, who)
                     self.set_combobox_histograms()
                 break
         self.comboBox_sprectral_band_display.setCurrentIndex(0)
Example #22
0
    def do_manage_histograms(self, text_changed):
        logger.debug("text changed histogram: " + text_changed)
        if text_changed == "Image de travail":
            self.main_histogram()
        elif text_changed != "Histogrammes" and text_changed != "":
            # find the layer corresponding to the name
            process = ProcessingManager().processing_from_name(text_changed)
            if process :
                process = process[0]
                specific_band = -1

                if text_changed == "Couleurs naturelles":
                    logger.debug("text changed couleurs naturelles")
                    self.set_working_message(True)
                    if not process.histogram:
                        hist = TerreImageHistogram_multiband(ProcessingManager().working_layer, self.canvas, 3, process)
                        process.histogram = hist
                        self.histogram(process.output_working_layer, process, specific_band, hist)
                else:
                    logger.debug("working layer")
                    bs = ["rouge", "verte", "bleue", "pir", "nir"]
                    corres = {"rouge":process.layer.red, "verte":process.layer.green, "bleue":process.layer.blue, "pir":process.layer.pir, "mir":process.layer.mir}
                    logger.debug("corres: " + str(corres))

                    for item in bs:
                        if item in text_changed:
                            logger.debug("bande à afficher : " + str(corres[item]))
                            specific_band = corres[item]

                    logger.debug("specific band: " + str(specific_band))

                    if not process.histogram:
                        # display the histogram of the layer
                        hist = self.histogram(process.output_working_layer, process, specific_band)
                        process.histogram = hist
                    else :
                        hist = self.histogram(process.output_working_layer, process, specific_band, process.histogram)
        self.comboBox_histogrammes.setCurrentIndex(0)
Example #23
0
    def __init__(self, iface, working_dir):

        self.iface = iface
        self.canvas = self.iface.mapCanvas()

        QtGui.QWidget.__init__(self)
        self.setupUi(self)
        self.setupUi_extra()

        self.qgis_education_manager = TerreImageManager(self.iface)

        #working dir
        self.qgis_education_manager.working_directory = working_dir
        self.lineEdit_working_dir.setText(working_dir)

        # todo remove this init
        self.qgis_education_manager.classif_tool.set_layers(
            ProcessingManager().get_qgis_working_layers(),
            ProcessingManager().working_layer.get_qgis_layer(),
            ProcessingManager().working_layer.band_invert)
        self.qgis_education_manager.classif_tool.set_directory(working_dir)
        self.qgis_education_manager.classif_tool.setupUi()

        logger.debug("Manager 1 {}".format(id(self.qgis_education_manager)))
        self.lineEdit_working_dir.setText(
            self.qgis_education_manager.working_directory)
        logger.debug("Before connecting toto titi")
        self.qgis_education_manager.processings_updated.connect(
            self.set_combobox_histograms)

        logger.debug("After connecting toto titi")

        QtCore.QObject.connect(QgsMapLayerRegistry.instance(),
                               QtCore.SIGNAL("layerWillBeRemoved(QString)"),
                               self.layer_deleted)

        self.dock_histo_opened = False
Example #24
0
    def display(self, output_filename):
        #         if "Angle Spectral" in self.processing_name:
        #             print self.rubberband
        #             print self.rubberband.getPoint(0)
        self.freezeCanvas(True)
        # result_layer = manage_QGIS.get_raster_layer( output_filename,
        # os.path.basename(os.path.splitext(self.layer.source_file)[0]) + "_" + self.processing_name )
        if self.r_layer:
            result_layer = self.r_layer
        else:
            result_layer = manage_QGIS.addRasterLayerToQGIS(
                output_filename, self.processing_name, self.iface)
            self.r_layer = result_layer
        if self.processing_name == "Seuillage":
            manage_QGIS.histogram_stretching_for_threshold(
                result_layer, self.iface.mapCanvas())
        else:
            manage_QGIS.histogram_stretching(result_layer,
                                             self.iface.mapCanvas())

        logger.debug("defining self.output_working_layer")
        self.output_working_layer = WorkingLayer(output_filename, result_layer)
        # 2 ouvrir une nouvelle vue
        self.mirror = self.mirrormap_tool.runDockableMirror(
            self.processing_name)
        logger.debug(self.mirror)
        self.mirror.mainWidget.addLayer(result_layer.id())
        self.mirror.mainWidget.onExtentsChanged()
        # 1 mettre image en queue

        iface_legend = self.iface.legendInterface()
        iface_layers = QgsMapLayerRegistry.instance().mapLayers()
        logger.debug("ifacelayers" + str(iface_layers))
        id_layer = result_layer.id()
        logger.debug("id_layer" + str(id_layer))
        logger.debug("result layer" + str(result_layer))
        # QgsMapLayerRegistry.instance().mapLayers()
        # {u'QB_1_ortho20140521141641682': <qgis.core.QgsRasterLayer object at 0x6592b00>,
        # u'QB_1_ortho_bande_bleue20140521141927295': <qgis.core.QgsRasterLayer object at 0x6592950>}
        iface_legend.setLayerVisible(result_layer, False)
        self.iface.mapCanvas().refresh()
        logger.debug(iface_legend.isLayerVisible(result_layer))

        ProcessingManager().add_processing(self)

        self.emit(SIGNAL("display_ok()"))
        logger.debug("signal emitted")
        # thaw the canvas
        self.freezeCanvas(False)
Example #25
0
def set_current_layer(iface):
    layer, bands = get_workinglayer_on_opening(iface)
    if layer:
        working_directory = os.path.join(os.path.dirname(layer.source_file), "working_directory")
        update_subdirectories(working_directory)
        if not os.path.exists(working_directory):
            os.makedirs(working_directory)
        ProcessingManager().working_layer = layer
        # self.classif_tool.set_layers(ProcessingManager().get_qgis_working_layers(), self.layer.get_qgis_layer(), self.layer.band_invert)
        # self.classif_tool.set_directory(self.working_directory)
        # self.classif_tool.setupUi()
        # layers_for_value_tool.append(layer ) #.get_qgis_layer())
        logger.debug("working directory" + working_directory)

        return layer, bands, working_directory
    return None, None, None
Example #26
0
 def main_histogram(self):
     """
     Display the histogram of the working image
     """
     self.set_working_message(True)
     if not self.dock_histo_opened:
         self.hist = TerreImageHistogram_multiband(
             ProcessingManager().working_layer, self.canvas)
         self.histodockwidget = Terre_Image_Dock_widget(
             "Histogrammes", self.iface.mainWindow())
         self.histodockwidget.setObjectName("Histogrammes")
         self.histodockwidget.setWidget(self.hist)
         self.iface.addDockWidget(QtCore.Qt.LeftDockWidgetArea,
                                  self.histodockwidget)
         QtCore.QObject.connect(self.hist,
                                QtCore.SIGNAL("threshold(PyQt_PyObject)"),
                                self.histogram_threshold)
         QtCore.QObject.connect(self.histodockwidget,
                                QtCore.SIGNAL("closed(PyQt_PyObject)"),
                                self.histogram_closed)
     self.dock_histo_opened = True
     self.set_working_message(False)
Example #27
0
    def onWriteProject(self, domproject):
        if ProcessingManager().working_layer is None:
            return

#         QgsProject.instance().writeEntry( "QGISEducation", "/working_layer", self.qgis_education_manager.layer.source_file )
#         # write band orders
#         QgsProject.instance().writeEntry( "QGISEducation", "/working_layer_bands", str(self.qgis_education_manager.layer.bands) )
#         logger.debug( str(self.qgis_education_manager.layer.bands) )
#         QgsProject.instance().writeEntry( "QGISEducation", "/working_layer_type", self.qgis_education_manager.layer.type )
#         QgsProject.instance().writeEntry( "QGISEducation", "/working_directory", self.qgis_education_manager.working_directory )
        QgsProject.instance().writeEntry("QGISEducation", "/working_layer", ProcessingManager().working_layer.source_file)
        # write band orders
        QgsProject.instance().writeEntry("QGISEducation", "/working_layer_bands", str(ProcessingManager().working_layer.bands))
        logger.debug("{}".format(ProcessingManager().working_layer.bands))
        QgsProject.instance().writeEntry("QGISEducation", "/working_layer_type", ProcessingManager().working_layer.type)
        QgsProject.instance().writeEntry("QGISEducation", "/working_directory", self.educationWidget.qgis_education_manager.working_directory)
        p = []
        for process in ProcessingManager().get_processings():
            p.append((process.processing_name, process.output_working_layer.get_source()))
        # logger.debug("process{}".format(p))

        QgsProject.instance().writeEntry("QGISEducation", "/process", str(p))
        QgsProject.instance().writeEntry("QGISEducation", "/index_group", self.constants.index_group)

        if "Angle Spectral" in ProcessingManager().get_processings_name():
            # delete rubberband
            for item in self.iface.mapCanvas().scene().items():
                # item is a rubberband
                if isinstance(item, QgsRubberBand):
                    # get point
                    if item.size() > 0:
                        point = item.getPoint(0)
                        # logger.debug(point)
                        QgsProject.instance().writeEntryDouble("QGISEducation", "/angle_spectral_point_x", point.x())
                        QgsProject.instance().writeEntryDouble("QGISEducation", "/angle_spectral_point_y", point.y())

        p = TerreImageParamaters()
        if p.is_complete():
            QgsProject.instance().writeEntryDouble("QGISEducation", "/red_x_min", p.red_min)
            QgsProject.instance().writeEntryDouble("QGISEducation", "/red_x_max", p.red_max)
            QgsProject.instance().writeEntryDouble("QGISEducation", "/green_x_min", p.green_min)
            QgsProject.instance().writeEntryDouble("QGISEducation", "/green_x_max", p.green_max)
            QgsProject.instance().writeEntryDouble("QGISEducation", "/blue_x_min", p.blue_min)
            QgsProject.instance().writeEntryDouble("QGISEducation", "/blue_x_max", p.blue_max)
Example #28
0
    def display_values(self):

        self.valuedockwidget.show()
        self.value_tool.changeActive(QtCore.Qt.Checked)
        self.value_tool.cbxActive.setCheckState(QtCore.Qt.Checked)
        self.value_tool.set_layers(ProcessingManager().get_working_layers())
Example #29
0
    def onProjectLoaded(self):
        # does not work stops the project reading.
        # should desactivate all interface and read the project again
        # self.newProject( True )

        # restore mirrors?
        wl, ok = QgsProject.instance().readEntry("QGISEducation", "/working_layer")
        if not ok or wl == "":
            pass

        if not wl == "":

            bands, ok = QgsProject.instance().readEntry("QGISEducation", "/working_layer_bands")
            logger.debug("is ok" + str(ok))
            logger.debug(bands)

            # working_layer = WorkingLayer(wl, None, bands)

            # TODO interpreter bands
            type, ok = QgsProject.instance().readEntry("QGISEducation", "/working_layer_type")

            working_dir, ok = QgsProject.instance().readEntry("QGISEducation", "/working_directory")

            layer, bands = terre_image_utils.restore_working_layer(wl, eval(bands), type)
            ProcessingManager().working_layer = layer

            self.show_education_widget(bands, working_dir)
    #         self.qgis_education_manager = TerreImageManager( self.iface )
    #         self.qgis_education_manager.restore_processing_manager(wl, eval(bands), type, working_dir)
    #         if self.qgis_education_manager:


            process, ok = QgsProject.instance().readEntry("QGISEducation", "/process")
            logger.debug(eval(process))

            index_group, ok = QgsProject.instance().readDoubleEntry("QGISEducation", "/index_group")
            self.constants.index_group = int(float(index_group))

            process = eval(process)

            for qgis_layer in self.iface.legendInterface().layers():
                # print "layer loading ", qgis_layer.name()
                if qgis_layer.name() in [ "NDVI", "NDTI", "Indice de brillance", "KMEANS" ]:
                    process = TerreImageProcessing(self.iface, working_dir, ProcessingManager().working_layer, self.educationWidget.qgis_education_manager.mirror_map_tool, qgis_layer.name(), None, qgis_layer)
                elif "Angle Spectral" in qgis_layer.name():
                    process = TerreImageProcessing(self.iface, working_dir, ProcessingManager().working_layer, self.educationWidget.qgis_education_manager.mirror_map_tool, qgis_layer.name(), qgis_layer.source(), qgis_layer)
                    # ProcessingManager().add_processing(process)
                elif "couleur_naturelles" in  qgis_layer.name():
                    try:
                        self.do_display_one_band('nat', qgis_layer, working_dir, self.educationWidget.qgis_education_manager.mirror_map_tool)
                    except AttributeError:
                        QMessageBox.warning(None , "Erreur", u'Le projet ne peut être lu. Essayez de créer un projet vierge, puis de réouvrir le projet souhaité.', QMessageBox.Ok)
                        # self.newProject(  )
                        return None
                    # ProcessingManager().add_display( process )

                else:
                    corres = { 'red':"_bande_rouge", 'green':"_bande_verte", 'blue':"_bande_bleue", 'pir':"_bande_pir", 'mir':"_bande_mir", "nat":"_couleurs_naturelles" }
                    result = [x for x in corres if qgis_layer.name().endswith(corres[x])]
                    # print result
                    if result:
                        # print "the couleur", result[0]
                        try:
                            self.do_display_one_band(result[0], qgis_layer, working_dir, self.educationWidget.qgis_education_manager.mirror_map_tool)
                        except AttributeError:
                            QMessageBox.warning(None , "Erreur", u'Le projet ne peut être lu. Essayez de créer un projet vierge, puis de réouvrir le projet souhaité.', QMessageBox.Ok)
                            # self.newProject(  )
                            return None
                    # ProcessingManager().add_display( process )

            angle_spectral_point_x, ok_x = QgsProject.instance().readDoubleEntry("QGISEducation", "/angle_spectral_point_x")
            angle_spectral_point_y, ok_y = QgsProject.instance().readDoubleEntry("QGISEducation", "/angle_spectral_point_y")
            # print "angle_spectral_point_x, angle_spectral_point_y", angle_spectral_point_x, angle_spectral_point_y
            if ok_x and ok_y:
                # print "angle_spectral_point_x, angle_spectral_point_y", angle_spectral_point_x, angle_spectral_point_y
                p = ProcessingManager().processing_from_name("Angle Spectral")
                if p:
                    rubberband = p[0].rubberband
                    rubberband.setWidth(10)
                    rubberband.setColor(QColor(Qt.yellow))
                    rubberband.addPoint(QgsPoint(float(angle_spectral_point_x), float(angle_spectral_point_y)))

            p = TerreImageParamaters()
            p.red_min = QgsProject.instance().readDoubleEntry("QGISEducation", "/red_x_min")[0]
            p.red_max = QgsProject.instance().readDoubleEntry("QGISEducation", "/red_x_max")[0]
            p.green_min = QgsProject.instance().readDoubleEntry("QGISEducation", "/green_x_min")[0]
            p.green_max = QgsProject.instance().readDoubleEntry("QGISEducation", "/green_x_max")[0]
            p.blue_min = QgsProject.instance().readDoubleEntry("QGISEducation", "/blue_x_min")[0]
            p.blue_max = QgsProject.instance().readDoubleEntry("QGISEducation", "/blue_x_max")[0]

            self.educationWidget.set_combobox_histograms()
            self.iface.mapCanvas().refresh()
            self.iface.mapCanvas().repaint()
Example #30
0
 def processing_end_display(self, my_processing):
     logger.info("processing_end_display")
     self.set_combobox_histograms()
     self.qgis_education_manager.value_tool.set_layers(
         ProcessingManager().get_working_layers())
     self.set_working_message(False)
Example #31
0
 def removing_layer(self, layer_id):
     ProcessingManager().remove_process_from_layer_id(layer_id)
Example #32
0
 def export_kmz(self):
     self.set_working_message(True)
     files_to_export = ProcessingManager().get_layers_for_kmz()
     kmz = terre_image_processing.export_kmz(
         files_to_export, self.qgis_education_manager.working_directory)
     self.set_working_message(False)