top of page

LBSocial

Spatial Analysis Agent in QGIS: Analyze Spatial Data with AI and Natural Language

This tutorial demonstrates how to use the Spatial Analysis Agent plugin in QGIS to perform spatial data analysis using natural language powered by AI. With this tool, users can describe tasks in natural language, and the plugin will generate geoprocessing workflows. While no advanced coding is required, some basic programming and GIS knowledge are necessary to understand and apply the outputs effectively.



Introduction to Natural Language Spatial Analysis

The Spatial Analysis Agent integrates QGIS with OpenAI’s GPT models, including GPT-o3, known for its reasoning capabilities. This plugin translates natural language prompts into spatial workflows, making it easier to conduct tasks such as creating symbology, performing temporal aggregation, and generating movement paths.

GIS software interface displaying tabs like Request Page, Generated Code. Input and output fields are visible, with blue buttons below.
The Spatial Analysis Agent plugin interface

Installing and Configuring the Plugin

  1. Open QGIS.

  2. Navigate to Plugins > Manage and Install Plugins.

  3. Search for SpatialAnalysisAgent and install it.

  4. Launch the plugin and open the Settings tab.

  5. Provide your OpenAI API key.

  6. Select a model (default: gpt-4o) and define a workspace directory.

QGIS plugin interface showing settings for GIS-Spatial Analysis Agent. Includes options for API key, code review, and workspace directory.
Plugin settings panel with API key input and model selection

Common Use Cases


Styling Layers by Attribute

Prompt: "Assign unique colors to the GPS layer based on the name field."

The plugin automatically generates a styling workflow based on unique attribute values, such as "home," "work," and "gym."

Map interface with colorful data clusters labeled commute, gym, home, work. Browser panel left shows various data sources and layers.
Map layer showing features symbolized

Summarizing Temporal Patterns

Prompt: "Count total hours spent at each location and display the results in a bar chart."

Using timestamp data, the plugin calculates durations per location and produces a visual summary.

Bar chart titled "Hours Spent at Different Locations": commute, gym, home, and work. Home has the highest hours spent.
Aggregated time per location type

Creating Movement Paths

Prompt: "Create movement paths from the GPS points."

GPT-4o interprets sequential data and generates line features that represent spatial movement over time.

Map interface showing red lines and points indicating movement paths. Left panel lists files and layers, including "movement_paths.shp".
The created movement paths

Attempting an Open-Ended Spatial Question

Prompt: "Analyze spatial-temporal movement patterns."

This is a more complex, open-ended task that pushes the model's reasoning limits. In the video, this prompt did not produce meaningful output. Still, reviewing the generated code may offer insight or inspiration for refining your own analysis.


Best Practices for Effective Prompts

  • Use precise layer and field names in your prompt.

  • Examine generated code to understand workflows or troubleshoot issues.

  • Combine with manual GIS techniques to validate or extend results.


Benefits of Using the Spatial Analysis Agent

This plugin supports AI-assisted geoprocessing in QGIS, enabling faster prototyping, reducing manual scripting, and enhancing learning. It is especially useful for:

  • GIS students and educators

  • Analysts working with spatial and temporal data

  • Users exploring AI-driven GIS workflows


Further Resources


Watch the Full Tutorial


Comments


bottom of page