I'm writing a script in pyQGIS, which would emulate measurement of a line by "walking" along it with a compass with constant length. I have a problem with the Clip algorythm from processing module, namely it returns None, regardless of whether I add layers as inputs or selected features. What do I do wrong? I believe, that should the clip result in an empty layer, it would still be there, just empty? Below is the piece of code with problems,
while d.measureLine(QgsPoint(coorFin,coorFin),QgsPoint(coor,coor))>step: # If the distance between current and last point is more than chosen step # Create buffer polygon around a point bufCirc = point.geometry().buffer(step,10) # do a buffer from existing point buforek = QgsFeature() buforek.setGeometry(bufCirc) # Create layer and put the polygon inside bufferLayer = QgsVectorLayer("Polygon", "temporary_polygons", "memory") pz = bufferLayer.dataProvider() bufferLayer.setCrs(my_crs) pz.addFeatures([buforek]) bufferLayer.commitChanges() # select the buffer buforSel = bufferLayer.setSelectedFeatures([buforek]) # Clip coastline with the buffer liniaWarstwa = processing.runandload("qgis:clip", selectedCoastLine, buforSel, "memory:liniaWarstwa") print liniaWarstwa layer = QgsMapLayerRegistry.instance().mapLayersByName("memory:liniaWarstwa")
The print prints "none", QgsMapLayerRegistry says "index out of range".