Real Centroids V0.1

Installation

Unzip the downloaded realcentroids.zip into your plugins directory, e.g. ~/.qgis2/python/plugins/.

Usage

Enable the plugin in the Plugins/Manage and Install Plugins ... dialog. Open the polygon layer you want to create centroids. Start the plugin clicking on the icon in the plugins toolbar or select it from the plugins menu. The following dialog appears


In the Polygon layer list you can select one from the loaded polygon layers. Select a new shapefile clicking on the Browse button. If you select an existing shapefile, you get a warning about weather to overwrite that shape. If you check Add to map canvas the point shape with the centroids is added to the current project. Not only the geometry but the attributes are also copied to the target point shape file.

Why do we need such plugin? There is a Polygon centroids option in the Vector/Geometry Tools menu. Polygon centroids will create centroids at the weight point of the vertexes of the polygon. So it can be outside the polygon in a concave case. Realcentroid will place the centroid always inside the polygon. See figures below to compare the results of the two methods.


Centroids (weight points) created by Vector/Geometry Tools/Polygon centroids


Centroids generated by RealCentroids plugin

Algorithm used

For each polygons the weight point is generated first. If it is outside the weight point of tree neighboring vertexes are generated until the weight point is inside the polygon. Se the figure below.


Inner point generation steps

The side effect of this algorithm is that the centroid is often very near to the polygon border.