1

I want to iterate a buffer from a list of distances I have, but I can´t find the way to do it. I´m a beginner on Python.

import processing
x=[100, 200, 300, 400, 500]
processing.run("native:buffer",\
{'INPUT':'C:/Path/points.shp',\
'DISTANCE':x,\
'SEGMENTS':5,\
'END_CAP_STYLE':0,\
'JOIN_STYLE':0,\
'MITER_LIMIT':2,\
'DISSOLVE':False,\
'OUTPUT':'"C:/Path/Buffer" + str(x) +".shp"'})
  • You want to run the processing.run() for each of the values in your list x (bad name!). This should help you Google. If not, it is suitable as a Python question at stackexchange.com. – bugmenot123 Feb 27 at 10:56
3

You need a loop:

import processing
for x in [100, 200, 300, 400, 500]:
    processing.run("native:buffer",\
      {'INPUT':'C:/Path/points.shp',\
       'DISTANCE':x,\
       'SEGMENTS':5,\
       'END_CAP_STYLE':0,\
       'JOIN_STYLE':0,\
       'MITER_LIMIT':2,\
       'DISSOLVE':False,\
       'OUTPUT':'"C:/Path/Buffer" + str(x) +".shp"'})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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