중요

번역은 여러분이 참여할 수 있는 커뮤니티 활동입니다. 이 페이지는 현재 100.00% 에서 번역되고 있습니다.

27.8. 명령 줄에서 공간 처리 알고리즘 사용

QGIS는 사용자가 QGIS 데스크탑 자체를 실행하지 않고서도 명령 줄에서 공간 처리 알고리즘과 (내장되어 있는 또는 플러그인이 제공하는) 모델을 직접 실행할 수 있는 QGIS Processing Executor 라는 도구를 제공합니다.

명령 줄에서 qgis_process 를 실행하면 다음과 같은 화면을 보게 될 것입니다:

QGIS Processing Executor - 3.27.0-Master 'Master' (3.27.0-Master)
Usage: C:\OSGeo4W\apps\qgis-dev\bin\qgis_process.exe [--help] [--version] [--json] [--verbose] [--no-python] [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)

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.

참고

qgis_process 도구는 설치된 플러그인 가운데 metadata.txt 파일에 hasProcessingProvider=yes 를 명시한 플러그인만 식별하고, 활성화시키거나 불러올 수 있습니다.

힌트

시스템 상에서 창 관리자(window manager)를 통하지 않고 (예: 헤드리스(headless) 서버) 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 는 예를 들어 스스로를 알고리즘 용 파라미터 목록(dictionary) 유형 객체로 지정하는 파라미터 유형 같은 복잡 입력 파라미터를 지원합니다. 복잡 파라미터가 표준입력(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 포맷으로 산출한다는 것을 의미합니다.