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.

TomazicM
  • 25,601
  • 22
  • 29
  • 39
dror
  • 21
  • 1
  • Have you checked the answers here: https://gis.stackexchange.com/questions/45243/how-to-determine-the-centroid-of-polygons?rq=1? – ahmadhanb Sep 02 '19 at 14:00

3 Answers3

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
David
  • 651
  • 3
  • 8
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

nmtoken
  • 13,355
  • 5
  • 38
  • 87
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.