I'm new to writing plugins in python for QGIS. I've been searching on internet for a while and wrote the code below. Even though it fills my combobox, all layers (rasters, vectors of all geometry types) get added. What am I doing wrong here?
#Populate the combo box with vector layers
layers = QgsMapLayerRegistry.instance().mapLayers().values()
for layer in layers:
if layer.type() == QgsMapLayer.VectorLayer and layer.geometryType() == QGis.Point:
self.dlg.mMapLayerComboBox.addItem(layer.name(), layer)
Answer
This should help:
if layer.type() == QgsMapLayer.VectorLayer and (layer.wkbType()==QGis.WKBPoint or layer.wkbType() == QGis.WKBMultiPoint):
But it is not the best approach. Just use QgsMapLayerComboBox https://qgis.org/api/classQgsMapLayerComboBox.html
use:
comboBox.setFilters(QgsMapLayerProxyModel.PointLayer)
On your combobox object.
No comments:
Post a Comment