1

I am using the following snippet to load a raster layer deployed under wms service using geoserver, in qgis python console. I am getting False output. Any idea?

registry = QgsMapLayerRegistry.instance()    
urlWithParams = "service=WMS&version=1.1.0&request=GetMap&layers=sf:sfdem&styles=&bbox=589980.0,4913700.0,609000.0,4928010.0&width=512&height=385&srs=EPSG:26713&format=image/png&url=http://maps.itu.edu.tr:8082/geoserver/sf/wms?"
rlayer = QgsRasterLayer (urlWithParams , "my_title", "wms")
rlayer.isValid()

I have tried this, How to load a WMS layer using PyQGIS?, and good enough web hunt but can't understand the issue. Is there any way to generate error code or info while working on qgis console?

  • what if the url is maps.itu.edu.tr:8082/geoserver/sf/… instead? – Ian Turton Jun 30 '15 at 16:20
  • still the same. Raster image is not loading up. But yes, you are right. I don't see any purpose of defining params that way, which I found on other online links. – Zia Jun 30 '15 at 16:26
3

Definitely that's not an obvious way of loading a WMS.

This is what have worked for me (QGIS v.2.8.1):

urlWithParams = "url=http://maps.itu.edu.tr:8082/geoserver/sf/wms&format=image/png&layers=sfdem&styles=&crs=EPSG:26713"
rlayer = QgsRasterLayer(urlWithParams, 'DEM', 'wms')
rlayer.isValid() # Returns True this time
QgsMapLayerRegistry.instance().addMapLayer(rlayer)

We can learn a couple of things from that:

  • QGIS expects a crs parameter instead of srs.
  • We don't need to pass width, height, and bbox. That's something QGIS handles for us.
  • Thx! That worked. But is there any difference between crs and srs? I am wondering. Besides I can't load the following custom raster maps.itu.edu.tr:8082/geoserver/localhost/… . May be coz it's a huge one but will look for your comment. – Zia Jul 2 '15 at 11:30
  • 1
    The new one works this way: urlWithParams="url=http://maps.itu.edu.tr:8082/geoserver/localhost/wms&layers=final&styles=&crs=EPSG:4326&format=image/png" Just try to leave only that set of parameters and also remove the namespace from layers, i.e., not localhost:final but only final. SRS was changed to CRS because the latter is more specific and tells us we are using coordinates. The former doesn't imply we use coordinates for georreferencing. See ogcnetwork.net/node/681 – Germán Carrillo Jul 2 '15 at 14:18
  • CRS very SRS is a WMS version issue, I think. – Ian Turton Jul 2 '15 at 17:52
  • Thx guys. Learned quite a bit today :) – Zia Jul 3 '15 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.