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?

1 Answer 1

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:

1
  • this works! thank you.
    – sutan
    Commented Mar 25, 2022 at 11:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.