Skip to main content

I want to clone my generated memory layer and apply different filters and symbology. The clone is visible in the layer tree, but doesn't displayshow up in the canvas. What I am I doing wrong?

uri = f'point?crs=EPSG:25832&field=id:integer&index=yes'
l_out = QgsVectorLayer(uri, 'new layer', 'memory')

x, y = 369000, 5616000
with edit(l_out):
    for i in range(10):
        f = QgsFeature(l_out.fields())
        g = QgsGeometry(QgsPoint(x, y))
        f.setGeometry(g)
        f.setAttributes([i])
        l_out.addFeature(f)
        x += 50
        y += 50

project = QgsProject.instance()
project.addMapLayer(l_out)

tree = project.layerTreeRoot()
group0 = tree.insertGroup(0, 'level 0')
group1 = group0.addGroup('level 1')

lcopy = project.addMapLayer(l_out.clone(), False)
nodecopy = group1.insertLayer(-1, lcopy)

I want to clone my generated memory layer and apply different filters and symbology. The clone is visible in the layer tree, but doesn't display in the canvas. What I am doing wrong?

uri = f'point?crs=EPSG:25832&field=id:integer&index=yes'
l_out = QgsVectorLayer(uri, 'new layer', 'memory')

x, y = 369000, 5616000
with edit(l_out):
    for i in range(10):
        f = QgsFeature(l_out.fields())
        g = QgsGeometry(QgsPoint(x, y))
        f.setGeometry(g)
        f.setAttributes([i])
        l_out.addFeature(f)
        x += 50
        y += 50

project = QgsProject.instance()
project.addMapLayer(l_out)

tree = project.layerTreeRoot()
group0 = tree.insertGroup(0, 'level 0')
group1 = group0.addGroup('level 1')

lcopy = project.addMapLayer(l_out.clone(), False)
nodecopy = group1.insertLayer(-1, lcopy)

I want to clone my generated memory layer and apply different filters and symbology. The clone is visible in the layer tree, but doesn't show up in the canvas. What am I doing wrong?

uri = f'point?crs=EPSG:25832&field=id:integer&index=yes'
l_out = QgsVectorLayer(uri, 'new layer', 'memory')

x, y = 369000, 5616000
with edit(l_out):
    for i in range(10):
        f = QgsFeature(l_out.fields())
        g = QgsGeometry(QgsPoint(x, y))
        f.setGeometry(g)
        f.setAttributes([i])
        l_out.addFeature(f)
        x += 50
        y += 50

project = QgsProject.instance()
project.addMapLayer(l_out)

tree = project.layerTreeRoot()
group0 = tree.insertGroup(0, 'level 0')
group1 = group0.addGroup('level 1')

lcopy = project.addMapLayer(l_out.clone(), False)
nodecopy = group1.insertLayer(-1, lcopy)
Became Hot Network Question
added 25 characters in body; edited tags; edited title
Source Link
Taras
  • 34k
  • 4
  • 73
  • 148

How to clone my Cloning the map layer? using PyQGIS

I want to clone my generated memory layer and apply different filters and symbology. The clone is visible in the layer tree, but doesn't display in the canvas. What I am doing wrong?

uri = f'point?crs=EPSG:25832&field=id:integer&index=yes'
l_out = QgsVectorLayer(uri, 'new layer', 'memory')

x, y = 369000, 5616000
with edit(l_out):
    for i in range(10):
        f = QgsFeature(l_out.fields())
        g = QgsGeometry(QgsPoint(x, y))
        f.setGeometry(g)
        f.setAttributes([i])
        l_out.addFeature(f)
        x += 50
        y += 50

project = QgsProject.instance()
project.addMapLayer(l_out)

tree = project.layerTreeRoot()
group0 = tree.insertGroup(0, 'level 0')
group1 = group0.addGroup('level 1')

lcopy = project.addMapLayer(l_out.clone(), False)
nodecopy = group1.insertLayer(-1, lcopy)
uri = f'point?crs=EPSG:25832&field=id:integer&index=yes'
l_out = QgsVectorLayer(uri, 'new layer', 'memory')

x, y = 369000, 5616000
with edit(l_out):
    for i in range(10):
        f = QgsFeature(l_out.fields())
        g = QgsGeometry(QgsPoint(x, y))
        f.setGeometry(g)
        f.setAttributes([i])
        l_out.addFeature(f)
        x += 50
        y += 50

project = QgsProject.instance()
project.addMapLayer(l_out)

tree = project.layerTreeRoot()
group0 = tree.insertGroup(0, 'level 0')
group1 = group0.addGroup('level 1')

lcopy = project.addMapLayer(l_out.clone(), False)
nodecopy = group1.insertLayer(-1, lcopy)

How to clone my map layer?

I want to clone my generated memory layer and apply different filters and symbology. The clone is visible in the layer tree, but doesn't display in the canvas. What I am doing wrong?

uri = f'point?crs=EPSG:25832&field=id:integer&index=yes'
l_out = QgsVectorLayer(uri, 'new layer', 'memory')

x, y = 369000, 5616000
with edit(l_out):
    for i in range(10):
        f = QgsFeature(l_out.fields())
        g = QgsGeometry(QgsPoint(x, y))
        f.setGeometry(g)
        f.setAttributes([i])
        l_out.addFeature(f)
        x += 50
        y += 50

project = QgsProject.instance()
project.addMapLayer(l_out)

tree = project.layerTreeRoot()
group0 = tree.insertGroup(0, 'level 0')
group1 = group0.addGroup('level 1')

lcopy = project.addMapLayer(l_out.clone(), False)
nodecopy = group1.insertLayer(-1, lcopy)

Cloning the map layer using PyQGIS

I want to clone my generated memory layer and apply different filters and symbology. The clone is visible in the layer tree, but doesn't display in the canvas. What I am doing wrong?

uri = f'point?crs=EPSG:25832&field=id:integer&index=yes'
l_out = QgsVectorLayer(uri, 'new layer', 'memory')

x, y = 369000, 5616000
with edit(l_out):
    for i in range(10):
        f = QgsFeature(l_out.fields())
        g = QgsGeometry(QgsPoint(x, y))
        f.setGeometry(g)
        f.setAttributes([i])
        l_out.addFeature(f)
        x += 50
        y += 50

project = QgsProject.instance()
project.addMapLayer(l_out)

tree = project.layerTreeRoot()
group0 = tree.insertGroup(0, 'level 0')
group1 = group0.addGroup('level 1')

lcopy = project.addMapLayer(l_out.clone(), False)
nodecopy = group1.insertLayer(-1, lcopy)
edited body
Source Link
Redoute
  • 2.2k
  • 2
  • 16
  • 23

I want to clone my generated memory layer and apply different filters and symbology. The clone is visible in the layer tree, but doesn't display in the canvas. What I am doing wrong?

uri = f'point?crs=EPSG:25832&field=id:integer&index=yes'
l_out = QgsVectorLayer(uri, 'new layer', 'memory')

x, y = 369000, 5616000
with edit(l_out):
    for i in range(10):
        f = QgsFeature(l_out.fields())
        g = QgsGeometry(QgsPoint(x, y))
        f.setGeometry(g)
        f.setAttributes([i])
        l_out.addFeature(f)
        x += 50
        y += 50

project.addMapLayer(l_out)

project = QgsProject.instance()
project.addMapLayer(l_out)

tree = project.layerTreeRoot()
group0 = tree.insertGroup(0, 'level 0')
group1 = group0.addGroup('level 1')

lcopy = project.addMapLayer(l_out.clone(), False)
nodecopy = group1.insertLayer(-1, lcopy)

I want to clone my generated memory layer and apply different filters and symbology. The clone is visible in the layer tree, but doesn't display in the canvas. What I am doing wrong?

uri = f'point?crs=EPSG:25832&field=id:integer&index=yes'
l_out = QgsVectorLayer(uri, 'new layer', 'memory')

x, y = 369000, 5616000
with edit(l_out):
    for i in range(10):
        f = QgsFeature(l_out.fields())
        g = QgsGeometry(QgsPoint(x, y))
        f.setGeometry(g)
        f.setAttributes([i])
        l_out.addFeature(f)
        x += 50
        y += 50

project.addMapLayer(l_out)

project = QgsProject.instance()
tree = project.layerTreeRoot()
group0 = tree.insertGroup(0, 'level 0')
group1 = group0.addGroup('level 1')

lcopy = project.addMapLayer(l_out.clone(), False)
nodecopy = group1.insertLayer(-1, lcopy)

I want to clone my generated memory layer and apply different filters and symbology. The clone is visible in the layer tree, but doesn't display in the canvas. What I am doing wrong?

uri = f'point?crs=EPSG:25832&field=id:integer&index=yes'
l_out = QgsVectorLayer(uri, 'new layer', 'memory')

x, y = 369000, 5616000
with edit(l_out):
    for i in range(10):
        f = QgsFeature(l_out.fields())
        g = QgsGeometry(QgsPoint(x, y))
        f.setGeometry(g)
        f.setAttributes([i])
        l_out.addFeature(f)
        x += 50
        y += 50

project = QgsProject.instance()
project.addMapLayer(l_out)

tree = project.layerTreeRoot()
group0 = tree.insertGroup(0, 'level 0')
group1 = group0.addGroup('level 1')

lcopy = project.addMapLayer(l_out.clone(), False)
nodecopy = group1.insertLayer(-1, lcopy)
edited tags
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
Loading
Source Link
Redoute
  • 2.2k
  • 2
  • 16
  • 23
Loading