2

I have been using QGIS to analyses spatial data and I created polygon centroids with the vector geometry tools. Now for a report I have to explain how these centroids were created. I have not been able to find an algorithm or an explanation of how QGIS creates centroids, can anyone help?

1
  • You may be able to assume that they use a standard formula, such as can be seen at Wikipedia. (I'm not advocating using Wikipedia exclusively as a source of content for a report, but it's often a reasonable starting point.)
    – Erica
    Commented Jul 11, 2014 at 18:57

2 Answers 2

4

For general centroid creation, QGIS QgsGeometry functions wrap respective calls to the underlying GEOS library:

The pointOnSurface() function is new for QGIS 2.4 and allows a workaround for when GEOSGetCentroid returns a centroid that lies outside the polygon's surface, e.g. as with a 'C'-shaped geometry. Such a result can make the centroid actually appear on the surface of an adjacent polygon.

Note: GEOSPointOnSurface does not 'weight' the point to the center of the polygon's area.

You can see how the pointOnSurface() function is used to provide such a fix with this commit for symbology.

1
  • I am certainly going to be trying this pointOnSurface() function out, another thing I have been looking for. Commented Jul 16, 2014 at 13:00
1

Centroid computation in Qgis are based on the GEOS library. I can then refer you to the the documentation of GEOS itself (http://geos.osgeo.org/doxygen/classgeos_1_1algorithm_1_1Centroid.html) where you can find the basic principle for polygon centroid computation:

Based on the usual algorithm for calculating the centroid as a weighted sum of the centroids of a decomposition of the area into (possibly overlapping) triangles. The algorithm has been extended to handle holes and multi-polygons. See http://www.faqs.org/faqs/graphics/algorithms-faq/ for further details of the basic approach.

1
  • Very helpful both for answering my question, but also as resource. Commented Jul 16, 2014 at 13:01

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.