简体   繁体   中英

How to run python script for QGIS from outside

I have hundred shape files in a folder. I have following tasks

  1. Find out what are the fields in each shapefile
  2. If there is no field 'City' in any of the shapefiles I have to add that field in those shapefile.

I can access each layer in python console in QGIS using iface.activeLayer()

But I want to run a stand alone python script which will perform the tasks. Can anyone help?

In my humble opinion, if you want to execute python scripts without the QGIS GUI, you could use the OGR Python API directly.

There's an entire "cookbook" here: https://pcjericks.github.io/py-gdalogr-cookbook/

The official API documentation is here: http://gdal.org/python/

Simple tutorial: http://www.gdal.org/ogr_apitut.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM