PyQGIS:从新图层中删除过滤器

问题描述

我目前正在编写一些代码,用于从另一层的选定特征创建一个新层。

layer_4 = QgsProject.instance().mapLayersByName('layer_1')[0]
iface.setActiveLayer(layer_4)
layer_2 = iface.activeLayer()
selected_2 = layer_4.selectedFeatures()
crs_2 = QgsProject.instance().crs().authid()
selection = QgsvectorLayer("Point?crs=" + str(crs_2),"selection","memory")
new_features_2 = []

for feat in selected_2:
    new_features_2.append(feat)

selection.dataProvider().addFeatures(new_features_2)
QgsProject.instance().addMapLayer(selection)

这似乎有效,但是点没有显示在新图层中,当我检查属性表时,它说所有元素都被过滤了。 为什么?以及如何移除过滤器?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)