QGIS – Setting Default Value for Attributes in Shapefiles

default valueqgisshapefile

In QGIS 2.14.6 I would like to define a default value for an attribute in a shapefile (or spatialite layer as well) which is applied if the user doesn't explicitely sets the value.

Is there a way to achieve this using standard tools/setting (without python)?

Best Answer

QGIS 3

Select the layer in the layer panel and left-click. Select properties. Select the "Attributes Form" as shown below. Select the fields from the "Available Widgets" list as show. Provide an expression for the default value in the "Defaults" dialog. If the "Apply default value on update" is checked, the value will be adjusted every time the feature's geometry or another attribute is changed. This makes things like a "last_modified" timestamp or an updated "area" possible.

Set Field Default Value QGIS 3.0.3


QGIS 2.18

Starting from QGIS 2.18 this is possible without any extra tools.

Just go to the field properties click on the button in the field you would like to assign a default value and enter an expression. It can also take the geometry as input.

enter image description here

Sidenote: I know that the original question targets QGIS 2.14, but I think this is still of interest to future readers of this question.

Related Question