0

How do I run gdal_proximity.py from the QGIS python console?

2

With the Python processing module (look at Using processing algorithms from the console)

1) look at the Processing Toolbox, there is a proximity command [GDAL] Analysis/proximity:

enter image description here

2) in the Python console

>>> import processing
>>> # list of algorithms (a lot ...)
>>> processing.alglist()
.....
pct2rgb---------------------------------------------->gdalogr:pct2rgb
proximity-------------------------------------------->gdalogr:proximity
rgb2pct---------------------------------------------->gdalogr:rgb2pct
......
>>> processing.alglist('proximity')
Grid proximity buffer-------------------------------->saga:gridproximitybuffer
Proximity grid--------------------------------------->saga:proximitygrid
proximity-------------------------------------------->gdalogr:proximity

and

>>> # help for the parameters of the proximity algorithm
>>> processing.alghelp("gdalogr:proximity")
ALGORITHM: proximity
src_filename <ParameterRaster>
values <ParameterString>
maxdist <ParameterNumber>
nodata <ParameterNumber>
distunits <ParameterSelection>
fixed_buf_val <ParameterNumber>
dst_filename <OutputRaster>
  distunits(distunits)
0 -  GEO
1 - PIXEL

So you use:

>>> processing.runalg("gdalogr:proximity","your_src_filename",yourvalues,yourmaxdist,yournodata,"GEO",yourfixed_buf_val,"yourdst_filename")
| improve this answer | |
  • alglist() works okay, but when I try to run listalgs(), I get "AttributeError: 'module' object has no attribute 'listalgs'"... – user1521655 Jan 7 '14 at 15:27

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.