[QGIS-Developer] How to update change the datasource of already existing layer

Ivan Ivanov suricactus at gmail.com
Tue Jun 11 17:08:47 PDT 2019


I fixed it. Sorry for the inconvenience:

layer1 = QgsVectorLayer('Polygon?crs=epsg:32612', 'layer2', 'memory')
layer2 = QgsVectorLayer('Polygon?crs=epsg:32612', 'layer1', 'memory')

print(layer1.source())
print(layer2.source())
layer1.setDataSource(layer2.source(), layer2.name(),
layer2.dataProvider().name())
print(layer1.source())

On Wed, 12 Jun 2019 at 00:28, Nyall Dawson <nyall.dawson at gmail.com> wrote:

> On Tue, 11 Jun 2019 at 15:06, Ivan Ivanov <suricactus at gmail.com> wrote:
> >
> > Hello,
> >
> >
> > 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)
> >
> > oldLayer.source()
> > #
> MultiLineString?crs=EPSG:32737&field=fid:integer(0,0)&uid={6cd1f176-9c05-4d2a-961a-3143a8fa422b}
> >
> > newLayer = processing.run('save:selectedfeatures', {
> >     'INPUT': oldLayer,
> >     'OUTPUT': 'memory:newLayer'
> > )
> >
> > oldLayer.setDataSource(newLayer.source(), oldLayer.name(),
> newLayer.dataProvider().name())
> >
> > newLayer.source()
> > #
> MultiLineString?crs=EPSG:32737&field=fid:integer(0,0)&uid={d36aff88-4248-4ffb-be2f-2ac1891ac26d}
> > oldLayer.source()
> >
> > # WRONG, I would expect the same as above. Also, the uid is completely
> new.
> > #
> MultiLineString?crs=EPSG:32737&field=fid:integer(0,0)&uid={d36aff88-4248-4ffb-be2f-2ac1891ac26d}&uid={3422de07-cf38-4249-af55-23c7d9779daf}
>
> Hi Ivan,
>
> Your code seems incomplete and has some syntax errors -- maybe it
> wasn't copied correctly? Can you repost please?
>
> Nyall
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20190612/7aad345e/attachment.html>


More information about the QGIS-Developer mailing list