<div dir="ltr"><div class="gmail_default" style="color:#666666">Hi, Nyall,<br></div><div class="gmail_default" style="color:#666666"><br></div><div class="gmail_default" style="color:#666666">I'm developing a plugin with a lot of internal layers, that are being (re)created on user interaction. </div><div class="gmail_default" style="color:#666666"><br></div><div class="gmail_default" style="color:#666666">There are multiple event listeners attached to a layer, as well as passed around to different functions and might have custom styles. At some point, I want to replace the layer entirely with another one (result from an algorithm). </div><div class="gmail_default" style="color:#666666"><br></div><div class="gmail_default" style="color:#666666">To solve this, I came up with three solutions, maybe there are more:</div><div class="gmail_default" style="color:#666666">One option to achieve this is to copy all the features from the new layer and put them in the first one, but the layers might be very big and I'm afraid it would be a problem. </div><div class="gmail_default" style="color:#666666">The second option that I'm currently using is to recreate all the event listeners on the new layer and replace it from the layer tree. This is okayish and it works.</div><div class="gmail_default" style="color:#666666">The third option is to set a new data source, as I thought it's the most optimal one, however, when the layer has two uids it's practically broken.</div><div class="gmail_default" style="color:#666666"><br></div><div class="gmail_default" style="color:#666666">I got some inspiration from here: <a href="https://github.com/enricofer/changeDataSource/blob/master/setdatasource.py#L175-L206" target="_blank">https://github.com/enricofer/changeDataSource/blob/master/setdatasource.py#L175-L206</a></div><div class="gmail_default" style="color:#666666">directly editing the XML but the result is the same - double ids. I checked this plugin because I'm sure it used to work in 3.2 (currently having 3.6.3 on Ubuntu). </div><div class="gmail_default" style="color:#666666"><br></div><div class="gmail_default" style="color:#666666">Best,<br>Ivan</div><div class="gmail_default" style="color:#666666"><br></div><div class="gmail_default" style="color:#666666"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 14 Jun 2019 at 01:21, Nyall Dawson <<a href="mailto:nyall.dawson@gmail.com" target="_blank">nyall.dawson@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Wed, 12 Jun 2019 at 10:09, Ivan Ivanov <<a href="mailto:suricactus@gmail.com" target="_blank">suricactus@gmail.com</a>> wrote:<br>
><br>
> I fixed it. Sorry for the inconvenience:<br>
><br>
> layer1 = QgsVectorLayer('Polygon?crs=epsg:32612', 'layer2', 'memory')<br>
> layer2 = QgsVectorLayer('Polygon?crs=epsg:32612', 'layer1', 'memory')<br>
><br>
> print(layer1.source())<br>
> print(layer2.source())<br>
> layer1.setDataSource(layer2.source(), <a href="http://layer2.name" rel="noreferrer" target="_blank">layer2.name</a>(), layer2.dataProvider().name())<br>
> print(layer1.source())<br>
<br>
I agree that the results of this output look odd - but what exactly<br>
are you trying to achieve here?<br>
<br>
Nyall<br>
<br>
><br>
> On Wed, 12 Jun 2019 at 00:28, Nyall Dawson <<a href="mailto:nyall.dawson@gmail.com" target="_blank">nyall.dawson@gmail.com</a>> wrote:<br>
>><br>
>> On Tue, 11 Jun 2019 at 15:06, Ivan Ivanov <<a href="mailto:suricactus@gmail.com" target="_blank">suricactus@gmail.com</a>> wrote:<br>
>> ><br>
>> > Hello,<br>
>> ><br>
>> ><br>
>> > Can you give me some idea why I'm getting two uids in the layer's source? And also how I can fix this because now the layer just disappears from the map canvas. (all layers are isValid() = True)<br>
>> ><br>
>> > oldLayer.source()<br>
>> > # MultiLineString?crs=EPSG:32737&field=fid:integer(0,0)&uid={6cd1f176-9c05-4d2a-961a-3143a8fa422b}<br>
>> ><br>
>> > newLayer = processing.run('save:selectedfeatures', {<br>
>> >     'INPUT': oldLayer,<br>
>> >     'OUTPUT': 'memory:newLayer'<br>
>> > )<br>
>> ><br>
>> > oldLayer.setDataSource(newLayer.source(), oldLayer.name(), newLayer.dataProvider().name())<br>
>> ><br>
>> > newLayer.source()<br>
>> > # MultiLineString?crs=EPSG:32737&field=fid:integer(0,0)&uid={d36aff88-4248-4ffb-be2f-2ac1891ac26d}<br>
>> > oldLayer.source()<br>
>> ><br>
>> > # WRONG, I would expect the same as above. Also, the uid is completely new.<br>
>> > # MultiLineString?crs=EPSG:32737&field=fid:integer(0,0)&uid={d36aff88-4248-4ffb-be2f-2ac1891ac26d}&uid={3422de07-cf38-4249-af55-23c7d9779daf}<br>
>><br>
>> Hi Ivan,<br>
>><br>
>> Your code seems incomplete and has some syntax errors -- maybe it<br>
>> wasn't copied correctly? Can you repost please?<br>
>><br>
>> Nyall<br>
</blockquote></div>