I'm a developer but this is the first experience with python and QGIS Plugin, I want make a plug-in for Remote Sensing Index. I have followed this basic tutorial https://www.youtube.com/watch?v=ZI3yzAVCK_0 and in this moment I have one dropdown with layer selection.

I correctly loaded the layer but I want see only the raster layer with multiple band for raster calculation, is it possible to filter it?

After at item selection from the dropdown list, load the band in other dropdown list for right association (green, blue, red, RedEdge ,Near IR).

Is it possible to make? What is the class prop to read?

This is almost the UI



Hopefully the following will help get you started, I've added comments to try and explain how it works.

Essentially, you can use a QgsMapLayerComboBox to filter out all layers loaded in QGIS and only have it list the multiband rasters. You can then define a function which will read the selected layer and populate the combo boxes for the bands (note that I only added the standard red, green and blue bands):

def raster_bands(self):
    # Read current item in raster layer combobox
    rlayer = self.dockwidget.mMapLayerComboBox.currentText()
    # Match name of current item with layer in table of contents
    selected_rlayer = QgsMapLayerRegistry.instance().mapLayersByName(rlayer)[0]
    # Clear band combo boxes
    # Add band numbers to associated combo boxes

# Set first filter for QgsMapLayerComboBox to only populate with raster layers
# Create an empty list
rlayer_list = []
# Loop through all loaded layers in table of contents
for layer in QgsMapLayerRegistry.instance().mapLayers().values():
    # If layer is a raster and it is not a multiband type
    if layer.type() == 1 and layer.renderer().type() != "multibandcolor":
        # Add to list
# Set second filter to only populate with multiband rasters

# Run function on startup
# When raster selection is changed, update combo boxes


Raster bands

| improve this answer | |
  • 1
    Thanks Joseph! you're so kind! Tomorrow morning i try , but i think are all in necessary for me ;) – Antonio Feliziani Dec 20 '16 at 22:03
  • @AntonioFeliziani - Most welcome, hope it will be helpful. Edited the post slightly to remove a couple of unnecessary lines :) – Joseph Dec 21 '16 at 9:52
  • Thanks Joseph Sorry i try tu use QgsMapLayerRegistry but not work, i have serch in the net, and i have undestand not worl with PyQt4 core... I try to add "from qgis.core import QgsMapLayerRegistry" but i use PyCharm with QtCreator for the UI and i think is not possible call this class. Are other method? – Antonio Feliziani Dec 24 '16 at 0:08
  • sorry i dotn have make the tag "mention" @Joseph – Antonio Feliziani Dec 27 '16 at 9:24
  • @AntonioFeliziani - Apologies for the late reply, holidays ;). Perhaps your issue might be related to this where you need to change a line in the header file of your plugin? – Joseph Jan 4 '17 at 10:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.