0

I am trying to create a single side distance buffer around a line on QGIS.

Here is the code I am writing but I don't get the expected result:

processing.runalg("qgis:fixeddistancebuffer","input.shp",0.5821,25,False,"output.shp",side=left)

Any idea?

enter image description here

1 Answer 1

3

You're using a fixed distance buffer when you should be using a single sided buffer. Please see usage examples below.

For QGIS 3:

x = processing.run("qgis:singlesidedbuffer", {'INPUT':'input.shp','DISTANCE':10,'SIDE':0,'SEGMENTS':8,'JOIN_STYLE':0,'MITER_LIMIT':2,'OUTPUT':'memory:'})

For QGIS 2.X, 5th parameter indicates side (0=right, 1=left):

x = processing.runalg("gdalogr:singlesidedbuffersandoffsetlinesforlines","input.shp",0,"geometry","10",1,False,None,False,"",None)

EDIT:
To add the resulting layer to the map, use the following command:

layer = iface.addVectorLayer(x['OUTPUT_LAYER'], "Single Buffer", "ogr")
7
  • Sure, see edited answer.
    – 15Step
    Commented Dec 25, 2018 at 17:12
  • Thank again, I think I am doing it wrong. Here is what I get when I run the code. FYI, the new shapefile (with the buffer) is not created. "processing.runalg("gdalogr:singlesidedbuffersandoffsetlinesforlines","input.shp",0,'geometry',10,1,False,None,False,None,"output.shp") {'OUTPUT_LAYER': 'output.shp'}" Commented Dec 25, 2018 at 17:46
  • I think you're mixing the two usage examples. Try to use only the second line I wrote, changing the parameters appropriately (you also need to first import processing in case you didn't already). The OUTPUT_LAYER part shouldn't be used in QGIS 2.
    – 15Step
    Commented Dec 25, 2018 at 18:16
  • Hi, So the code I wrote in my previous message i.e. {'OUTPUT_LAYER': 'output.shp'}" is actually something I get from the python consol after running the code : "processing.runalg("gdalogr:singlesidedbuffersandoffsetlinesforlines","input.shp",0,'geometry',10,1,False,None,False,"output.shp",None) Hence I guess there is another problem. Commented Dec 25, 2018 at 18:26
  • There is no problem. The layer, as you showed, is generated correctly. The return value is a Python dictonary. See edited below above how to access the layer. Hope that works
    – 15Step
    Commented Dec 26, 2018 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.