14

In QGIS I would like to update two columns with the centroid easting and northing of my polygons. I am using the field calculator. I have tried using $x and $y but this only seems to work for points.

I have checked the help but it does not seem to mention being able to do this.

2
  • hmm doesn't seem possible at the moment. Shouldn't be too hard to add in.
    – Nathan W
    Jul 1, 2011 at 9:22
  • Any easy thing should be adding centroids to the columns added by "Export geometry columns"
    – underdark
    Jul 1, 2011 at 10:44

3 Answers 3

21

Not sure if it worked 5 years ago, but now the solution looks like this:

x(centroid($geometry))

and

y(centroid($geometry))

Results are the same as while using the "Join" option mentioned above:

polygons' centroids m

15

A fast way (without field calculator) would be to

  1. create a centroid layer: Vector - Geometry Tools - Polygon Centroids
  2. join the centroid layer to the polygon layer: (Polygon) Layer Properties - Join tab
1
  • 1
    Thanks for the answer. I had figured out I could do it this way, I just wondered if there was a way to do it through field calculator like for points.
    – James S
    Jul 1, 2011 at 10:37
0

If you would consider doing it in workaround method here's how I did it:

Export your polygon as MapInfo file

Calculate centroids with Vector > Geometry Tools > Polygon Centroids

Export centroids as MapInfo File

Remove all unneeded info from Centroid MIF file, leave just coordinates

In your polygon MIF file add information that you have 2 more columns (x and y/lat and long) don't forget to update column count information.

In your polygon MID file copy all columns from centroid MIF file (excel will help here)

There might be a shorter/direct way to do this, but maybe my answer will help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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