1
  • Given that I have 1 shapefiles for instance c:/users/user/line.shp

  • and I have activated my QGIS Console in Anaconda prompt

(base) $ conda activate qgis-venv
(qgis-venv) $ python

>>> import qgis >>> #????

  • How should I put command in the console to execute buffer of 500?
Lilium
  • 1,057
  • 1
  • 6
  • 17
sutan
  • 931
  • 1
  • 9
  • 22

1 Answers1

3

You can try this :

import sys
from qgis.core import (
     QgsApplication, 
     QgsProcessingFeedback, 
     QgsVectorLayer
)

See https://gis.stackexchange.com/a/155852/4972 for details about the prefix

QgsApplication.setPrefixPath('/usr', True) qgs = QgsApplication([], False) qgs.initQgis()

Append the path where processing plugin can be found

sys.path.append('/docs/dev/qgis/build/output/python/plugins')

import processing from processing.core.Processing import Processing Processing.initialize()

vlayer = QgsVectorLayer('P:/Test/qgis_test/poly_test.shp', "poly_test", "ogr")

parameter_dictionary = { 'INPUT' : vlayer, 'DISTANCE' : 500, 'SEGMENTS' : 25, 'END_CAP_STYLE' : 0, 'JOIN_STYLE' : 1, 'MITER_LIMIT' : 10, 'DISSOLVE' : False, 'OUTPUT' : 'memory:' }

buffer_result = processing.run("native:buffer", parameter_dictionary)

output = buffer_result['OUTPUT']

Also do not forget to check the QGIS Documentation


References:

Taras
  • 32,823
  • 4
  • 66
  • 137