QGIS 多准则分析 (MCP)

QGIS MCP
分类General
作者Community
星标454
定价Free

简介

QGIS MCP 是一个将地理信息系统 QGIS 与 Claude AI 深度打通的桥梁。它打破了传统 GIS 操作依赖繁琐菜单和 Python 脚本的壁垒,让开发者和分析师能直接用自然语言驱动 QGIS。无论是快速加载图层、自动化项目创建,还是执行复杂的空间分析代码,你只需在对话框中下指令,AI 即可在桌面端同步执行。对于习惯于用代码处理地图但厌倦重复配置的用户来说,它极大地降低了 GIS 自动化门槛,将 AI 从简单的“代码生成器”变成了真正的“软件操作员”。

核心亮点

  • 自然语言驱动 QGIS,无需手动翻找功能菜单
  • 支持 AI 直接加载图层并快速构建地理项目
  • 实现 Prompt 直接执行空间分析代码,提升效率
  • 连接 LLM 与桌面端,将 AI 能力转化为实际操作

完整文档

QGISMCP - QGIS Model Context Protocol 集成

QGISMCP 通过 Model Context Protocol (MCP)QGIS 连接到 Claude AI,允许 Claude 直接与 QGIS 交互并控制它。此集成实现了由提示词辅助的项目创建、图层加载、代码执行等功能。

本项目在很大程度上基于 Siddharth AhujaBlenderMCP 项目。

功能特性

  • 双向通信:通过基于 socket 的服务器将 Claude AI 连接到 QGIS。
  • 项目操作:在 QGIS 中创建、加载和保存项目。
  • 图层操作:向项目中添加或删除矢量或栅格图层。
  • 代码执行:从 Claude 在 QGIS 中运行任意 Python 代码。功能非常强大,但使用此工具时请务必谨慎。

组件

系统由两个主要组件组成:

1. QGIS plugin:一个 QGIS 插件,在 QGIS 内部创建 socket 服务器以接收并执行命令。
2. MCP Server:一个实现了 Model Context Protocol 并连接到 QGIS 插件的 Python 服务器。

安装

前置条件- QGIS 3.X (仅在 3.22 上测试)

  • Claude desktop
  • Python 3.10 或更高版本
  • uv 包管理器:

如果你使用的是 Mac,请通过以下方式安装 uv:

bash
brew install uv
在 Windows PowerShell 上
bash
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
否则,安装指南请参阅其官网:Install uv

⚠️ 在安装 UV 之前请勿继续

下载代码

将此 repo 下载到你的电脑。你可以使用以下命令 clone:

bash
git clone [email protected]:jjsantos01/qgis_mcp.git
### QGIS 插件

你需要将 qgis_mcp_plugin 文件夹及其内容复制到你的 QGIS profile plugins 文件夹中。

你可以在 QGIS 中通过菜单 Settings -> User profiles -> Open active profile folder 找到你的 profile 文件夹。然后,进入 Python/plugins 并粘贴 qgis_mcp_plugin 文件夹。

> 在 Windows 机器上,plugins 文件夹通常位于:C:\Users\USER\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins

在 MacOS 上位于:~/Library/Application\ Support/QGIS/QGIS3/profiles/default/python/plugins

然后关闭 QGIS 并重新打开。进入菜单选项 Plugins > Installing and Managing Plugins,选择 All 选项卡并搜索 "QGIS MCP",然后勾选 QGIS MCP 复选框。

Claude for Desktop 集成

前往 Claude > Settings > Developer > Edit Config > claude_desktop_config.json 并添加以下内容:

> 如果你找不到 "Developers 选项卡" 或 claude_desktop_config.json,请参阅此 文档

json
{
"mcpServers": {
"qgis": {
"command": "uv",
"args": [
"--directory",
"/ABSOLUTE/PATH/TO/PARENT/REPO/FOLDER/qgis_mcp/src/qgis_mcp",
"run",
"qgis_mcp_server.py"
]
}

}
}

## 使用方法

启动连接

1. 在 QGIS 中,前往 plugins > QGIS MCP > QGIS MCP
!plugins menu
2. 点击 "Start Server"
!start server

在 Claude 中使用

一旦在 Claude 中设置好配置文件且 QGIS 上的 server 正在运行,你将看到一个带有 QGIS MCP 工具的锤子图标。

!Claude tools

#### 工具

  • ping - 简单的 ping 命令,用于检查 server 连接性
  • get_qgis_info - 获取当前安装的 QGIS 信息
  • load_project - 从指定路径加载 QGIS 项目
  • create_new_project - 创建新项目并保存
  • get_project_info - 获取当前项目信息
  • add_vector_layer - 向项目添加矢量图层
  • add_raster_layer - 向项目添加栅格图层
  • get_layers - 获取当前项目中的所有图层
  • remove_layer - 通过 ID 从项目中移除图层
  • zoom_to_layer - 缩放到指定图层的范围
  • get_layer_features - 从矢量图层检索要素(可选限制数量)
  • execute_processing - 使用给定参数执行处理算法
  • save_project - 将当前项目保存到给定路径
  • render_map - 将当前地图视图渲染为图像文件
  • execute_code - 执行以字符串形式提供的任意 PyQGIS 代码

示例命令这是我在 demo 中使用的示例:
plain
You have access to the tools to work with QGIS. You will do the following:

1. Ping to check the connection. If it works, continue with the following steps. 2. Create a new project and save it at: "C:/Users/USER/GitHub/qgis_mcp/data/cdmx.qgz" 3. Load the vector layer: ""C:/Users/USER/GitHub/qgis_mcp/data/cdmx/mgpc_2019.shp" and name it "Colonias". 4. Load the raster layer: "C:/Users/USER/GitHub/qgis_mcp/data/09014.tif" and name it "BJ" 5. Zoom to the "BJ" layer. 6. Execute the centroid algorithm on the "Colonias" layer. Skip the geometry check. Save the output to "colonias_centroids.geojson". 7. Execute code to create a choropleth map using the "POB2010" field in the "Colonias" layer. Use the quantile classification method with 5 classes and the Spectral color ramp. 8. Render the map to "C:/Users/USER/GitHub/qgis_mcp/data/cdmx.png" 9. Save the project.
查看官方来源