Exemplo n.º 1
0
def restore_working_layer(filename, bands, layer_type):
    raster_layer = manage_QGIS.get_raster_layer(
        filename,
        os.path.splitext(os.path.basename(filename))[0])
    layer = WorkingLayer(filename, raster_layer)
    layer.set_type(layer_type)
    layer.set_bands(bands)
    return layer, bands
Exemplo n.º 2
0
def restore_working_layer(filename, bands, layer_type):
    raster_layer = manage_QGIS.get_raster_layer(filename, os.path.splitext(os.path.basename(filename))[0])
    layer = WorkingLayer(filename, raster_layer)
    layer.set_type(layer_type)
    layer.set_bands(bands)
    return layer, bands
Exemplo 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])
            type_image = terre_image_processing.get_sensor_id(file_opened)
            logger.debug("type_image {}".format(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 = 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)

                        logger.debug("{} {} {} {} {}".format(red, green, blue, pir, 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)
                        terre_image_gdal_system.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
Exemplo n.º 4
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])
            type_image = terre_image_processing.get_sensor_id(file_opened)
            logger.debug("type_image {}".format(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 = 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)

                        logger.debug("{} {} {} {} {}".format(
                            red, green, blue, pir, 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)
                        terre_image_gdal_system.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