[Qgis-psc] [QGIS-Developer] PyQGIS: add feature (+defaults/expressions), with Form

Richard Duivenvoorde rdmailings at duif.net
Tue Nov 24 00:29:28 PST 2020


Forwarding from dev list thread:

On 11/23/20 6:47 PM, C Hamilton wrote:
> So why is there a separate way to create features? Should these be cross referenced in the documentation as to why one method should be used vs. the other? This solves the openFeatureForm problem. Perhaps the documentation should also mention that if you use openFeatureForm then you need to use QgsVectorLayerUtils.createFeature(...).

Agreed, QGIS code (and available API) becoming bigger and bigger, it would be nice to have this kind of docs/cross references in cpp/python code (api docs).

Documentation for core classes like QgsFeature would greatly benefit for an overview/introduction, like:
- what is the purpose (and why does it excist)
- how to be used (and NOT)
- relations with other core classes
- etc

In the case of the original post:

We have (just like the Qt docs) a nice 'More...' link in the cpp docs header:

https://qgis.org/api/classQgsFeature.html
https://qgis.org/pyqgis/master/core/QgsFeature.html

But that does not show 'More' :-)

But maybe we should create a QhackFest (or what is it called now), and together with some QGIS veterans and core devs and some native English speakers, and try to describe/write some docs for the core objects of QGIS code? 
We need the veterans to dig ut WHY certain classes were created.
We need the core devs because they have current overview.
We need english speakers/writers because code docs are/should be so important.

November is already full? What about December?

What about a write up for:
- QgsMapCanvas
- QgsFeature and QgsGeometry
- QgsMapLayer
To start with?


I can add something now like:

"
A 'Feature' is an object modelling a Real World Phenomenon in Vector-based GIS systems. 
A Feature mostly have both geometric (geometry) and non geometric properties (attributes).

The QgsFeature class encapsulates a single feature including its id, geometry and a list of field/values attributes (see QgsFields and QgsAttributes (links!)

Constructing QgsFeature's can be done using one of the QgsFeature constructors.

But if you want to create a QgsFeature which respects the 'default values' or 'expression values' defined in the QgsVectorLayer for this feature, it is better to use the utility class:
QgsVectorLayerUtils.createFeature(layer, geom, {}, layer.createExpressionContext() )

etc etc
"


https://qgis.org/api/classQgsVectorLayerUtils.html itself is also pretty short...

What about:
"
QgsVectorLayerUtils is a class which handles the connection between QgsVectorLayers and QgsFeatures. Taking things into account like: "creating features of feature attributes which respect rules or default values defined for this layer".

etc etc
"

But instead of me adding some lines of text, I think a (social) group effort would be better...
Volunteers?

Regards,

Richard Duivenvoorde







More information about the Qgis-psc mailing list