I have a buffer layer (green polygon) which I want to split to two polygons whenever it crosses a barrier (blue line). I have been trying to use "splitGeometry" method, but I just can't get it to work. My code so far is this :
while ldbuffprovider.nextFeature(feat):
while barprovider.nextFeature(feat2):
if feat.geometry().intersects(feat2.geometry()):
intersection = feat.geometry().intersection(feat2.geometry())
result, newGeometries, topoTestPoints=feat.geometry().splitGeometry(intersection.asPolyline(),True)
Which returns 1 for result( error) and an empty list for newGeometries.
Any help is greatly appreciated.
Best Answer
You can use the
reshapeGeometry
function of theQgsGeometry
object for this, which cuts a polygon along its intersection with a line.The following will intersect the buffer polygons with the lines, and add the split polygon features to a memory layer (QGIS 2.0 syntax):