本文整理汇总了Python中qgis.core.QgsRasterLayer.saveDefaultStyle方法的典型用法代码示例。如果您正苦于以下问题:Python QgsRasterLayer.saveDefaultStyle方法的具体用法?Python QgsRasterLayer.saveDefaultStyle怎么用?Python QgsRasterLayer.saveDefaultStyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.core.QgsRasterLayer
的用法示例。
在下文中一共展示了QgsRasterLayer.saveDefaultStyle方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: accept
# 需要导入模块: from qgis.core import QgsRasterLayer [as 别名]
# 或者: from qgis.core.QgsRasterLayer import saveDefaultStyle [as 别名]
def accept(self):
"""Handler for when OK is clicked.
"""
input_path = self.input_path.text()
input_title = self.line_edit_title.text()
input_source = self.line_edit_source.text()
output_path = self.output_path.text()
if not output_path.endswith('.tif'):
# noinspection PyArgumentList,PyCallByClass,PyTypeChecker
QMessageBox.warning(
self,
self.tr('InaSAFE'),
(self.tr('Output file name must be tif file')))
if not os.path.exists(input_path):
# noinspection PyArgumentList,PyCallByClass,PyTypeChecker
QMessageBox.warning(
self,
self.tr('InaSAFE'),
(self.tr('Input file does not exist')))
return
if self.nearest_mode.isChecked():
algorithm = 'nearest'
else:
algorithm = 'invdist'
QtGui.qApp.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
file_name = convert_mmi_data(
input_path,
input_title,
input_source,
output_path,
algorithm=algorithm,
algorithm_filename_flag=True)
QtGui.qApp.restoreOverrideCursor()
if self.load_result.isChecked():
file_info = QFileInfo(file_name)
base_name = file_info.baseName()
layer = QgsRasterLayer(file_name, base_name)
# noinspection PyTypeChecker
mmi_ramp(layer)
layer.saveDefaultStyle()
if not layer.isValid():
LOGGER.debug("Failed to load")
else:
# noinspection PyArgumentList
QgsMapLayerRegistry.instance().addMapLayers([layer])
iface.zoomToActiveLayer()
self.done(self.Accepted)
示例2: on_pushButton_clicked
# 需要导入模块: from qgis.core import QgsRasterLayer [as 别名]
# 或者: from qgis.core.QgsRasterLayer import saveDefaultStyle [as 别名]
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()
示例3: accept
# 需要导入模块: from qgis.core import QgsRasterLayer [as 别名]
# 或者: from qgis.core.QgsRasterLayer import saveDefaultStyle [as 别名]
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)
示例4: ShakemapConverterDialog
# 需要导入模块: from qgis.core import QgsRasterLayer [as 别名]
# 或者: from qgis.core.QgsRasterLayer import saveDefaultStyle [as 别名]
#.........这里部分代码省略.........
else:
algorithm = 'invdist'
QtGui.qApp.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
file_name = convert_mmi_data(
input_path,
input_title,
input_source,
output_path,
algorithm=algorithm,
algorithm_filename_flag=True)
# reclassify raster
file_info = QFileInfo(file_name)
base_name = file_info.baseName()
self.output_layer = QgsRasterLayer(file_name, base_name)
self.output_layer.keywords = KeywordIO.read_keywords(self.output_layer)
self.output_layer.keywords['classification'] = (
earthquake_mmi_scale['key'])
keywords = self.output_layer.keywords
if self.output_layer.isValid():
self.output_layer = reclassify(
self.output_layer, overwrite_input=True)
KeywordIO.write_keywords(self.output_layer, keywords)
else:
LOGGER.debug("Failed to load")
QtGui.qApp.restoreOverrideCursor()
if self.load_result.isChecked():
# noinspection PyTypeChecker
mmi_ramp_roman(self.output_layer)
self.output_layer.saveDefaultStyle()
if not self.output_layer.isValid():
LOGGER.debug("Failed to load")
else:
# noinspection PyArgumentList
QgsMapLayerRegistry.instance().addMapLayer(self.output_layer)
iface.zoomToActiveLayer()
if (self.keyword_wizard_checkbox.isChecked() and
self.keyword_wizard_checkbox.isEnabled()):
self.launch_keyword_wizard()
self.done(self.Accepted)
@pyqtSignature('') # prevents actions being handled twice
def on_open_input_tool_clicked(self):
"""Autoconnect slot activated when open input tool button is clicked.
"""
# noinspection PyCallByClass,PyTypeChecker
filename = QFileDialog.getOpenFileName(
self, self.tr('Input file'), 'grid.xml',
self.tr('Raw grid file (*.xml)'))
self.input_path.setText(filename)
@pyqtSignature('') # prevents actions being handled twice
def on_open_output_tool_clicked(self):
"""Autoconnect slot activated when open output tool button is clicked.
"""
# noinspection PyCallByClass,PyTypeChecker
filename = QFileDialog.getSaveFileName(
self, self.tr('Output file'), 'grid.tif',
self.tr('Raster file (*.tif)'))
self.output_path.setText(filename)
示例5: ShakemapConverterDialog
# 需要导入模块: from qgis.core import QgsRasterLayer [as 别名]
# 或者: from qgis.core.QgsRasterLayer import saveDefaultStyle [as 别名]
#.........这里部分代码省略.........
extra_keywords = {}
if self.check_box_custom_shakemap_id.isChecked():
event_id = self.line_edit_shakemap_id.text()
extra_keywords[extra_keyword_earthquake_event_id['key']] = event_id
current_index = self.combo_box_source_type.currentIndex()
source_type = self.combo_box_source_type.itemData(current_index)
if source_type:
extra_keywords[
extra_keyword_earthquake_source['key']] = source_type
file_name = convert_mmi_data(
input_path,
input_title,
input_source,
output_path,
algorithm=algorithm,
algorithm_filename_flag=True,
smoothing_method=smoothing_method,
extra_keywords=extra_keywords
)
file_info = QFileInfo(file_name)
base_name = file_info.baseName()
self.output_layer = QgsRasterLayer(file_name, base_name)
# noinspection PyUnresolvedReferences
QgsApplication.instance().restoreOverrideCursor()
if self.load_result.isChecked():
# noinspection PyTypeChecker
mmi_ramp_roman(self.output_layer)
self.output_layer.saveDefaultStyle()
if not self.output_layer.isValid():
LOGGER.debug("Failed to load")
else:
# noinspection PyArgumentList
QgsProject.instance().addMapLayer(self.output_layer)
iface.zoomToActiveLayer()
if (self.keyword_wizard_checkbox.isChecked()
and self.keyword_wizard_checkbox.isEnabled()):
self.launch_keyword_wizard()
self.done(self.Accepted)
@pyqtSlot() # prevents actions being handled twice
def on_open_input_tool_clicked(self):
"""Autoconnect slot activated when open input tool button is clicked.
"""
input_path = self.input_path.text()
if not input_path:
input_path = os.path.expanduser('~')
# noinspection PyCallByClass,PyTypeChecker
filename, __ = QFileDialog.getOpenFileName(
self, tr('Input file'), input_path, tr('Raw grid file (*.xml)'))
if filename:
self.input_path.setText(filename)
@pyqtSlot() # prevents actions being handled twice
def on_open_output_tool_clicked(self):
"""Autoconnect slot activated when open output tool button is clicked.
"""
output_path = self.output_path.text()
if not output_path: