重要
翻訳は あなたが参加できる コミュニティの取り組みです。このページは現在 100.00% 翻訳されています。
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.
注釈
インストールされたプラグインのうち、 metadata.txt ファイルに hasProcessingProvider=yes と記述されているものだけが認識され、qgis_process ツールで起動または読み込まれます。
ヒント
ウィンドウマネージャのないシステム(例 ヘッドレスサーバ)で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 になります。