Blog ·

AI for GIS: from QGIS to a web map with an AI agent

AI agents can now do GIS work, not just talk about it. Connected to the right tools, Claude, ChatGPT, and Cursor load layers in QGIS, run spatial analysis, and build web maps. To see how far that goes, I gave Claude one small project: count Portland's street trees in each neighborhood in QGIS, then put the result on a web page. This post walks through it, with the prompts, what the agent did, and what to check.

Connect Claude to QGIS

MCP, the Model Context Protocol, is how AI agents connect to outside tools. QGIS MCP is a QGIS plugin plus an MCP server that lets any MCP client drive QGIS 3.28 to 4.x. Its tools load layers, run Processing algorithms, style layers, take screenshots of the map, and run any PyQGIS code.

  1. In QGIS, open Plugins → Manage and Install Plugins, search for "QGIS MCP", and install it.
  2. Install uv, which runs the server.
  3. Choose Plugins → QGIS MCP → Run MCP to start the server. QGIS has to be running, with the server started, before your agent connects.
  4. Add the server to your agent. In Claude Code:
Terminal
claude mcp add -s user qgis -- uvx --from https://github.com/nkarasiak/qgis-mcp/archive/refs/heads/main.zip qgis-mcp-server

For Claude Desktop, Cursor, and other clients, the project's README has the config to paste.

The plugin's port has no password by default. It only listens on your own computer, but any program there can reach it, including its tool that runs arbitrary Python. Set the QGIS_MCP_TOKEN shared secret the README describes, and let your agent ask before it runs code.

Load the data

Portland publishes its Street Tree Inventory, every tree the city has counted along its streets, and its neighborhood boundaries. I downloaded both as GeoJSON and asked Claude Code:

In QGIS, load street-trees.geojson and neighborhoods.geojson. Put an OpenStreetMap basemap underneath, style the trees as small green dots and the neighborhoods as outlines only, and zoom to the neighborhoods. Then tell me each layer's CRS and feature count.

It added the three layers, styled them, and reported 253,697 trees and 125 neighborhoods, both in WGS 84, over a Web Mercator basemap. Then it took a screenshot of the map to check its work, saw that 253,697 dots blurred into one green mass, and shrank them until the street grid showed through. Nobody asked it to look.

QGIS with 253,697 Portland street trees as small green dots, the city's neighborhood outlines, and an OpenStreetMap basemap

Count the trees in each neighborhood

Next, the analysis, with the checks a GIS analyst would make written into the prompt:

Count the street trees in each neighborhood and work out trees per square kilometer, measuring area in a projected CRS rather than degrees. Check that the per-neighborhood counts add up to the total, and tell me about any trees that fall outside every neighborhood. Then hide the tree points, show the neighborhoods as a graduated green choropleth of trees per km² with neighborhood labels, and export the neighborhoods with tree_count and trees_per_km2 to neighborhood-trees.geojson in EPSG:4326.

About a minute later, it reported back:

QGIS showing Portland neighborhoods shaded from pale to dark green by street trees per square kilometer, darkest in Northeast Portland, with the neighborhood names labeled

The airport gap is the kind of mistake that fails quietly: without the check, 769 trees would simply have vanished from the totals. Asking for counts before and after is the cheapest insurance there is.

It did the counting by writing PyQGIS with a spatial index, not with Processing's Count points in polygon. That's fast, but it leaves nothing in the Processing history. If you want to rerun the analysis without an agent, ask it to use Processing algorithms, or to save its code as a script.

Put it on the web

A map in a QGIS project only helps the people who open the project. To share it, connect your agent to Mapricot's MCP server too: add the URL https://api.mapricot.com/mcp in Claude, Claude Code, ChatGPT, Cursor, or another client, and sign in. When the sign-in page asks what the agent can do, tick Map tiles and Create browser keys. Then ask:

Make a web page for mysite.com that shows neighborhood-trees.geojson as a choropleth of trees per km², with a legend and the neighborhood's numbers on hover.

A web map needs a browser key, so the agent calls Mapricot's create_key tool to make one in your account. The key only works from the origins it names, here https://mysite.com and http://localhost:* for testing, and only for map tiles. You don't copy anything from a dashboard: the agent gets the key once and puts it straight into the page it writes, which draws the GeoJSON on Mapricot's free map tiles with MapLibre GL JS. Here's the page it made, running on this site:

Map tiles are free and don't count against your requests. If your map also searches addresses, routes, or finds places, each of those is an API request at the usual price: the first 250,000 every 30 days are free, then $0.10 per 1,000.

What to check

The agent did well here because the job was short and the prompts asked for checks. Watch for these wherever a GIS mistake fails quietly:

Other ways to use AI in GIS

The MCP server docs list every tool Mapricot's server offers and how billing and keys work. If you're using AI in your GIS work and have found something that works, I'd love to hear about it at support@mapricot.com.