Hello list,<br><br>I was looking for pyqgis cookbook and on wms step, I&#39;m stuck in my test.<br>I search in archives and see <a href="http://osgeo-org.1803224.n2.nabble.com/Re-RE-Qgis-user-WMS-in-python-td2039236.html">http://osgeo-org.1803224.n2.nabble.com/Re-RE-Qgis-user-WMS-in-python-td2039236.html</a> and <a href="http://osgeo-org.1803224.n2.nabble.com/Re-WMS-in-python-td2048465.html">http://osgeo-org.1803224.n2.nabble.com/Re-WMS-in-python-td2048465.html</a><br>

but the first link is the cookbook recipe and the FRMT sample won&#39;t work too for me.<br>It&#39;s related to my install? only my code ? Someone get clues to solve this, please?<br>You will find below my tests both in command line and qgis python console.<br>

I&#39;m working on Ubuntu 10.04 and my Qgis (1.6) is from on <a href="https://launchpad.net/%7Eubuntugis/+archive/ubuntugis-unstable">https://launchpad.net/~ubuntugis/+archive/ubuntugis-unstable</a><br><br>Regards<br><br>

ThomasG<br>GIS specialist<br><br># IN COMMAND LINE<br><br>from PyQt4.QtCore import *<br>from PyQt4.QtGui import *<br>from qgis.core import *<br>from qgis.gui import *<br>import os<br># Import our GUI<br># Environment variable QGISHOME must be set to the install directory<br>

# before running the application<br>qgis_prefix = os.getenv(&quot;QGISHOME&quot;) # Set to /usr (on Ubuntu 10.04)<br><br>QgsApplication.setPrefixPath(qgis_prefix, True)<br>QgsApplication.initQgis()<br><br># Cookbook sample<br>

url = &#39;<a href="http://wms.jpl.nasa.gov/wms.cgi">http://wms.jpl.nasa.gov/wms.cgi</a>&#39;<br>layers = [&#39;global_mosaic&#39;]<br>styles = [&#39;pseudo&#39;]<br>format = &#39;image/jpeg&#39;<br>crs = &#39;EPSG:4326&#39;<br>

rlayer = QgsRasterLayer(0, url, &#39;some layer name&#39;, &#39;wms&#39;, layers, format, crs) # Freeze here<br>QgsMapLayerRegistry.instance().addMapLayer(rlayer)<br>if not rlayer.isValid():<br>  print &quot;Layer failed to load!&quot;<br>

<br># Test with GDAL driver<br>rLayer2 = QgsRasterLayer(&#39;/home/thomas/git/frmt_wms_onearth_global_mosaic.xml&#39;,&#39;Test&#39;) # using file from <a href="http://www.gdal.org/frmt_wms_onearth_global_mosaic.xml">http://www.gdal.org/frmt_wms_onearth_global_mosaic.xml</a><br>

QgsMapLayerRegistry.instance().addMapLayer(rlayer2)<br><br>QgsApplication.exitQgis()<br><br># QGIS PYTHON CONSOLE<br><br># Cookbook sample<br>url = &#39;<a href="http://wms.jpl.nasa.gov/wms.cgi">http://wms.jpl.nasa.gov/wms.cgi</a>&#39;<br>

layers = [&#39;global_mosaic&#39;]<br>styles = [&#39;pseudo&#39;]<br>format = &#39;image/jpeg&#39;<br>crs = &#39;EPSG:4326&#39;<br>rlayer = QgsRasterLayer(0, url, &#39;some layer name&#39;, &#39;wms&#39;, layers, format, crs) # Freeze here<br>

rlayer.isValid() # Return true<br>QgsMapLayerRegistry.instance().addMapLayer(rlayer) # Don&#39;t see anything rendering<br>#or<br>qgis.utils.iface.addRasterLayer(url, &#39;some layer name&#39;, &#39;wms&#39;, layers, styles, format, crs)<br>

<br># Test with GDAL driver<br>rLayer2 = 
QgsRasterLayer(&#39;/home/thomas/git/frmt_wms_onearth_global_mosaic.xml&#39;,&#39;Test&#39;)
 # using file from 
<a href="http://www.gdal.org/frmt_wms_onearth_global_mosaic.xml">http://www.gdal.org/frmt_wms_onearth_global_mosaic.xml</a> # Failed with layer is not defined<br>
QgsMapLayerRegistry.instance().addMapLayer(rlayer2)<br><br><br>