Thank you Nyall! That solved the problem. I failed to see that in the C++ code for split features tool, but it was there.
The only small annoyance that I had was the need to convert the result of feature.attributes() into a dictionary. Once again, thanks! It solved a long-standing issue in the plugin. Alex But it for the clarification. A qua, 28/03/2018, 23:01, Nyall Dawson <[email protected]> escreveu: > On 28 March 2018 at 08:32, Alexandre Neto <[email protected]> wrote: > > My multipart split plugin (which I am porting to 3), It breaks multipart > > features and transforms each part in individual features, copying the > > attributes from the original feature. > > > > In the process, I need to be careful with the autoincrement primary keys. > > For PostGIS and Spatialite, asking for the providers pkattributesindex > works > > and I can do the following: > > > > new_attributes = feature.attributes() > > > > # When attribute is a Primary Key, replace by default value > > ### This is not working well with spatialite provider### > > for j in provider.pkAttributeIndexes(): > > if provider.defaultValue(j): > > new_attributes[j] = provider.defaultValue(j) > > else: > > new_attributes[j] = QVariant() > > > > But for geopackage the provider.pkAttributeIndexes() always returns an > empty > > list... > > > > The above code was copied a long time ago from the split features tools > in > > core. Looking at the code now, there is no longer that part where the > > provider's primary keys are searched, Nevertheless, the code works and > the > > split features tool leave the pkattributes NULL to be autogenerated. > Wasn't > > able to figure out where that is done now ... > > The canonical/correct 3.0 way to do this is to use > QgsVectorLayerUtils.createFeature > > That method should be used whenever you are creating a brand new > feature which is destined for a particular vector layer, and needs to > correctly respect constraints and default value clauses set on the > provider side. > > Nyall > -- Alexandre Neto --------------------- @AlexNetoGeo http://sigsemgrilhetas.wordpress.com http://gisunchained.wordpress.com
_______________________________________________ QGIS-Developer mailing list [email protected] List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
