Thursday, 9 July 2015

qgis - How to set a default value for attributes in shapefiles?


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)?



Answer




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





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.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...