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"'})
1
  • 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. Commented Feb 27, 2019 at 10:56

1 Answer 1

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 and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.