<div dir="ltr"><div><div><div><div>Hi,<br><br></div>Thanks for your answer, Tim. The framadrop link is working on my side. You may try again.<br><br>So to directly answer to your question without the framadrop issue.<br><br>In fact, I do not declare any layer here in the code but I only reference a different "qgs" file.<br></div><div>One is with only a shapefile (Natural Earth Data countries), a second one with both shapefile and WMS from OpenGeo GeoServer demo<br></div><div>(exact url for data source is<br>contextualWMSLegend=0&crs=EPSG:4326&dpiMode=7&featureCount=10&format=image/png&layers=ne:NE1_HR_LC_SR_W_DR&styles=&url=<a href="http://demo.boundlessgeo.com/geoserver/wms">http://demo.boundlessgeo.com/geoserver/wms</a>)<br></div><div><br><br></div>The code is the following (tested with QGIS 2.10)<br><br># coding:utf-8<br><br># A simple demonstration of how to load a QGIS project and then<br># show it in a widget.<br># This code is public domain, use if for any purpose you see fit.<br># Tim Sutton 2015<br><br>import os<br>from qgis.core import QgsProject<br>from qgis.gui import QgsMapCanvas, QgsLayerTreeMapCanvasBridge<br>from qgis.core.contextmanagers import qgisapp<br>from PyQt4.QtCore import QFileInfo, Qt<br><br>with qgisapp():<br>    project_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'world.qgs')<br>    canvas = QgsMapCanvas(None)<br>    canvas.setCanvasColor(Qt.white)<br>    canvas.enableAntiAliasing(True)<br><br>    # Load our project<br>    bridge = QgsLayerTreeMapCanvasBridge(<br>        QgsProject.instance().layerTreeRoot(), canvas)<br>    QgsProject.instance().read(QFileInfo(project_path))<br>    canvas.setCrsTransformEnabled(True)<br>    canvas.mapRenderer().setProjectionsEnabled(True)<br><br>    canvas.show()<br><br></div><div>Only `world.qgs` file changes as already explained<br></div><div><br></div>Cheers<br><br><br></div>Thomas Gratier<br></div><div class="gmail_extra"><br><div class="gmail_quote">2015-10-21 23:28 GMT+02:00 Tim Sutton <span dir="ltr"><<a href="mailto:tim@qgis.org" target="_blank">tim@qgis.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hi Thomas<div><br><div><span class=""><blockquote type="cite"><div>On 12 Oct 2015, at 18:08, Thomas Gratier <<a href="mailto:osgeo.mailinglist@gmail.com" target="_blank">osgeo.mailinglist@gmail.com</a>> wrote:</div><br><div><div dir="ltr"><div><div><div><div><div><div><div>Hi,<br><br></div><div>I'm working with the Python API to create a standalone app.<br></div>When I reuse this sample from <a href="http://kartoza.com/how-to-load-a-qgis-project-in-python/" target="_blank">http://kartoza.com/how-to-load-a-qgis-project-in-python/</a>, it works perfectly with only vector layer(s).<br></div>When I use a WMS with a vector layer, it fails directly.<br></div>I've done two samples to demonstrate the issue. You can take samples from <a href="https://framadrop.org/r/kkC2MVV9TH#anlncOhrg5vbo5W7D8Lfjg8ghRq7BTo9flJXvnIV+Io=" target="_blank">https://framadrop.org/r/kkC2MVV9TH#anlncOhrg5vbo5W7D8Lfjg8ghRq7BTo9flJXvnIV+Io=</a> <br></div></div></div></div></div></div></blockquote><div><br></div></span><span>It seems like that <a href="http://framadrop.org" target="_blank">framadrop.org</a> site is broken (FileConstructor is not a constructor (evaluating 'new File(a, <a href="http://data.name" target="_blank">data.name</a>, {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.</span></div><div><span><br></span></div><div><span>Regards</span></div><div><span><br></span></div><div><span>Tim<br></span><span><br></span><blockquote type="cite"><div><span class=""><div dir="ltr"><div><div><div><div><br></div>Run the working vector sample with:<br></div>    python test_project_standalone_no_wms.py<br><br>Run the non working wms + vector sample with:<br>    python test_project_standalone.py<br><br></div>I should miss something. Do you have any clue? It's a bug or a feature (unwanted for my case)?<br><br></div>Cheers<br><br>Thomas Gratier<br></div></span>
_______________________________________________<br>Qgis-user mailing list<br><a href="mailto:Qgis-user@lists.osgeo.org" target="_blank">Qgis-user@lists.osgeo.org</a><br><a href="http://lists.osgeo.org/mailman/listinfo/qgis-user" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-user</a></div></blockquote></div><br><div>
<span><img src="cid:DDEF9B12-67C3-4498-BD7D-EC3563CC35A4" height="60" width="60"></span><span class="HOEnZb"><font color="#888888"><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div><br><br></div><div>Tim Sutton</div><div>QGIS Project Steering Committee Member</div><div><a href="mailto:tim@qgis.org" target="_blank">tim@qgis.org</a></div><div><br></div></div><br style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br>
</font></span></div>
<br></div></div></blockquote></div><br></div>