1

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.

2
  1. Open Field Calculator for your centroid layer
  2. Tick 'Update existing field'
  3. Select your 'x' field in the dropdown menu under this tickbox
  4. Enter the expression $x in the expression box and click 'OK'
  5. Repeat 2-4 for the y field
1

QGIS now has a centroids tool builtin.

Go to Vector > Geometry tools > Centroids

Vector > Geometry tools > Centroids

Select your input polygon layer, and output file, and Run

Created centroids on map

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

Export to CSV

Now viewing the attribute table gives the coordinates:

Centroid coordinates as WKT in exported CSV

0

Use Point on Surface, not use Centroid (irregular polygon).

  1. Create column "x" and "y" (data type decimal).
  2. Use the field calculator expression: x(point_on_surface($geometry)

Optional. In Form Editing (Qgis 3.X) you can use this expression value default when update the vector layer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.