<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<br>
Thank you for your help.<br>
<br>
<blockquote
cite="mid:CAECJsSq6ExVGWc33jrfUsvEcdAC3DxRe+8XYDjRi+oeuZQ-=AA@mail.gmail.com"
type="cite">
<div dir="ltr"><span style="color:rgb(11,83,148)">Hi,</span><br>
<div>
<div class="gmail_extra"><br>
<div class="gmail_quote">2015-05-18 17:51 GMT+02:00 Benoît
Laurent <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:blaurent@heurisis.eu" target="_blank">blaurent@heurisis.eu</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
I would like to generate a series of maps representing
tracks with stops along them.<br>
<br>
For each track, I have got a group of two layers, one
for the linear, one for the points that have associated
information (basically name and time of the stops).
First, is there a better way to achieve this ? For the
moment, I have to handle two types of layer. It is the
beginning of my problems.<br>
<br>
As the tracks overlap, I would like to generate a map
for each track where only the current selected track
appears. The others would be hidden.<br>
<br>
I had a try with Atlas generation. It perfectly works
except that I can't hide the other tracks.<br>
<br>
</blockquote>
<div><span style="color:rgb(11,83,148)">You can style your
coverage layer so that only atlas current feature will
appear. In categorized style, use an expression like
$id=$atlasfeatureid. You'll get 0 (false) and 1 (true)
when classing. Set the 0 features style so that they
become invisible or transparent.</span> <br>
</div>
</div>
</div>
</div>
</div>
</blockquote>
It is a little better : with your help, I can highlight the current
linear layer. Actually, I aggregated all my linear layers to
constitute the coverage layer. However, I can't hide the points
layers.<br>
<br>
<blockquote
cite="mid:CAECJsSq6ExVGWc33jrfUsvEcdAC3DxRe+8XYDjRi+oeuZQ-=AA@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>
<div class="gmail_extra">
<div class="gmail_quote">
<div> <br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
I also had a try with a Python script. I managed to
iterate over the groups of layers but I can't refresh
the map canvas during the Python script. So, it doesn't
work.<br>
<br>
</blockquote>
<div><span style="color:rgb(11,83,148)">A snippet of your
code may help but I remember I had to face such a
problem and it was because after
*myatlas.beginRender()*, I forgot to set active the
export of the atlas, sthg like
*mycomposition.setAtlasMode(QgsComposition.ExportAtlas)*</span><br>
<br>
</div>
</div>
</div>
</div>
</div>
</blockquote>
Actually, I did not use the Atlas generator (maybe a mistake ?). I
wanted to reproduce/modify its behavior. Here is a piece of code
(remember that for each track, there is linear layer and a points
layer) :<br>
<br>
<pre style="" class="lang-py prettyprint prettyprinted"><code><span class="pln"> </span><span class="com"># Iterate over groups of pair of layers</span><span class="pln">
</span><span class="kwd">for</span><span class="pln"> g </span><span class="kwd">in</span><span class="pln"> range</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln">nbGroups</span><span class="pun">-</span><span class="lit">1</span><span class="pun">):</span><span class="pln">
</span><span class="com"># Display layers of the current group</span><span class="pln">
layer </span><span class="pun">=</span><span class="pln"> layers</span><span class="pun">[</span><span class="lit">2</span><span class="pun">*</span><span class="pln">g</span><span class="pun">]</span><span class="pln">
rectTrajet </span><span class="pun">=</span><span class="pln"> layer</span><span class="pun">.</span><span class="pln">extent</span><span class="pun">()</span><span class="pln">
legend</span><span class="pun">.</span><span class="pln">setLayerVisible</span><span class="pun">(</span><span class="pln">layer</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">True</span><span class="pun">)</span><span class="pln">
layer </span><span class="pun">=</span><span class="pln"> layers</span><span class="pun">[</span><span class="lit">2</span><span class="pun">*</span><span class="pln">g</span><span class="pun">+</span><span class="lit">1</span><span class="pun">]</span><span class="pln">
rectPtsArr </span><span class="pun">=</span><span class="pln"> layer</span><span class="pun">.</span><span class="pln">extent</span><span class="pun">()</span><span class="pln">
legend</span><span class="pun">.</span><span class="pln">setLayerVisible</span><span class="pun">(</span><span class="pln">layer</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">True</span><span class="pun">)</span><span class="pln">
</span><span class="com"># extent area</span><span class="pln">
rectGlb </span><span class="pun">=</span><span class="pln"> </span><span class="typ">QgsRectangle</span><span class="pln">
xMin </span><span class="pun">=</span><span class="pln"> min</span><span class="pun">(</span><span class="pln">rectTrajet</span><span class="pun">.</span><span class="pln">xMinimum</span><span class="pun">(),</span><span class="pln"> rectPtsArr</span><span class="pun">.</span><span class="pln">xMinimum</span><span class="pun">())</span><span class="pln">
xMax </span><span class="pun">=</span><span class="pln"> max</span><span class="pun">(</span><span class="pln">rectTrajet</span><span class="pun">.</span><span class="pln">xMaximum</span><span class="pun">(),</span><span class="pln"> rectPtsArr</span><span class="pun">.</span><span class="pln">xMaximum</span><span class="pun">())</span><span class="pln">
yMin </span><span class="pun">=</span><span class="pln"> min</span><span class="pun">(</span><span class="pln">rectTrajet</span><span class="pun">.</span><span class="pln">yMinimum</span><span class="pun">(),</span><span class="pln"> rectPtsArr</span><span class="pun">.</span><span class="pln">yMinimum</span><span class="pun">())</span><span class="pln">
yMax </span><span class="pun">=</span><span class="pln"> max</span><span class="pun">(</span><span class="pln">rectTrajet</span><span class="pun">.</span><span class="pln">yMaximum</span><span class="pun">(),</span><span class="pln"> rectPtsArr</span><span class="pun">.</span><span class="pln">yMaximum</span><span class="pun">())</span><span class="pln">
rectGlb </span><span class="pun">=</span><span class="pln"> </span><span class="typ">QgsRectangle</span><span class="pun">(</span><span class="pln">xMin</span><span class="pun">,</span><span class="pln"> yMin</span><span class="pun">,</span><span class="pln"> xMax</span><span class="pun">,</span><span class="pln"> yMax</span><span class="pun">)</span><span class="pln">
self</span><span class="pun">.</span><span class="pln">iface</span><span class="pun">.</span><span class="pln">mapCanvas</span><span class="pun">().</span><span class="pln">setExtent</span><span class="pun">(</span><span class="pln">rectGlb</span><span class="pun">)</span><span class="pln">
self</span><span class="pun">.</span><span class="pln">iface</span><span class="pun">.</span><span class="pln">mapCanvas</span><span class="pun">().</span><span class="pln">zoomToSelected</span><span class="pun">()</span><span class="pln">
self</span><span class="pun">.</span><span class="pln">iface</span><span class="pun">.</span><span class="pln">mapCanvas</span><span class="pun">().</span><span class="pln">updateScale</span><span class="pun">()</span><span class="pln">
self</span><span class="pun">.</span><span class="pln">iface</span><span class="pun">.</span><span class="pln">mapCanvas</span><span class="pun">().</span><span class="pln">zoomByFactor</span><span class="pun">(</span><span class="lit">1.5</span><span class="pun">)</span><span class="pln">
</span><span class="com"># Nothing works here !!</span><span class="pln">
self</span><span class="pun">.</span><span class="pln">iface</span><span class="pun">.</span><span class="pln">mapCanvas</span><span class="pun">().</span><span class="pln">updateOverview</span><span class="pun">()</span><span class="pln">
self</span><span class="pun">.</span><span class="pln">iface</span><span class="pun">.</span><span class="pln">mapCanvas</span><span class="pun">().</span><span class="pln">refresh</span><span class="pun">()</span><span class="pln">
layers</span><span class="pun">[</span><span class="lit">2</span><span class="pun">*</span><span class="pln">g</span><span class="pun">].</span><span class="pln">triggerRepaint</span><span class="pun">()</span><span class="pln">
layers</span><span class="pun">[</span><span class="lit">2</span><span class="pun">*</span><span class="pln">g</span><span class="pun">+</span><span class="lit">1</span><span class="pun">].</span><span class="pln">triggerRepaint</span><span class="pun">()</span><span class="pln">
</span><span class="com"># Map composer</span><span class="pln">
composerMap </span><span class="pun">=</span><span class="pln"> </span><span class="typ">QgsComposerMap</span><span class="pun">(</span><span class="pln">c</span><span class="pun">,</span><span class="pln">x</span><span class="pun">,</span><span class="pln">y</span><span class="pun">,</span><span class="pln">w</span><span class="pun">,</span><span class="pln">h</span><span class="pun">)</span><span class="pln">
composerMap</span><span class="pun">.</span><span class="pln">setPreviewMode</span><span class="pun">(</span><span class="typ">QgsComposerMap</span><span class="pun">.</span><span class="typ">Render</span><span class="pun">)</span><span class="pln">
composerMap</span><span class="pun">.</span><span class="pln">updateBoundingRect</span><span class="pun">()</span><span class="pln">
composerMap</span><span class="pun">.</span><span class="pln">renderModeUpdateCachedImage</span><span class="pun">()</span><span class="pln">
composerMap</span><span class="pun">.</span><span class="pln">setFrameEnabled</span><span class="pun">(</span><span class="kwd">True</span><span class="pun">)</span><span class="pln">
c</span><span class="pun">.</span><span class="pln">addItem</span><span class="pun">(</span><span class="pln">composerMap</span><span class="pun">)</span><span class="pln">
</span><span class="com"># Launch printing</span><span class="pln">
printer </span><span class="pun">=</span><span class="pln"> </span><span class="typ">QtGui</span><span class="pun">.</span><span class="typ">QPrinter</span><span class="pun">()</span><span class="pln">
printer</span><span class="pun">.</span><span class="pln">setOutputFormat</span><span class="pun">(</span><span class="typ">QtGui</span><span class="pun">.</span><span class="typ">QPrinter</span><span class="pun">.</span><span class="typ">PdfFormat</span><span class="pun">)</span><span class="pln">
printer</span><span class="pun">.</span><span class="pln">setOutputFileName</span><span class="pun">(</span><span class="pln">nomFichier</span><span class="pun">)</span><span class="pln">
printer</span><span class="pun">.</span><span class="pln">setPaperSize</span><span class="pun">(</span><span class="typ">QSizeF</span><span class="pun">(</span><span class="pln">c</span><span class="pun">.</span><span class="pln">paperWidth</span><span class="pun">(),</span><span class="pln"> c</span><span class="pun">.</span><span class="pln">paperHeight</span><span class="pun">()),</span><span class="pln"> </span><span class="typ">QtGui</span><span class="pun">.</span><span class="typ">QPrinter</span><span class="pun">.</span><span class="typ">Millimeter</span><span class="pun">)</span><span class="pln">
printer</span><span class="pun">.</span><span class="pln">setFullPage</span><span class="pun">(</span><span class="kwd">True</span><span class="pun">)</span><span class="pln">
printer</span><span class="pun">.</span><span class="pln">setColorMode</span><span class="pun">(</span><span class="typ">QtGui</span><span class="pun">.</span><span class="typ">QPrinter</span><span class="pun">.</span><span class="typ">Color</span><span class="pun">)</span><span class="pln">
printer</span><span class="pun">.</span><span class="pln">setResolution</span><span class="pun">(</span><span class="pln">c</span><span class="pun">.</span><span class="pln">printResolution</span><span class="pun">())</span><span class="pln">
pdfPainter </span><span class="pun">=</span><span class="pln"> </span><span class="typ">QPainter</span><span class="pun">(</span><span class="pln">printer</span><span class="pun">)</span><span class="pln">
paperRectMM </span><span class="pun">=</span><span class="pln"> printer</span><span class="pun">.</span><span class="pln">pageRect</span><span class="pun">(</span><span class="typ">QtGui</span><span class="pun">.</span><span class="typ">QPrinter</span><span class="pun">.</span><span class="typ">Millimeter</span><span class="pun">)</span><span class="pln">
paperRectPixel </span><span class="pun">=</span><span class="pln"> printer</span><span class="pun">.</span><span class="pln">pageRect</span><span class="pun">(</span><span class="typ">QtGui</span><span class="pun">.</span><span class="typ">QPrinter</span><span class="pun">.</span><span class="typ">DevicePixel</span><span class="pun">)</span><span class="pln">
c</span><span class="pun">.</span><span class="pln">render</span><span class="pun">(</span><span class="pln">pdfPainter</span><span class="pun">,</span><span class="pln"> paperRectPixel</span><span class="pun">,</span><span class="pln"> paperRectMM</span><span class="pun">)</span><span class="pln">
pdfPainter</span><span class="pun">.</span><span class="pln">end</span><span class="pun">()</span><span class="pln">
</span><span class="com"># Remove map composer</span><span class="pln">
c</span><span class="pun">.</span><span class="pln">removeItem</span><span class="pun">(</span><span class="pln">composerMap</span><span class="pun">)</span><span class="pln">
</span><span class="com"># Hide layers of the current group</span><span class="pln">
legend</span><span class="pun">.</span><span class="pln">setLayerVisible</span><span class="pun">(</span><span class="pln">layers</span><span class="pun">[</span><span class="lit">2</span><span class="pun">*</span><span class="pln">g</span><span class="pun">],</span><span class="pln"> </span><span class="kwd">False</span><span class="pun">)</span><span class="pln">
legend</span><span class="pun">.</span><span class="pln">setLayerVisible</span><span class="pun">(</span><span class="pln">layers</span><span class="pun">[</span><span class="lit">2</span><span class="pun">*</span><span class="pln">g</span><span class="pun">+</span><span class="lit">1</span><span class="pun">],</span><span class="pln"> </span><span class="kwd">False</span><span class="pun">)</span><span class="pln">
</span></code></pre>
<br>
<br /><br />
<hr style='border:none; color:#909090; background-color:#B0B0B0; height: 1px; width: 99%;' />
<table style='border-collapse:collapse;border:none;'>
<tr>
<td style='border:none;padding:0px 15px 0px 8px'>
<a href="http://www.avast.com/">
<img border=0 src="http://static.avast.com/emails/avast-mail-stamp.png" />
</a>
</td>
<td>
<p style='color:#3d4d5a; font-family:"Calibri","Verdana","Arial","Helvetica"; font-size:12pt;'>
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
<br><a href="http://www.avast.com/">www.avast.com</a>
</p>
</td>
</tr>
</table>
<br />
</body>
</html>