I'm using the intersection tool (processing toolbox) to intersect polygons. I have a huge number of small polygons to intersect and it needs so much time to do do that. Maybe it is caused by the great extent of the polygon shape. Is it possible to set a maximum distance which defines the max distance between polygons they will be intersected. I would like to put this option into a python script if it is possible.
I tried out your shapefile with next script, at the Python Console of QGIS, to produce a memory layer with all intersections (intersection of intersections; 57,401 features) of original shapefile (20,730 features).
import fiona from shapely.geometry import shape, LineString from shapely.ops import unary_union, polygonize import time c = fiona.open('/home/zeito/pyqgis_data/example/example_1.shp') collection =  start = time.time() print "wait..." for i,item in enumerate(c): geom = shape(item['geometry']) collection.append(geom) rings = [ LineString(pol.exterior.coords) for pol in collection ] union = unary_union(rings) new_intersections = [geom.wkt for geom in polygonize(union)] epsg = int(c.crs.values().split(':')) uri = "Polygon?crs=epsg:" + str(epsg) + "&field=id:integer""&index=yes" mem_layer = QgsVectorLayer(uri, 'polygon', 'memory') prov = mem_layer.dataProvider() for i,feat in enumerate(new_intersections): feat = QgsFeature() feat.setAttributes([i]) feat.setGeometry(QgsGeometry.fromWkt(new_intersections[i])) prov.addFeatures([feat]) QgsMapLayerRegistry.instance().addMapLayer(mem_layer) end = time.time() time_tot = end - start print "total time = %.4f s" % time_tot
At the first image, I selected one arbitrary feature in original shapefile:
At second image, where memory layer has a 50 % of transparency, it can be observed that this original feature has seven features in the new layer.