WMS in python?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

WMS in python?

Rob McCulley

Hi All,

 

Can a WMS Layer be added to an application built using the python bindings?

 

I’ve tried to do it using a few variations of parameters with the QgsDataSourceURI(), but my lyr.isValid() is always false.

 

Can I add a WMS Layer using the python bindings, and if so, how?

 

Thanks

Rob McCulley

GIS Coordinator

County of Vermilion River

(780) 846-2244

www.vermilion-river.ab.ca

 


_______________________________________________
Qgis-user mailing list
[hidden email]
http://lists.qgis.org/cgi-bin/mailman/listinfo/qgis-user
Reply | Threaded
Open this post in threaded view
|

Re: WMS in python?

Martin Dobias
On Mon, Mar 3, 2008 at 9:08 PM, Rob McCulley <[hidden email]> wrote:

>
> Can a WMS Layer be added to an application built using the python bindings?
>
>
>
> I've tried to do it using a few variations of parameters with the
> QgsDataSourceURI(), but my lyr.isValid() is always false.
>
>
>
> Can I add a WMS Layer using the python bindings, and if so, how?

It *should* be possible. There's a following constructor (available
also from python) of raster layers which is used in case of WMS:

  QgsRasterLayer(int dummy,
                 const QString & baseName = QString(),
                 const QString & path = QString(),
                 const QString & providerLib = QString(),
                 const QStringList & layers = QStringList(),
                 const QStringList & styles = QStringList(),
                 const QString & format = QString(),
                 const QString & crs = QString(),
                 const QString & proxyHost = QString(),
                 int proxyPort = 80,
                 const QString & proxyUser = QString(),
                 const QString & proxyPass = QString());

I have never done something with WMS so can't supply you with a
working example, but to get an idea how to fill in the parameters, see
QgisApp::addWmsLayer() and debug output from QgisApp::addRasterLayer()
in src/app/qgisapp.cpp.

Regards
Martin
_______________________________________________
Qgis-user mailing list
[hidden email]
http://lists.qgis.org/cgi-bin/mailman/listinfo/qgis-user
Reply | Threaded
Open this post in threaded view
|

Re: WMS in python?

Rob McCulley
> > Can a WMS Layer be added to an application built using the python
> bindings?
> >
> >
> >
> > I've tried to do it using a few variations of parameters with the
> > QgsDataSourceURI(), but my lyr.isValid() is always false.
> >
> >
> >
> > Can I add a WMS Layer using the python bindings, and if so, how?
>
> It *should* be possible. There's a following constructor (available
> also from python) of raster layers which is used in case of WMS:
>
>   QgsRasterLayer(int dummy,
>                  const QString & baseName = QString(),
>                  const QString & path = QString(),
>                  const QString & providerLib = QString(),
>                  const QStringList & layers = QStringList(),
>                  const QStringList & styles = QStringList(),
>                  const QString & format = QString(),
>                  const QString & crs = QString(),
>                  const QString & proxyHost = QString(),
>                  int proxyPort = 80,
>                  const QString & proxyUser = QString(),
>                  const QString & proxyPass = QString());
>
> I have never done something with WMS so can't supply you with a
> working example, but to get an idea how to fill in the parameters, see
> QgisApp::addWmsLayer() and debug output from QgisApp::addRasterLayer()
> in src/app/qgisapp.cpp.
>
> Regards
> Martin

Right you are Martin.  A WMS layer can be added via the python bindings
by using gdal.  I just had to set up an .xml file describing the wms
server as outlined here:  http://www.gdal.org/frmt_wms.html

Then it was a simple matter of adding the layer:

rLayer = QgsRasterLayer('data/local_wms.xml','2007 Aerial')

And everything worked perfectly.  The gdal wms provider doesn't seem
quite as fast as the native wms provider in QGIS, which isn't really a
surprise.  It works though.

Thanks for the tips!

Rob
_______________________________________________
Qgis-user mailing list
[hidden email]
http://lists.qgis.org/cgi-bin/mailman/listinfo/qgis-user