I have a few thousands of polygons, which I found the centroid for each one of them. Now I want to find the coordinates of each centroid. But for some reason the x and y columns are empty and I don't know how to fix it.
- Open Field Calculator for your centroid layer
- Tick 'Update existing field'
- Select your 'x' field in the dropdown menu under this tickbox
- Enter the expression
$xin the expression box and click 'OK'
- Repeat 2-4 for the y field
QGIS now has a centroids tool builtin.
Go to Vector > Geometry tools > Centroids
Select your input polygon layer, and output file, and Run
That gives you the centroids on the map, but the coordinates may be
hidden in the geometry column and not shown to you in the attributes table, so finally you may wish to...
Export as CSV
Now viewing the attribute table gives the coordinates:
Use Point on Surface, not use Centroid (irregular polygon).
- Create column "x" and "y" (data type decimal).
- Use the field calculator expression:
Optional. In Form Editing (Qgis 3.X) you can use this expression value default when update the vector layer.