Can I edit this code below to show only point layers?
This is being used in a Plugin for QGIS 2.
I am creating if that makes any difference.
self.addParameter(ParameterVector(self.INPUT, self.tr('Input layer'), [ParameterVector.VECTOR_TYPE_ANY]))
Answer for QGIS 2.18
You can according to the QGIS code base by using ParameterVector.VECTOR_TYPE_POINT
instead of ParameterVector.VECTOR_TYPE_ANY
. You need to do import using from processing.core.parameters import ParameterVector
Info extracted from QGIS 2.18 code base file https://github.com/qgis/QGIS/blob/ltr-2_18/python/plugins/processing/script/ScriptAlgorithm.py#L203
For QGIS 3.x, it should be
# At the top of your file
from qgis.core import QgsProcessing
self.addParameter(
QgsProcessingParameterFeatureSource(
self.INPUT,
self.tr('Input layer'),
[QgsProcessing.TypeVectorPoint]
)
)
The enum for other types of geometry for QGIS 3 can be seen in https://qgis.org/api/classQgsProcessing.html#acad4d2322342455b53eee5701e2b3115
QgsMapLayerComboBox
. If you want to filter, you have to set filters like at webgeodatavore.github.io/pyqgis-samples/gui-group/… You will need to replace in the sample, the line map_layer_combo_box.setFilters(QgsMapLayerProxyModel.VectorLayer)
with map_layer_combo_box.setFilters(QgsMapLayerProxyModel.PointLayer)
. The sample code you mentioned is for processing algorithms
Commented
May 2, 2020 at 22:06