Hello list,<br><br>I was looking for pyqgis cookbook and on wms step, I'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't work too for me.<br>It'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'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("QGISHOME") # Set to /usr (on Ubuntu 10.04)<br><br>QgsApplication.setPrefixPath(qgis_prefix, True)<br>QgsApplication.initQgis()<br><br># Cookbook sample<br>
url = '<a href="http://wms.jpl.nasa.gov/wms.cgi">http://wms.jpl.nasa.gov/wms.cgi</a>'<br>layers = ['global_mosaic']<br>styles = ['pseudo']<br>format = 'image/jpeg'<br>crs = 'EPSG:4326'<br>
rlayer = QgsRasterLayer(0, url, 'some layer name', 'wms', layers, format, crs) # Freeze here<br>QgsMapLayerRegistry.instance().addMapLayer(rlayer)<br>if not rlayer.isValid():<br> print "Layer failed to load!"<br>
<br># Test with GDAL driver<br>rLayer2 = QgsRasterLayer('/home/thomas/git/frmt_wms_onearth_global_mosaic.xml','Test') # 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 = '<a href="http://wms.jpl.nasa.gov/wms.cgi">http://wms.jpl.nasa.gov/wms.cgi</a>'<br>
layers = ['global_mosaic']<br>styles = ['pseudo']<br>format = 'image/jpeg'<br>crs = 'EPSG:4326'<br>rlayer = QgsRasterLayer(0, url, 'some layer name', 'wms', layers, format, crs) # Freeze here<br>
rlayer.isValid() # Return true<br>QgsMapLayerRegistry.instance().addMapLayer(rlayer) # Don't see anything rendering<br>#or<br>qgis.utils.iface.addRasterLayer(url, 'some layer name', 'wms', layers, styles, format, crs)<br>
<br># Test with GDAL driver<br>rLayer2 =
QgsRasterLayer('/home/thomas/git/frmt_wms_onearth_global_mosaic.xml','Test')
# 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>