[Qgis-developer] Adding a WMS layer via python

Nyall Dawson nyall.dawson at gmail.com
Sun Feb 24 19:21:05 PST 2013


>
> I haven't had need to tweak the tile size so I can't offer any advice there.
> However I have had success adding authenticated WMS layers to 1.8 with this
> code:
>
> if len(self.user) > 0 :
> connectionString = "username=" + self.user + ",password=" + self.password +
> ",url=" + self.url
> else:
> connectionString = self.url
>

Thanks for this -- I've managed to solve this one now. Turns out the
username and password can be set through QgsDataSourceURI() by:

uri.setParam("username", "xx")
uri.setParam("password", "xx")

(rather then setUsername/setPassword).

The tilesize are set by the parameters maxWidth/maxHeight:

uri.setParam("maxWidth", "512")
uri.setParam("maxHeight", "512")

Cheers,
Nyall


More information about the Qgis-developer mailing list