<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 12 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
pre
{mso-style-priority:99;
mso-style-link:"HTML Vorformatiert Zchn";
margin:0cm;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
{mso-style-priority:99;
mso-style-link:"Sprechblasentext Zchn";
margin:0cm;
margin-bottom:.0001pt;
font-size:8.0pt;
font-family:"Tahoma","sans-serif";}
span.E-MailFormatvorlage17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
span.SprechblasentextZchn
{mso-style-name:"Sprechblasentext Zchn";
mso-style-priority:99;
mso-style-link:Sprechblasentext;
font-family:"Tahoma","sans-serif";}
span.HTMLVorformatiertZchn
{mso-style-name:"HTML Vorformatiert Zchn";
mso-style-priority:99;
mso-style-link:"HTML Vorformatiert";
font-family:"Courier New";}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="2050" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="DE" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Hi developers,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="EN-US">i’m facing a problem which i do not understand. In our plugin I created a function to set snapping options and bound it to a shortcut.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Using Qgis 2.14.3, source code see below.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">The assigned shortcut works well, but for the snapping I have to do the following on every QGIS start:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Go to snapping options, mode = advanced, press ok (without changing anything). Then it works afterwards!
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">But when I print the options <b>before</b> I do this, I definitely get the right options (see below).<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Does anyone know what I’m missing? Should I open an bug report? Is there a workaround do do: “Go to snapping options, mode = advanced, press ok” programmatically ?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thanks for any help<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Christian<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">## Print result<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Initialize, when aggroInstance is true<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">(True, False, 2, 0, 2.0, True)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">(True, False, 2, 0, 2.0, True)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">(True, False, 2, 0, 2.0, True)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">(True, False, 2, 0, 2.0, True)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">(True, False, 2, 0, 2.0, True)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">(True, False, 2, 0, 2.0, True)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">(True, False, 2, 0, 2.0, True)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">(True, False, 2, 0, 2.0, True)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">checked<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">(True, False, 2, 0, 2.0, True)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">(True, False, 2, 0, 2.0, True)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">(True, True, 2, 0, 2.0, False)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">(True, False, 2, 0, 2.0, True)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">(True, False, 2, 0, 2.0, True)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">(True, True, 2, 0, 2.0, False)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">(True, False, 2, 0, 2.0, True)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">(True, False, 2, 0, 2.0, True)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">## function<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal" style="background:white"><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:navy">def
</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">toggleSnapping(checked):<br>
</span><i><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:gray">'''<br>
Toggle snapping option<br>
</span></i><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:gray">:param</span></b><i><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:gray"> checked: True if snapping has been activated, False otherwise<br>
'''<br>
</span></i><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">aggroInstance = initModule.aggroInstance<br>
</span><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:navy">print
</span></b><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:green">'Initialize'<br>
</span></b><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:navy">if
</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:navy">bool</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">(agroInstance):<br>
</span><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:navy">for
</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">item
</span><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:navy">in
</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">QgsMapLayerRegistry.instance().mapLayers().values():<br>
QgsProject.instance().setSnapSettingsForLayer(item.id(), </span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:navy">False</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">,
</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:blue">2</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">,
</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:blue">0</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">,
</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:blue">2</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">,
</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:navy">True</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">)<br>
fieldLayer = mapUtils.getLayerByName(aggroInstance.dictData[</span><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:green">'field'</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">])<br>
backgroundLayer = mapUtils.getLayerByName(</span><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:green">'bg'</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">)<br>
</span><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:navy">for
</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">item
</span><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:navy">in
</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">QgsMapLayerRegistry.instance().mapLayers().values():<br>
</span><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:navy">print
</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">QgsProject.instance().snapSettingsForLayer(item.id())<br>
</span><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:navy">if
</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">checked:<br>
</span><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:navy">print
</span></b><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:green">'checked'<br>
</span></b><i><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:gray"># Convenience function to set snap settings per layer.<br>
# it defines the snapping options:<br>
# id : the id of your layer, True : to enable the layer snapping, 2 : options (2: vertex+segment), 0: type of unit on map, 2 : tolerance, true : avoidIntersection)<br>
</span></i><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">QgsProject.instance().setSnapSettingsForLayer(fieldLayer.id(),
</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:navy">True</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">,
</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:blue">2</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">,
</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:blue">0</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">,
</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:blue">2</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">,
</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:navy">False</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">)<br>
QgsProject.instance().setSnapSettingsForLayer(backgroundLayer.id(), </span>
<span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:navy">True</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">,
</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:blue">2</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">,
</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:blue">0</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">,
</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:blue">2</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">,
</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:navy">False</span><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">)<br>
</span><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:navy">for
</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">item
</span><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:navy">in
</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">QgsMapLayerRegistry.instance().mapLayers().values():<br>
</span><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:navy">print
</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">QgsProject.instance().snapSettingsForLayer(item.id())<br>
<br>
<o:p></o:p></span></p>
<p class="MsoNormal" style="background:white"><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal" style="background:white"><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black">## initialization in run() method<o:p></o:p></span></p>
<p class="MsoNormal" style="background:white"><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black"><o:p> </o:p></span></p>
<pre style="background:white"><i><span lang="EN-US" style="color:gray"># Call Snapping Tool by a key shortcut<br></span></i><b><span lang="EN-US" style="color:navy">for </span></b><span lang="EN-US" style="color:black">action </span><b><span lang="EN-US" style="color:navy">in </span></b><span lang="EN-US" style="color:#94558D">self</span><span lang="EN-US" style="color:black">.actions:<br> </span><b><span lang="EN-US" style="color:navy">if </span></b><span lang="EN-US" style="color:black">action.text() == </span><b><span lang="EN-US" style="color:green">'Toggle Snapping'</span></b><span lang="EN-US" style="color:black">:<br> </span><i><span lang="EN-US" style="color:gray"># Action triggered by shortcut key<br> </span></i><span lang="EN-US" style="color:#94558D">self</span><span lang="EN-US" style="color:black">.iface.registerMainWindowAction(action, </span><b><span lang="EN-US" style="color:green">"c"</span></b><span lang="EN-US" style="color:black">)<o:p></o:p></span></pre>
<p class="MsoNormal" style="background:white"><span lang="EN-US" style="font-size:10.0pt;font-family:"Courier New";color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:8.0pt;font-family:"Arial","sans-serif"">--<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:8.0pt;font-family:"Arial","sans-serif""><img width="623" height="6" id="Bild_x0020_1" src="cid:image001.gif@01D1CD62.00B27700" alt="image003"><span style="color:white"><o:p></o:p></span></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:8.0pt;font-family:"Arial","sans-serif";color:#002060"><img width="213" height="119" id="Bild_x0020_2" src="cid:image002.gif@01D1CD62.00B27700" alt="eftas3"></span><span style="font-size:8.0pt;font-family:"Arial","sans-serif""><o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:8.0pt;font-family:"Arial","sans-serif"">Dipl.-Geoinf. Christian Röttger<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:8.0pt;font-family:"Arial","sans-serif"">-Forschung und Entwicklung<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:8.0pt;font-family:"Arial","sans-serif"">E F T A S Fernerkundung<br>
Technologietransfer GmbH<br>
Oststraße 2-18<br>
48145 Münster<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:8.0pt;font-family:"Arial","sans-serif"">Fon: +49 251 13307-23 E-Mail:
</span><a href="mailto:christian.roettger@eftas.com"><span style="color:blue"><span style="font-size:8.0pt;font-family:"Arial","sans-serif";color:#E2001A">christian.roettger@eftas.com</span></span></a><span style="font-size:8.0pt;font-family:"Arial","sans-serif""><br>
Fax: +49 251 13307-33 Web: </span><a href="http://www.eftas.com/" title="blocked::http://www.eftas.com/"><span style="font-size:8.0pt;font-family:"Arial","sans-serif";color:#E2001A">http://www.eftas.com</span></a><span style="font-size:8.0pt;font-family:"Arial","sans-serif""><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:8.0pt;font-family:"Arial","sans-serif"">Geschäftsführer:<br>
Dipl.-Ing. Georg Altrogge<br>
<br>
Sitz der Gesellschaft: Münster<br>
Amtsgericht Münster, HRB 2999<br>
USt.-IdNr. DE 126038986<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:8.0pt;font-family:"Arial","sans-serif";color:white">******************************************************************<o:p></o:p></span></p>
<p class="MsoNormal"><img border="0" width="623" height="21" id="Bild_x0020_3" src="cid:image003.gif@01D1CD62.00B27700" alt="image007"><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>