def on_pushButton_clicked(self): """Wow - an autoconnected slot!""" print 'Click!' myPath = os.path.join( os.path.dirname(__file__), 'landsat.tif') print myPath layer = QgsRasterLayer(myPath, 'A Layer') QgsMapLayerRegistry.instance().addMapLayers([layer]) layer.setGrayBandName(layer.bandName(1)) layer.setDrawingStyle(QgsRasterLayer.SingleBandPseudoColor) layer.setColorShadingAlgorithm(QgsRasterLayer.PseudoColorShader) layer.saveDefaultStyle() self.widget.zoomToFullExtent() print self.widget.extent().toString() print layer.extent().toString() self.widget.refresh()
def accept(self): """Handler for when OK is clicked. """ input_path = str(self.leInputPath.text()) output_path = str(self.leOutputPath.text()) if not output_path.endswith('.tif'): # noinspection PyArgumentList QMessageBox.warning( self.parent, self.tr('InaSAFE'), (self.tr('Output file name must be tif file'))) if not os.path.exists(input_path): # noinspection PyArgumentList QMessageBox.warning( self.parent, self.tr('InaSAFE'), (self.tr('Input file is not exist'))) return if self.radNearest.isChecked(): my_algorithm = 'nearest' else: my_algorithm = 'invdist' QtGui.qApp.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor)) fileName = convert_mmi_data( input_path, output_path, algorithm=my_algorithm, algorithm_filename_flag=False) QtGui.qApp.restoreOverrideCursor() if self.cBLoadLayer.isChecked(): fileInfo = QFileInfo(fileName) baseName = fileInfo.baseName() layer = QgsRasterLayer(fileName, baseName) layer.setGrayBandName(layer.bandName(1)) layer.setDrawingStyle(QgsRasterLayer.SingleBandPseudoColor) layer.setColorShadingAlgorithm(QgsRasterLayer.PseudoColorShader) layer.saveDefaultStyle() if not layer.isValid(): LOGGER.debug("Failed to load") else: # noinspection PyArgumentList QgsMapLayerRegistry.instance().addMapLayer(layer) self.done(self.Accepted)
def accept(self): """Handler for when OK is clicked. """ input_path = str(self.leInputPath.text()) output_path = str(self.leOutputPath.text()) if not output_path.endswith('.tif'): # noinspection PyArgumentList QMessageBox.warning(self.parent, self.tr('InaSAFE'), (self.tr('Output file name must be tif file'))) if not os.path.exists(input_path): # noinspection PyArgumentList QMessageBox.warning(self.parent, self.tr('InaSAFE'), (self.tr('Input file is not exist'))) return if self.radNearest.isChecked(): my_algorithm = 'nearest' else: my_algorithm = 'invdist' fileName = convert_mmi_data(input_path, output_path, the_algorithm=my_algorithm, algorithm_name=False) if self.cBLoadLayer.isChecked(): fileInfo = QFileInfo(fileName) baseName = fileInfo.baseName() layer = QgsRasterLayer(fileName, baseName) layer.setGrayBandName(layer.bandName(1)) layer.setDrawingStyle(QgsRasterLayer.SingleBandPseudoColor) layer.setColorShadingAlgorithm(QgsRasterLayer.PseudoColorShader) layer.saveDefaultStyle() if not layer.isValid(): LOGGER.debug("Failed to load") else: # noinspection PyArgumentList QgsMapLayerRegistry.instance().addMapLayer(layer) self.done(self.Accepted)