[Qgis-developer] WMS Python again...

Thomas Gratier osgeo.mailinglist at gmail.com
Mon Jun 13 05:38:51 EDT 2011


Hello list,

I was looking for pyqgis cookbook and on wms step, I'm stuck in my test.
I search in archives and see
http://osgeo-org.1803224.n2.nabble.com/Re-RE-Qgis-user-WMS-in-python-td2039236.htmland
http://osgeo-org.1803224.n2.nabble.com/Re-WMS-in-python-td2048465.html
but the first link is the cookbook recipe and the FRMT sample won't work too
for me.
It's related to my install? only my code ? Someone get clues to solve this,
please?
You will find below my tests both in command line and qgis python console.
I'm working on Ubuntu 10.04 and my Qgis (1.6) is from on
https://launchpad.net/~ubuntugis/+archive/ubuntugis-unstable<https://launchpad.net/%7Eubuntugis/+archive/ubuntugis-unstable>

Regards

ThomasG
GIS specialist

# IN COMMAND LINE

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
import os
# Import our GUI
# Environment variable QGISHOME must be set to the install directory
# before running the application
qgis_prefix = os.getenv("QGISHOME") # Set to /usr (on Ubuntu 10.04)

QgsApplication.setPrefixPath(qgis_prefix, True)
QgsApplication.initQgis()

# Cookbook sample
url = 'http://wms.jpl.nasa.gov/wms.cgi'
layers = ['global_mosaic']
styles = ['pseudo']
format = 'image/jpeg'
crs = 'EPSG:4326'
rlayer = QgsRasterLayer(0, url, 'some layer name', 'wms', layers, format,
crs) # Freeze here
QgsMapLayerRegistry.instance().addMapLayer(rlayer)
if not rlayer.isValid():
  print "Layer failed to load!"

# Test with GDAL driver
rLayer2 =
QgsRasterLayer('/home/thomas/git/frmt_wms_onearth_global_mosaic.xml','Test')
# using file from http://www.gdal.org/frmt_wms_onearth_global_mosaic.xml
QgsMapLayerRegistry.instance().addMapLayer(rlayer2)

QgsApplication.exitQgis()

# QGIS PYTHON CONSOLE

# Cookbook sample
url = 'http://wms.jpl.nasa.gov/wms.cgi'
layers = ['global_mosaic']
styles = ['pseudo']
format = 'image/jpeg'
crs = 'EPSG:4326'
rlayer = QgsRasterLayer(0, url, 'some layer name', 'wms', layers, format,
crs) # Freeze here
rlayer.isValid() # Return true
QgsMapLayerRegistry.instance().addMapLayer(rlayer) # Don't see anything
rendering
#or
qgis.utils.iface.addRasterLayer(url, 'some layer name', 'wms', layers,
styles, format, crs)

# Test with GDAL driver
rLayer2 =
QgsRasterLayer('/home/thomas/git/frmt_wms_onearth_global_mosaic.xml','Test')
# using file from http://www.gdal.org/frmt_wms_onearth_global_mosaic.xml #
Failed with layer is not defined
QgsMapLayerRegistry.instance().addMapLayer(rlayer2)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20110613/6c6ecc49/attachment.html


More information about the Qgis-developer mailing list