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?

2 Answers 2

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:

0
-1
# YOU CAN ADJUST THIS with your file paths and country UTM import geopandas as gpd # Load the shapefile hospitals = gpd.read_file(r'C:\GIS\GIS_2024\GIS_Spartial_Analysis\ShapeFile\hSites.shp') # Reproject to UTM Zone 35S (EPSG:32735) hospitals_utm = hospitals.to_crs(epsg=32735) # Create a 5KM buffer hospitals_utm['geometry'] = hospitals_utm.buffer(5000) # 5000 meters # Save the output to a new shapefile output_path = r'C:\GIS\GIS_2024\GIS_Spartial_Analysis\Buffer_001\Buffer_5km.shp' hospitals_utm.to_file(output_path) 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.