So I created columns for latitude and longitude for a point layer in QGIS using the expressions $y and $x in the field calculator respectively. However whenever I add a new point feature the latitude and longitude have null values. Does anyone know what I am doing incorrectly?
Asked
Active
Viewed 171 times
2 Answers
2
You can set a default value for your Latitude and Longitude fields under the Attributes Form tab of the Layer Properties dialog.
Use $y and $x as default values and check Apply default value on update:
Now the values in the Latitude and Longitude fields will auto populate and update when you add or move a point feature.
Ben W
- 21,426
- 3
- 15
- 39
1
They fields are not continuously updated as dynamic attributes. You will need to run the calculation again to get an update, including for new features.
alphabetasoup
- 8,718
- 4
- 38
- 78
-
So I will have to the field of calculator each time to update all of the new rows with NULL values? – Ian Moffit Apr 21 '23 at 00:46
-
1Yes, but it should be noted that given you can calculate these as simple $x and $y expressions from the geometry, why are you writing these into columns at all when you already have the geometry? – alphabetasoup Apr 21 '23 at 01:19
