[Qgis-user] Features geometry/attributes inconsistency ?
Jésahel Benoist
djes1975 at gmail.com
Wed May 13 02:18:33 PDT 2020
Hi,
I'm working with a lot of layers and need to copy/paste features with
attributes from source layers to destination layers, within a rectangle.
I'm using the "multiple selection by rectangle" plugin by Felipe Ferrari
and Luiz Andrade to make a selection on all my layers and looked for a
script but do not find something simple and easy.
So I've rapidly coded this :
---
def selectedFeaturesCopy(sourceLayerName, destLayerName):
sourceLYR = QgsProject.instance().mapLayersByName(sourceLayerName)[0]
destLYR = QgsProject.instance().mapLayersByName(destLayerName)[0]
destLYR.startEditing()
data_provider = destLYR.dataProvider()
data_provider.addFeatures(sourceLYR.getSelectedFeatures())
destLYR.commitChanges()
selectedFeaturesCopy('source layer', 'destination layer')
---
Badly, I see that, as I rode elsewhere, it only copies geometry, not
attributes. I'll have to parse every feature to add the attributes.
So far I understand that features are only geometries. Why is it called
features then ?
More than that, when I look at the QGIS code, I see that some functions
dedicated to features do work with attributes too ?! Isn't it inconsistent ?
Wouldn't it be more efficient that some methods, like addFeature(), have at
least a flag to add attributes too ? In the addFeature() code (
https://qgis.org/api/qgsvectorlayer_8cpp_source.html#l00993), the flag
seems unused.
Regards,
Jésahel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20200513/1145e70b/attachment.html>
More information about the Qgis-user
mailing list