Title: Select and use raster layer from python
Tags: pyqgis;qgis-plugins;pyqt4
Question: 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



Here is the accepted answer: 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
    self.dockwidget.red_comboBox.clear()
    self.dockwidget.green_comboBox.clear()
    self.dockwidget.blue_comboBox.clear()
    # Add band numbers to associated combo boxes
    self.dockwidget.red_comboBox.addItem(str(selected_rlayer.renderer().redBand()))
    self.dockwidget.green_comboBox.addItem(str(selected_rlayer.renderer().greenBand()))
    self.dockwidget.blue_comboBox.addItem(str(selected_rlayer.renderer().blueBand()))

# Set first filter for QgsMapLayerComboBox to only populate with raster layers
self.dockwidget.mMapLayerComboBox.setFilters(QgsMapLayerProxyModel.RasterLayer)
# 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
        rlayer_list.append(layer)
# Set second filter to only populate with multiband rasters
self.dockwidget.mMapLayerComboBox.setExceptedLayerList(rlayer_list)

# Run function on startup
raster_bands(self)
# When raster selection is changed, update combo boxes
self.dockwidget.mMapLayerComboBox.currentIndexChanged.connect(raster_bands)
```



Result:



Comment for this answer: Thanks Joseph! you're so kind!
Tomorrow morning i try , but i think are all in necessary for me ;)
Comment for this answer: @AntonioFeliziani - Most welcome, hope it will be helpful. Edited the post slightly to remove a couple of unnecessary lines :)
Comment for this answer: 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?
Comment for this answer: sorry i dotn have make the tag "mention" @Joseph
Comment for this answer: @AntonioFeliziani - Apologies for the late reply, holidays ;). Perhaps your issue might be related to [this](http://gis.stackexchange.com/questions/199169/how-can-i-trigger-a-qgis-plugin-event-from-map-refresh/199265#199265) where you need to change a line in the header file of your plugin?


{'source': 'StackExchangeDataset', 'subset': 'gis.stackexchange.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:12/19/16', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<pyqgis><qgis-plugins><pyqt4>', 'Title': 'Select and use raster layer from python', 'ViewCount': 1109, 'id': 221989, 'user_AboutMe': None, 'user_AccountId': 1602129.0, 'user_DisplayName': 'Antonio Feliziani', 'user_Reputation': 73.0, 'user_Views': 19.0, 'user_id': 88453.0}}