I am new to the python console. How can I add a layer from the OpenLayers plugin from the python console? Thank you
Renaud, there are a couple of ways to do this:
Solution #1 is pretty straightforward. OpenLayers plugin offers a good solution to #2, which will help you understand working with other plugins as well. Here is how both are accomplished.
Trigger OpenLayers plugin menu action
Work directly with OpenLayers plugin
This latter solution probably needs a little more explaining.
Get the OpenLayers plugin instance from qgis.utils's plugin registry.
Get the 'Google Physical' layer type object from OpenLayers's layer type registry. Open [path-to-user-plugins]/openlayers/openlayers_plugin.py and starting at line #111 you will see the order the layer types are assigned to the registry. They are given IDs starting with 0 (see rest of module for how that's done).
Loads the layer into QGIS's map canvas.
There may be other solutions as well, but those are the basics that I could find.
Since QGIS 2.4 Chugiak, the OpenLayers plugin has moved in the QGIS Gui to
Still, it would be interesting to know how to adapt the second method to QGIS 2.4 and above.