[Qgis-user] WMS display issue and QGIS based standalone application

Thomas Gratier osgeo.mailinglist at gmail.com
Wed Oct 21 17:13:23 PDT 2015


Hi,

Thanks for your answer, Tim. The framadrop link is working on my side. You
may try again.

So to directly answer to your question without the framadrop issue.

In fact, I do not declare any layer here in the code but I only reference a
different "qgs" file.
One is with only a shapefile (Natural Earth Data countries), a second one
with both shapefile and WMS from OpenGeo GeoServer demo
(exact url for data source is
contextualWMSLegend=0&crs=EPSG:4326&dpiMode=7&featureCount=10&format=image/png&layers=ne:NE1_HR_LC_SR_W_DR&styles=&url=
http://demo.boundlessgeo.com/geoserver/wms)


The code is the following (tested with QGIS 2.10)

# coding:utf-8

# A simple demonstration of how to load a QGIS project and then
# show it in a widget.
# This code is public domain, use if for any purpose you see fit.
# Tim Sutton 2015

import os
from qgis.core import QgsProject
from qgis.gui import QgsMapCanvas, QgsLayerTreeMapCanvasBridge
from qgis.core.contextmanagers import qgisapp
from PyQt4.QtCore import QFileInfo, Qt

with qgisapp():
    project_path =
os.path.join(os.path.dirname(os.path.realpath(__file__)), 'world.qgs')
    canvas = QgsMapCanvas(None)
    canvas.setCanvasColor(Qt.white)
    canvas.enableAntiAliasing(True)

    # Load our project
    bridge = QgsLayerTreeMapCanvasBridge(
        QgsProject.instance().layerTreeRoot(), canvas)
    QgsProject.instance().read(QFileInfo(project_path))
    canvas.setCrsTransformEnabled(True)
    canvas.mapRenderer().setProjectionsEnabled(True)

    canvas.show()

Only `world.qgs` file changes as already explained

Cheers


Thomas Gratier

2015-10-21 23:28 GMT+02:00 Tim Sutton <tim at qgis.org>:

> Hi Thomas
>
> On 12 Oct 2015, at 18:08, Thomas Gratier <osgeo.mailinglist at gmail.com>
> wrote:
>
> Hi,
>
> I'm working with the Python API to create a standalone app.
> When I reuse this sample from
> http://kartoza.com/how-to-load-a-qgis-project-in-python/, it works
> perfectly with only vector layer(s).
> When I use a WMS with a vector layer, it fails directly.
> I've done two samples to demonstrate the issue. You can take samples from
> https://framadrop.org/r/kkC2MVV9TH#anlncOhrg5vbo5W7D8Lfjg8ghRq7BTo9flJXvnIV+Io=
>
>
> It seems like that framadrop.org site is broken (FileConstructor is not a
> constructor (evaluating 'new File(a, data.name, {type: data.type})’)) so
> I cannot view the example. But you said above that you were trying ‘WMS
> with a vector layer’ so I am wondering if you have been trying to add a WMS
> layer as a raster layer rather than a vector layer? If you can just reply
> with the relevant snippet of code you are trying to use that would help to
> see what is going on.
>
> Regards
>
> Tim
>
>
> Run the working vector sample with:
>     python test_project_standalone_no_wms.py
>
> Run the non working wms + vector sample with:
>     python test_project_standalone.py
>
> I should miss something. Do you have any clue? It's a bug or a feature
> (unwanted for my case)?
>
> Cheers
>
> Thomas Gratier
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-user
>
>
>
>
> Tim Sutton
> QGIS Project Steering Committee Member
> tim at qgis.org
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20151022/f5444c77/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PastedGraphic-1.tiff
Type: image/tiff
Size: 9882 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20151022/f5444c77/attachment.tiff>


More information about the Qgis-user mailing list