# How to split a circle in equal parts in QGIS?

I'm looking to split a circle polygon generated by a buffer around a point in equal parts. The goal is to be able to calculate statistics about the raster that will be under the circle for each part of the circle.

This post explains how to do it for a square polygon and this one how to do it with arcpy, but does anyone know how can I achieve a similar thing with a circle AND with QGIS ?

• I guess the most "simple" way would be to translate the script from your second link to PyQGIS. This requires a relatively good knowledge of PyQGIS though. – ArMoraer Mar 22 '16 at 15:58

It is very easy to do with Shapely. The secret is the union predicate which divides the lines in segments at each intersection.

The Polygon is converted to a LinearRing or LineString an the union is done.

``````from shapely.geometry import LineString, Polygon
# union of the line and the LinearRing of the Polygon
result = line.union(LineString(list(polygon.exterior.coords)))
``````

The result is a MultiLineString

Now we can use use the polygonize function

``````from shapely.ops import polygonize
for geom in polygonize(result):
.....
``````

Result

In PyQGIS the combine predicate is the equivalent of union, see Python: Union selected polygons in a layer)

``````ring = poly.asPolygon()[0]
linearRing = ring.asPolyline()
result = line.combine(linearRing)
``````

The result is the same MultiLineString but PyQGIS has no polygonize function. There is an algorithm in the Processing Toobox (qgis:polygonize) but it crashes with MultiLineStrings in my case. So I continue to use shapely.