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?

asked Jun 30, 2015 at 15:10
2
  • what if the url is maps.itu.edu.tr:8082/geoserver/sf/… instead? Commented Jun 30, 2015 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. Commented Jun 30, 2015 at 16:26

1 Answer 1

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.
answered Jul 2, 2015 at 4:04
4
  • 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. Commented Jul 2, 2015 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 Commented Jul 2, 2015 at 14:18
  • CRS very SRS is a WMS version issue, I think. Commented Jul 2, 2015 at 17:52
  • Thx guys. Learned quite a bit today :) Commented Jul 3, 2015 at 12:40

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.