6

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 Oct 6 '17 at 12:42
  • QGIS 2.18.12, dump crashes when I clicking OK in the Field Calculator – Jane Oct 6 '17 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 Oct 6 '17 at 12:54
  • Interesing, it calculates, but when opening attribute table, it crashes! – Jane Oct 6 '17 at 13:03
  • I've added some info in my question about virtual field – Jane Oct 6 '17 at 13:09
3

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.

1

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, privacy policy and cookie policy

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