4

I am starting to learn PyQGIS and following tutorials online. However, I have QGIS 3.0 and most of the tutorials use QGIS version 2. I am trying to do a buffer on a point shapefile, but only have the code for Qgis 2. I have looked at the backwards incompatible changes (https://qgis.org/api/api_break.html) but cannot work out how to adjust the code. The 'GeometryAnalyzer' class, which contained the buffer function in Qgis 2 no longer exists, so I am not sure where to find it now. I am sure there is a simple solution..

The code for Qgis 2 as far as I know is as follows:

from qgis.analysis import QgsGeometryAnalzer
layer = iface.activeLayer()
QgsGeometryAnalyzer().buffer(layer, 'OutputFilePath/FileName.shp', 0.5, False, False, -1)

How can this be adjusted to Qgis 3?

Simba06
  • 841
  • 1
  • 8
  • 20

1 Answers1

6

The API changes page says:

QgsGeometryAnalyzer. Use the equivalent Processing algorithms instead.

processing.algorithmHelp("native:buffer") gives

processing.run('native:buffer', {"INPUT": lineLayer, "DISTANCE": 5, "OUTPUT": resultLayer})
Ian Turton
  • 81,417
  • 6
  • 84
  • 185
  • 1
    Also worth checking out: https://gis.stackexchange.com/questions/279874/using-qgis3-processing-algorithms-from-standalone-pyqgis-scripts-outside-of-gui/279937#279937 – HeikkiVesanto May 31 '18 at 10:26