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?
1 Answer 1
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 ofsrs
. - 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
andsrs
? 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– Zia2015年07月02日 11:30:17 +00:00Commented Jul 2, 2015 at 11:30 -
1The 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 fromlayers
, i.e., notlocalhost:final
but onlyfinal
. 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/681Germán Carrillo– Germán Carrillo2015年07月02日 14:18:07 +00:00Commented Jul 2, 2015 at 14:18 -
CRS very SRS is a WMS version issue, I think.Ian Turton– Ian Turton2015年07月02日 17:52:56 +00:00Commented Jul 2, 2015 at 17:52
-
Thx guys. Learned quite a bit today :)Zia– Zia2015年07月03日 12:40:04 +00:00Commented Jul 3, 2015 at 12:40
params
that way, which I found on other online links.