23.8. استخدام المعالجة من سطر الأوامر

يأتي QGIS مع أداة اسمها QGIS Processing Executor تتيح لك تشغيل خوارزميات المعالجة ونماذجها (المدمجة أو التي توفرها الإضافات) مباشرة من سطر الأوامر دون تشغيل QGIS Desktop نفسه.

من أداة سطر الأوامر، شغّل qgis_process وستحصل على:

QGIS Processing Executor - 3.35.0-Master 'Master' (3.35.0-Master)
Usage: C:\OSGeo4W\apps\qgis-dev\bin\qgis_process.exe [--help] [--version] [--json] [--verbose] [--no-python] [--skip-loading-plugins] [command] [algorithm id, path to model file, or path to Python script] [parameters]

Options:

  --help or -h            Output the help
  --version or -v         Output all versions related to QGIS Process
  --json                  Output results as JSON objects
  --verbose               Output verbose logs
  --no-python             Disable Python support (results in faster startup)
  --skip-loading-plugins  Avoid loading enabled plugins (results in faster startup)

Available commands:

  plugins            list available and active plugins
  plugins enable     enables an installed plugin. The plugin name must be specified, e.g. "plugins enable cartography_tools"
  plugins disable    disables an installed plugin. The plugin name must be specified, e.g. "plugins disable cartography_tools"
  list               list all available processing algorithms
  help               show help for an algorithm. The algorithm id or a path to a model file must be specified.
  run                runs an algorithm. The algorithm id or a path to a model file and parameter values must be specified.
                     Parameter values are specified after -- with PARAMETER=VALUE syntax.
                     Ordered list values for a parameter can be created by specifying the parameter multiple times,
                     e.g. --LAYERS=layer1.shp --LAYERS=layer2.shp
                     Alternatively, a '-' character in place of the parameters argument indicates that the parameters should be read from STDIN as a JSON object.
                     The JSON should be structured as a map containing at least the "inputs" key specifying a map of input parameter values.
                     This implies the --json option for output as a JSON object.
                     If required, the ellipsoid to use for distance and area calculations can be specified via the "--ELLIPSOID=name" argument.
                     If required, an existing QGIS project to use during the algorithm execution can be specified via the "--PROJECT_PATH=path" argument.
                     When passing parameters as a JSON object from STDIN, these extra arguments can be provided as an "ellipsoid" and a "project_path" key respectively.

ملاحظة

لا تتعرّف أداة qgis_process إلا على الإضافات المثبّتة التي تعلن hasProcessingProvider=yes في ملفها metadata.txt، ولا يمكنها تفعيل أو تحميل سواها.

تلميح

قبل استدعاء qgis_process على نظام بلا مدير نوافذ (مثل خادم بلا واجهة)، عليك ضبط:

export QT_QPA_PLATFORM=offscreen

يمكن استخدام الأمر list للحصول على قائمة بجميع المزوّدين والخوارزميات المتاحة.

qgis_process list

يمكن استخدام الأمر help للحصول على مزيد من المعلومات عن الأوامر أو الخوارزميات.

qgis_process help qgis:regularpoints

يمكن استخدام الأمر run لتشغيل خوارزمية أو نموذج. حدّد اسم الخوارزمية أو مسار النموذج كمعامل أول.

qgis_process run native:buffer -- INPUT=source.shp DISTANCE=2 OUTPUT=buffered.shp

عندما يقبل معامل قائمة قيم، اضبط المتغير نفسه عدة مرات.

qgis_process run native:mergevectorlayers -- LAYERS=input1.shp LAYERS=input2.shp OUTPUT=merged.shp

أثناء تشغيل خوارزمية يُعرض شريط تقدم نصي، ويمكن إلغاء العملية بالضغط على CTRL+C.

يدعم الأمر run أيضًا معاملات إضافية.

  • --json ينسّق مخرجات stdout بهيكلية JSON.

  • --ellipsoid يضبط الإهليلج على الإهليلج المحدد.

  • --distance_units يستخدم وحدات المسافة المحددة.

  • --area_units يستخدم وحدات المساحة المحددة.

  • --project_path يحمّل المشروع المحدد لتشغيل الخوارزمية.

تدعم qgis_process معاملات الإدخال المعقّدة، أي أنواع المعاملات التي تُحدَّد هي نفسها ككائن من نوع قاموس للخوارزميات. وللإشارة إلى أن المعاملات ستُحدَّد عبر stdin، يجب أن يتبع أمر qgis_process الصيغة التالية (مع - في النهاية بدلًا من قائمة الوسائط المعتادة).

qgis_process run algorithmId -

يجب أن يحتوي كائن JSON على المفتاح "inputs"، وهو خريطة بقيم معاملات الإدخال. مثلًا:

echo "{'inputs': {'INPUT': 'my_shape.shp', 'DISTANCE': 5}}" | qgis_process run native:buffer -

إضافة إلى ذلك، يمكن تضمين إعدادات إضافية مثل وحدات المسافة ووحدات المساحة والإهليلج ومسار المشروع في كائن JSON هذا:

{
 'ellipsoid': 'EPSG:7019',
 'distance_units': 'feet',
 'area_units': 'ha',
 'project_path': 'C:/temp/my_project.qgs'
 'inputs': {'DISTANCE': 5, 'SEGMENTS': 8 ... }
}

تحديد معاملات الإدخال عبر stdin يعني تلقائيًا استخدام تنسيق المخرجات JSON للنتائج.