I want to calculate centroid coordinates X_center and Y_center for every polygon in layer so that in case polygon has not simple shape (e.g. with holes or like in the picture below) centroid will be in the polygon anyway:

enter image description here

I found 'point on surface' function in QGIS, that returns a point guaranteed to lie on the surface of a geometry. BUT When trying to calculate coordinates with the function, dump happens, although qgis shows output preview correctly -

enter image description here

I found similar question but the following answer implicates new point layer creation, that is useless for me - I want to get centroid coordinates in the same layer.

Interesting, when creating virtual field - it calculates, I can even pick the polygon and see coordinates, but when opening attribute table, qgis crushes.

enter image description here

What is wrong?

  • Which QGIS version and platform are you using? Does it crash when you finish entering the expression or when you click OK in the Field Calculator?
    – Joseph
    Commented Oct 6, 2017 at 12:42
  • QGIS 2.18.12, dump crashes when I clicking OK in the Field Calculator
    – Jane
    Commented Oct 6, 2017 at 12:43
  • Does it still crash if you create a virtual field or changing the field type (you can always copy over the values to a new real field)?
    – Joseph
    Commented Oct 6, 2017 at 12:54
  • Interesing, it calculates, but when opening attribute table, it crashes!
    – Jane
    Commented Oct 6, 2017 at 13:03
  • I've added some info in my question about virtual field
    – Jane
    Commented Oct 6, 2017 at 13:09

2 Answers 2


Sounds like something in your geometry is causing the issue. I'd check your geometry validity, and also open a bug report for qgis and attach your original dataset.


I had a similarly doubt, but I used Python to store the centroid in a new shapefile. See my question. I think it will help you:

Saving centroid with attribute fields in PyQGIS?

Your Answer

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

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