How to Automate GIS Tasks with QGIS and AI: A Step-by-Step Guide

Automate GIS Processing with AI
Artificial intelligence (AI) is generating significant buzz these days. A variety of models have emerged, starting with ChatGPT, followed by Gemini, DeepSeek, Claude, and many others. Each day, I witness AI’s growing influence in shaping our world, answering questions, assisting with coding, generating images and videos, and powering countless other applications. As a GIS professional, I naturally want AI to support us in tackling GIS tasks. In a previous discussion, I explored how to make a map with ChatGPT. However, I believe AI offers far more to GIS professionals than just map creation. Beyond generating maps based on provided data, AI can enhance our ability to perform complex GIS analysis and streamline workflows.

In this post, I’d like to explore how AI can assist us in automating GIS tasks, from creating a new project and adding data to selecting features, performing processing, and exporting results. For this guide, I’ll use a protocol called the Model Context Protocol (MCP) to enable communication between QGIS and AI. MCP is an open standard that connects AI models like Claude or DeepSeek to external applications, allowing them to exchange data and execute commands seamlessly. By leveraging MCP, we can harness AI’s capabilities to streamline workflows and enhance productivity in QGIS, making complex tasks more efficient and accessible.

Prerequisites

Before we dive into the automation process, let’s ensure you have the necessary tools set up namely QGIS, Claude Dekstop, UV Package manager and of course Python.

QGIS 3.X

QGIS is the core GIS platform we’ll be automating. While the latest version (e.g., 3.34) works well, I’ve tested this setup on QGIS 3.26 Buenos Aires to ensure compatibility. It includes the Python console and PyQGIS API, which are essential for scripting and AI integration. If you don’t have QGIS installed yet, download it from qgis.org.

Claude Desktop

Claude Desktop serves as our AI interface, connecting to MCP-enabled models. You can download the Cloud Desktop from claude.ai. Unfortunately It’s not officially supported on Linux, but community builds like the one from GitHub’s aaddrick/claude-desktop-debian make it accessible.

UV Package Manager

The uv package manager, developed by Astral, is a fast, modern alternative to pip for managing Python dependencies. It’s optional but highly recommended for installing MCP-related libraries efficiently. To install uv you can follow the instructions from this Github.

Python 3.10+

Python powers QGIS scripting, and we need version 3.10 or later for compatibility with modern tools and libraries.

Make sure you downloaded all the prerequisites before moving to the next step.

Installing QGIS MCP Plugin

The next step is to install the QGIS MCP Plugin. You can get the plugin from Github's jjsantos01/qgis_mcp or simply using git in command prompt or shell: git clone git@github.com:jjsantos01/qgis_mcp.git as shown in the figure 1.

Git Clone to get QGIS MCP Plugin
Figure 1. Git Clone to get QGIS MCP Plugin

You will get a folder called qgis_mcp. Figure 2 shows the content of the folder.

QGIS MCP Folder
Figure 2. QGIS MCP Folder

To install the qgis_mcp_plugin we need to copy the qgis_mcp_plugin folder into QGIS Active Profile Folder. You can access the active profile folder from QGIS in the Settings > User Profiles > Open Active Profile Folder as seen in the figure 3.

Open QGIS Active Profile Folder
Figure 3. Open QGIS Active Profile Folder

The QGIS active profile folder will be opened. Open the python folder and  then plugins folder. Copy the qgis_mcp_plugin folder into the plugins folder. Close QGIS. We will open it again later.

Configure Claude Dekstop

Now it's time to configure the Claude Dekstop. Open the Claude Desktop and login to your account. Open the settings.

Claude Desktop Setting
Figure 4. Claude Desktop Setting

Select Developer > Edit Config as seen in the figure 5.

Edit Claude Desktop Configuration
Figure 5. Edit Claude Desktop Configuration

Open the claude_desktop_config.json file and replace with the following text. Don't forget to change the parent folder with yours. 

{
    "mcpServers": {
        "qgis": {
            "command": "uv",
            "args": [
                "--directory",
                "YOUR PARENT FOLDER/qgis_mcp/src/qgis_mcp",
                "run",
                "qgis_mcp_server.py"
            ]
        }

    }
}   

Close the Claude Desktop and open it again. Now you should see the hammer and connection icon as in the figure 6.

Claude-QGIS MCP
Figure 6. Claude-QGIS MCP 

Clicking the hammer icon will open a window that list all available MCP tools as seen as in figure 7.

QGIS MCP Tools
Figure 7. QGIS MCP Tools

 There are currently 15 tools avalailable.

  • ping - Simple ping command to check server connectivity
  • get_qgis_info - Get QGIS information about the current installation
  • load_project - Load a QGIS project from the specified path
  • create_new_project - Create a new project and save it
  • get_project_info - Get current project information
  • add_vector_layer - Add a vector layer to the project
  • add_raster_layer - Add a raster layer to the project
  • get_layers - Retrieve all layers in the current project
  • remove_layer - Remove a layer from the project by its ID
  • zoom_to_layer - Zoom to the extent of a specified layer
  • get_layer_features - Retrieve features from a vector layer with an optional limit
  • execute_processing - Execute a processing algorithm with the given parameters
  • save_project - Save the current project to the given path
  • render_map - Render the current map view to an image file
  • execute_code - Execute arbitrary PyQGIS code provided as a string

Setup Connection Claude AI with QGIS

Now it's time to connect QGIS with Claude AI. Open QGIS and activate the qgis_mcp_plugin from Plugins > QGIS MCP as shown in the figure 8.

QGIS MCP Plugin
Figure 8. QGIS MCP Plugin

The QGIS MCP plugin window will appear as in figure 9. Push the Start Server button.

QGIS MCP Window
Figure 9. QGIS MCP Window

To test the connectivity Claude-QGIS. In the Claude Desktop type ping. If the connection is working properly you will get the response as in figure 10.

Ping to check server connection
Figure 10. Ping to check server connection

Congratulations! Everything is set up. We’re ready to automate GIS tasks with AI.

Automate GIS Task with Claude AI

In this tutorial, we'll automate GIS tasks using QGIS with assistance from Claude AI to analyze crime patterns in Vancouver, Canada. Our goal is to filter crime events located within 100 meters of arterial roads. We'll work with two datasets: crimes.gpkg, which contains crime event data, and streets.gpkg, which includes the road network. The workflow involves selecting arterial roads from the street dataset, generating a 100-meter buffer around them, and intersecting this buffer with crime events to pinpoint incidents within the specified distance. Finally, we'll adjust the map view to a scale of 1:50,000 for optimal visualization.

To accomplish this, I developed a series of sequential prompts as follows: 

1. Make this path as working directory:"/media/ideageo/F48C7D848C7D41E2/QGIS/MCP"
2. Get "crimes.gpkg" and "streets.gpkg" file and add it to current project. Set the layer name as "crime" and "street"
3. On the "street" layer. Select features based on attribute table for 'use' column with value 'Arterial'. Save it as 'arterial_street.gpkg'. Add to the project with layer's name "arterial street"
4. Remove "street" layer from the project
5. Buffer "arterial_street" layer 100 m. "Dissolve" the result and save it as "arterial_buffer_100m.gpkg". Add to the project with layer's name "arterial_buffer"
6. Using "Intersection" tool, intersect the "crime" layer with "arterial_buffer" layer. Save it as "crime_arterial_intersect.gpkg". Add the "crime_arterial_intersect.gpkg" to the project with layer's name "crime_arterial_intersect"
7. Remove the "crime" layer from the project
8. Zoom in to the center of "arterial_street" layer to the scale 1:50000 

Transfer all the prompts by copying and pasting them into the Claude Desktop application, then proceed to execute them. Once initiated, the application will process each command in the sequence they were entered, running them one after another. This step-by-step execution is visually demonstrated in the accompanying figure provided below, which showcases the workflow and output as the tasks unfold.

Claude AI running GIS Task Automatically
Figure 11. Claude AI Executing GIS Tasks Automatically in QGIS
 

The processing results integrate seamlessly into the QGIS application, providing a clear visualization of the analysis. Upon completion, both the crime and street layers are automatically added to the QGIS map canvas. The arterial roads are then extracted from the street layer, and a 100-meter buffer is applied around them. Next, the crime points are intersected with this buffer layer, and the resulting dataset is incorporated into the map canvas. Finally, the map is adjusted to a zoom level that enhances visibility of the processed data. Each step of this workflow is illustrated in the figure below.

Automating GIS Process in QGIS with AI
Figure 12. Automating GIS Process in QGIS with AI

This tutorial has covered the essentials of automating GIS processing and analysis using Claude AI in conjunction with QGIS. Throughout this guide, we explored the necessary tools, including the installation of the QGIS MCP plugin, the configuration of MCP within Claude Desktop, testing the connection, and performing GIS tasks automatically by designing a sequence of prompts.As a practical demonstration, we analyzed crime events within 100 meters of arterial roads in Vancouver, Canada, bringing the concept to life. I appreciate you taking the time to read through this tutorial!

Related Posts

Disqus Comments