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)
def working_layer(canvas): source = canvas.currentLayer().source() layer = WorkingLayer(source, canvas.currentLayer()) # 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().get_values() bands = {'red': red, 'green': green, 'blue': blue, 'pir': pir, 'mir': mir} layer.set_bands(bands) logger.debug(str(red) + " " + str(green) + " " + str(blue) + " " + str(pir) + " " + str(mir)) return layer
def working_layer(canvas): source = canvas.currentLayer().source() layer = WorkingLayer(source, canvas.currentLayer()) # 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().get_values() bands = {'red': red, 'green': green, 'blue': blue, 'pir': pir, 'mir': mir} layer.set_bands(bands) logger.debug("{} {} {} {} {}".format(red, green, blue, pir, mir)) return layer
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
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)
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
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
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