# Buffering polygon until it hits neighbor using PyQGIS?

I have a shapefile made up of a number of polygons. Neighboring polygons often share an attribute.

What I need to do is buffer these polygons based on the common attribute. However, I would like to expand said buffers until they meet, at which point they can stop.

I have a hastily put together mock-up:

All I have code-wise is the following:

from qgis.core import *
from qgis.analysis import *

layer=qgis.utils.iface.activeLayer()

QgsGeometryAnalyzer().dissolve(layer, "D:/test_dissolved.shp", onlySelectedFeatures=False, uniqueIdField=3, p=None)


Truthfully I am not very well versed in the QGIS API documentation and despite my best efforts I cannot find a suitable method for this. QgsGeometryAnalyzer().dissolve allows me to dissolve the buffer but that isn't what I am after.

Should I perhaps be looking in another direction here?

Something you could try is a thiessen process where you voronoi the polygons then dissolve by similar attributes. I don't know what this would be in python but maybe the steps are useful to you.

• I am going to have a go at figuring out the Voronoi route using pyQGIS and see where it takes me. I prefer the idea of using an open source solution. – Ingwe Apr 24 '17 at 6:03
• What do you mean by open source? QGIS and all its tools come under the free open source licence. – Knightshound Apr 26 '17 at 6:38

You probably want to explore raster analysis functions. See Creating centreline for every polygon in submarine canyon database using ArcGIS for Desktop Basic? and Creating Thiessen (Voronoi) polygons using lines (rather than points) as the input features? for further inspiration.

This requires you to use a suitable raster resolution of course.

• I like this idea of converting to a raster and it had occurred to me but would a large dataset not result in a very slow processing time? – Ingwe Apr 24 '17 at 6:02
• Maybe not slower than doing the same iteratively with vectors. – bugmenot123 Apr 24 '17 at 8:13

I had a slightly related task the other day. In theorie, voronoi polygons with (weighted) building centrepoints should just be the solution for your case but it didn't work for me; PostgreSQL is not what you asked for, but, as a workaround, if it's the 'centreline' between each building you're after for the first step, using PostGIS ST_ApproximateMedialAxis could be worth a try. You'd have to create a base polygon for the whole study area and cut out the building polygons prior to apply the function on the base polygon to get related results. Could work, might not...