本文整理匯總了Python中qgis.gui.QgsMapLayerComboBox.setLayer方法的典型用法代碼示例。如果您正苦於以下問題:Python QgsMapLayerComboBox.setLayer方法的具體用法?Python QgsMapLayerComboBox.setLayer怎麽用?Python QgsMapLayerComboBox.setLayer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qgis.gui.QgsMapLayerComboBox
的用法示例。
在下文中一共展示了QgsMapLayerComboBox.setLayer方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: FieldMappingDialog
# 需要導入模塊: from qgis.gui import QgsMapLayerComboBox [as 別名]
# 或者: from qgis.gui.QgsMapLayerComboBox import setLayer [as 別名]
class FieldMappingDialog(QDialog, FORM_CLASS):
"""Dialog implementation class for the InaSAFE field mapping tool."""
def __init__(self, parent=None, iface=None, setting=None):
"""Constructor."""
QDialog.__init__(self, parent)
self.setupUi(self)
self.setWindowTitle(self.tr('InaSAFE Field Mapping Tool'))
icon = resources_path('img', 'icons', 'show-mapping-tool.svg')
self.setWindowIcon(QIcon(icon))
self.parent = parent
self.iface = iface
if setting is None:
setting = QSettings()
self.setting = setting
self.keyword_io = KeywordIO()
self.layer = None
self.metadata = {}
self.layer_input_layout = QHBoxLayout()
self.layer_label = QLabel(tr('Layer'))
self.layer_combo_box = QgsMapLayerComboBox()
# Filter only for Polygon and Point
self.layer_combo_box.setFilters(
QgsMapLayerProxyModel.PolygonLayer
| QgsMapLayerProxyModel.PointLayer)
# Filter out a layer that don't have layer groups
excepted_layers = []
for i in range(self.layer_combo_box.count()):
layer = self.layer_combo_box.layer(i)
try:
keywords = self.keyword_io.read_keywords(layer)
except (KeywordNotFoundError, NoKeywordsFoundError):
excepted_layers.append(layer)
continue
layer_purpose = keywords.get('layer_purpose')
if not layer_purpose:
excepted_layers.append(layer)
continue
if layer_purpose == layer_purpose_exposure['key']:
layer_subcategory = keywords.get('exposure')
elif layer_purpose == layer_purpose_hazard['key']:
layer_subcategory = keywords.get('hazard')
else:
layer_subcategory = None
field_groups = get_field_groups(layer_purpose, layer_subcategory)
if len(field_groups) == 0:
excepted_layers.append(layer)
continue
self.layer_combo_box.setExceptedLayerList(excepted_layers)
# Select the active layer.
if self.iface.activeLayer():
found = self.layer_combo_box.findText(
self.iface.activeLayer().name())
if found > -1:
self.layer_combo_box.setLayer(self.iface.activeLayer())
self.field_mapping_widget = None
self.main_stacked_widget.setCurrentIndex(1)
# Input
self.layer_input_layout.addWidget(self.layer_label)
self.layer_input_layout.addWidget(self.layer_combo_box)
self.header_label = QLabel()
self.header_label.setWordWrap(True)
self.main_layout.addWidget(self.header_label)
self.main_layout.addLayout(self.layer_input_layout)
# Signal
self.layer_combo_box.layerChanged.connect(self.set_layer)
if self.layer_combo_box.currentLayer():
self.set_layer(self.layer_combo_box.currentLayer())
# Set up things for context help
self.help_button = self.button_box.button(QDialogButtonBox.Help)
# Allow toggling the help button
self.help_button.setCheckable(True)
self.help_button.toggled.connect(self.help_toggled)
# Set up things for ok button
self.ok_button = self.button_box.button(QDialogButtonBox.Ok)
self.ok_button.clicked.connect(self.accept)
# Set up things for cancel button
self.cancel_button = self.button_box.button(QDialogButtonBox.Cancel)
self.cancel_button.clicked.connect(self.reject)
def set_layer(self, layer=None, keywords=None):
"""Set layer and update UI accordingly.
:param layer: A QgsVectorLayer.
:type layer: QgsVectorLayer
#.........這裏部分代碼省略.........
示例2: Viewer
# 需要導入模塊: from qgis.gui import QgsMapLayerComboBox [as 別名]
# 或者: from qgis.gui.QgsMapLayerComboBox import setLayer [as 別名]
#.........這裏部分代碼省略.........
@property
def current_action_color(self):
action = self.actiongroup.checkedAction()
color = int("0x00ff00", 16)
if action == self.measureaction:
if self.mode == "Vertical":
color = int("0x0000ff", 16)
return color
def action_triggered(self, *args):
action = self.actiongroup.checkedAction()
layer = self.activelayercombo.currentLayer()
self.clear_line()
if not action:
return
if not action == self.measureaction and (not layer or not layer.type() == QgsMapLayer.VectorLayer):
return
color = self.current_action_color
actiondata = {}
if action == self.measureaction:
self.measuredialog.show()
actiondata['mode'] = self.mode
geomtype = None
layerid = None
else:
self.measuredialog.hide()
geomtype = QGis.vectorGeometryType(layer.geometryType())
layerid = layer.id()
data = dict(action=action.objectName(),
layer=layerid,
geom=geomtype,
actiondata=actiondata,
color=color)
self.earthmine.updateAction(data)
def active_tool(self):
action = self.actiongroup.checkedAction()
if not action:
return None
return action.objectName()
def update_current_layer(self, layer):
self.activelayercombo.setLayer(layer)
def addcallbackobject(self):
self.frame.addToJavaScriptWindowObject("qgis", self.callbackobject)
def loadviewer(self, url):
self.webview.load(url)
self.frame.addToJavaScriptWindowObject("qgis", self.callbackobject)
def startViewer(self, settings):
self.earthmine.startViewer(settings)
def set_location(self, point):
# # NOTE Set location takes WGS84 make sure you have transformed it first before sending
self.earthmine.setLocation(point.x(), point.y())
def clear_features(self):
self.earthmine.clearFeatures()
def clear_layer_features(self, layerid):
self.earthmine.clearLayerObjects(layerid)
def remove_feature(self, layerid, featureid):
"""
:param features: A dict of layerid, id, lat, lng
:return:
"""
self.earthmine.removeFeature(layerid, featureid)
def load_features(self, layerdata, features):
"""
:param features: A dict of layerid, id, lat, lng
:return:
"""
self.earthmine.loadFeatures(layerdata, features)
def layer_loaded(self, layerid):
return self.earthmine.layerLoaded(layerid)
def clear_selection(self, layerid):
self.earthmine.clearSelection(layerid)
def set_selection(self, layerid, featureids, clearlast=True):
self.earthmine.setSelection(layerid, featureids, clearlast)
def edit_feature(self, layerid, featureid, nodes):
self.earthmine.editFeature(layerid, featureid, nodes)
def delete_selected(self):
layer = self.active_layer
layer.deleteSelectedFeatures()
示例3: Dialog
# 需要導入模塊: from qgis.gui import QgsMapLayerComboBox [as 別名]
# 或者: from qgis.gui.QgsMapLayerComboBox import setLayer [as 別名]
#.........這裏部分代碼省略.........
self.__layout.addWidget(self.fnLink, 3, 1)
self.__layout.addWidget(
QtGui.QLabel(self.tr(u"Point 'TO' id field") + ":"), 4, 0)
self.fnIdTo = QgsFieldComboBox()
self.fnIdTo.setFilters(QgsFieldProxyModel.Int | QgsFieldProxyModel.LongLong)
self.fnIdTo.setEditable(True)
# self.fnIdTo.setEditText(curFNIdTo)
self.fnIdTo.fieldChanged.connect(self.filedChooze)
self.__layout.addWidget(self.fnIdTo, 4, 1)
self.__layout.addWidget(
QtGui.QLabel(self.tr(u"Save result in layer") + ":"),
5, 0
)
self.linesLayer = QgsMapLayerComboBox()
self.linesLayer.setSizePolicy(
QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Fixed
)
self.linesLayer.setFilters(QgsMapLayerProxyModel.LineLayer)
self.linesLayer.setEditable(True)
self.linesLayer.layerChanged.connect(self.choozeResultLayer)
self.__layout.addWidget(self.linesLayer, 5, 1)
# self.__layout4resultFileChoose = QtGui.QHBoxLayout()
# self.leResultFilename = QtGui.QLineEdit(curResultFilename)
# self.__layout4resultFileChoose.addWidget(self.leResultFilename)
# self.pbChooseResultFilename = QtGui.QPushButton(u"Выбрать")
# self.pbChooseResultFilename.released.connect(self.chooseResultFilename)
# self.__layout4resultFileChoose.addWidget(self.pbChooseResultFilename)
# self.__layout.addLayout(self.__layout4resultFileChoose, 6, 0, 2, 0)
self.pointsLayerFrom.layerChanged.connect(self.fnIdFrom.setLayer)
self.pointsLayerFrom.layerChanged.connect(self.fnLink.setLayer)
self.pointsLayerTo.layerChanged.connect(self.fnIdTo.setLayer)
self.__mainLayout.addLayout(self.__layout)
self.__bbox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok)
self.__bbox.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)
self.__bbox.accepted.connect(self.accept)
self.__mainLayout.addWidget(self.__bbox)
self.fillControls(
curPointsLayerFrom,
curPointsLayerTo,
curFNIdFrom,
curFNLink,
curFNIdTo,
curResultLayerName
)
def fillControls(
self,
curPointsLayerFrom,
curPointsLayerTo,
curFNIdFrom,
curFNLink,
curFNIdTo,
curResultLayerName
):
QgisPlugin().plPrint("curPointsLayerFrom: " + curPointsLayerFrom)
QgisPlugin().plPrint("curPointsLayerTo: " + curPointsLayerTo)
QgisPlugin().plPrint("curFNIdFrom: " + curPointsLayerFrom)