QGISMCP-QGIS模型上下文协议集成(更新版本自https://github.com/jjsantos01/qgis_mcp)
QGISMCP连接 量子地理信息系统 向 克劳德 AI 通过模型上下文协议(MCP)允许Claude直接与QGIS交互并控制QGIS。这种集成支持快速辅助项目创建、层加载、代码执行等。
主要项目基于(https://github.com/jjsantos01/qgis_mcp).我只是在更新我发现的一些错误
特性
- 双向通信:通过基于套接字的服务器将Claude AI连接到QGIS。
- 项目操作:在QGIS中创建、加载和保存项目。
- 图层操作:在项目中添加和删除矢量或光栅图层。
- 执行处理:执行处理算法(处理工具箱).
- 代码执行:在Claude的QGIS中运行任意Python代码。非常强大,但使用此工具时也要非常谨慎。
组件
该系统由两个主要部分组成:
安装
先决条件
- QGIS 3.X(仅在3.22和3.34上测试)
- 云桌面
- Python 3.10或更新版本
- uv包管理器:
如果您使用的是Mac,请将uv安装为
brew install uv在Windows Powershell上
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"否则,安装说明在他们的网站上: 安装uv
⚠️ 安装UV之前不要继续
下载代码
将此仓库下载到您的计算机。您可以使用以下方式克隆它:
https://github.com/syauqi-uqi/qgis_mcp_modify1.gitQGIS插件
您需要复制文件夹 qgis_mcp_插件 以及QGIS配置文件插件文件夹中的内容。
你可以在QGIS的菜单中找到你的个人资料文件夹 Settings -> User profiles -> Open active profile folder 然后,转到 Python/plugins 并粘贴文件夹 qgis_mcp_plugin.
在Windows计算机上,插件文件夹通常位于: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桌面集成
首选 Claude > Settings > Developer > Edit Config > claude_desktop_config.json 包括以下内容:
如果你找不到“开发人员选项卡”或 claude_desktop_config.json 看看这个 文档.{
"mcpServers": {
"qgis": {
"command": "uv",
"args": [
"--directory",
"#change this line to your directory#",
"run",
"qgis_mcp_server.py"
]
}
}
}用法
启动连接
- 在QGIS中,转到
plugins->QGIS MCP->QGIS MCP
- 点击“启动服务器”
与克劳德一起使用
一旦在Claude上设置了配置文件,并且服务器在QGIS上运行,您将看到一个带有QGIS MCP工具的锤子图标。
工具
ping-检查服务器连接的简单ping命令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代码
示例命令
这是我用于 演示: 或者,有关此更新版本,请参阅(https://www.linkedin.com/posts/syauqi-arka-yudisti-73b236288_qgis-ai-vibemapping-activity-7316248625045483524-hQdB?utm_source=share&utm_medium=member_android&rcm=ACoAAEXNN58BLMyjf4iZIy1KZZJBUFyiNlLtNSg)
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.我版本中的另一个示例命令
You have access to the tools to work with QGIS. You will do the following:
1. **Ping to check the connection**. If successful, proceed.
2. **Create a new QGIS project** and save it to:
**"D:/PROJECT/MCP/claudemap.qgz"** (gunakan slash `/` untuk kompatibilitas).
3. **Load vector layers**:
a. Load **"D:/PROJECT/MCP/map (2).osm"** (OSM layers akan terbagi menjadi `points`, `lines`, `multilinestrings`, `multipolygons`).
b. Load **"D:/PROJECT/MCP/Bahan_Mundupesisir/aoi.shp"** and name it **"aoi"**.
4. **Zoom to the "aoi" layer** to set the initial extent.
5. **Remove/hide unnecessary layers**:
a. Remove layer **"map (2) — points"** (klik kanan > Remove Layer).
b. Hide layer **"aoi"** (untuk mempertahankan extent tetapi tidak menampilkannya di peta).
6. **Style layers**:
a. **"map (2) — lines"**:
- Line color: **#ff6201** (orange)
- Stroke width: **0.5 mm**
b. **"map (2) — multilinestrings"**:
- Line color: **#8bff07** (hijau neon)
- Stroke width: **0.8 mm**
c. **"map (2) — multipolygons"**:
- Fill color: **#fff65f** (kuning pucat)
- Stroke color: **#fff65f** (sama dengan fill)
- Stroke width: **0.3 mm**
- Transparency: **80%**
7. **Create Print Layout (A4 Portrait)**:
a. Tambahkan **Map Item** dengan ukuran A4 (210x297 mm).
b. Set **scale to 1:10,000** and enable **"Lock layers for map item"**.
c. Tambahkan **Title**:
- Text: **"PETA MUNDUPESISIR BY CLAUDE.AI"**
- Font: **Bold, 24pt**
- Posisi: Atas tengah.
d. Tambahkan **Scale Bar** dan **Legend** (opsional).
8. **Export to PNG**:
- Path: **"D:/PROJECT/MCP/claudemap.png"**
- Resolution: **600 DPI** (pastikan ukuran file tidak terlalu besar).
9. **Save the QGIS project**.