I'm trying to use the gdal:proximity function from pyQGIS algorithms.

below is my code for trying to run the algorithms:

def publicgreen_qgis(self, in_fn):
        params = {'INPUT':in_fn,
       'EXTENT':'2667.53800002985,56396.4399999964,15748.72099999,50256.3342999838 [EPSG:3414]','NODATA':0,

        feedback = QgsProcessingFeedback()

        res = processing.run("gdal:rasterize", params, feedback=feedback)

        params = {'INPUT':res['OUTPUT'],'BAND':1,

        res2 = processing.run("gdal:proximity", params, feedback=feedback)

Have tried running on QGIS python plugin with 'OUTPUT':'TEMPORARY_OUTPUT' but still doesn't output anything.

The code runs without error in my application, however, the output file I want is not created.

EDIT1: running from QGIS python plugin works, was not paying attention to my folder, however, still no output from the application.

EDIT2: have tried changing directories, running without GUI, only gdal:rasterized would give me an output, gdal:proximity still not giving me any output. Not sure how to check if the process is running as well. Program just runs without giving me an output or exception.

EDIT3: Getting results from processing.run GRASS r.resample in PyQGIS seems to have the same problem.


The problem was because I didn't add Python37/Script to PYTHONPATH environment (C:\OSGeo4W64\apps\Python37\Scripts) for most people.

Not too sure why rasterize works while proximity don't.


Here is my results with UI and standalone script (perhaps something wrong with your input parameters):

enter image description here

import os
import sys
import qgis.core

OSGeo_folder = r'C:\OSGeo4W64'

qgis.core.QgsApplication.setPrefixPath(os.path.join(OSGeo_folder, r'apps\qgis'), True)
qgs = qgis.core.QgsApplication([], False)
sys.path.append(os.path.join(OSGeo_folder, r'apps\qgis\python\plugins'))
import processing

params = {'INPUT': r'C:\DELETE\GIS SE 3\test_UTM_42N.shp',
          'BURN': 1,
          'UNITS': 1,
          'WIDTH': 50,
          'HEIGHT': 50,
          'EXTENT': '501106.039172488,502781.3902660671,6760036.967377309,6763673.388672297 [EPSG:32642]',
          'NODATA': 0,
          'DATA_TYPE': 0,
          'INVERT': False,
          'OUTPUT': r'C:\DELETE\GIS SE 3\raster_StandAlone.tif'}

feedback = qgis.core.QgsProcessingFeedback()

res = processing.run("gdal:rasterize", params, feedback=feedback)
  • my rasterize process works fine but proximity doesn't, can't seem to find the problem though. My input parameters should be correct since it works in the python plug-in in qgis application. Thanks for the reply though! – Sean Ang May 8 '20 at 8:58
  • @SeanAng Please, edit the question topic "Using QGIS 3.12 gdal:rasterize doesn't output raster file in output location in PyQGIS standalone application". – Comrade Che May 8 '20 at 9:00

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.