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.
- In QGIS, open Plugins → Manage and Install Plugins, search for "QGIS MCP", and install it.
- Install uv, which runs the server.
- Choose Plugins → QGIS MCP → Run MCP to start the server. QGIS has to be running, with the server started, before your agent connects.
- Add the server to your agent. In Claude Code:
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.
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:
- It measured area in UTM zone 10N (EPSG:26910), and checked it against areas on the ellipsoid, which agreed within 0.08%.
- The neighborhood counts add up to 252,928. With the 769 trees that fall outside every neighborhood, that's exactly 253,697. No neighborhoods overlap, so no tree was counted twice.
- 768 of the missing trees are around Portland International Airport, where the neighborhood layer has no polygon. The last one is just past the city's southern edge.
- The highest densities are in Northeast Portland, in Alameda, Irvington, and Sabin, with 2,500 to 2,700 street trees per km². It warned that two tiny slivers where neighborhoods meet rank even higher only because their areas are so small.
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:
- Coordinate systems. A buffer of "500" on a layer in degrees, or an area measured in degrees, runs without an error and gives the wrong answer. Ask for each layer's CRS before any analysis.
- Joins and filters that drop rows without saying so. Ask for counts before and after, as above.
- Long workflows. Matt Forrest gave Claude control of QGIS and it handled loading data, zooming, and styling well, but a multi-step hillshade workflow fell apart when it removed the DEM layer while fixing the layer order. Work in small steps and save the project between them.
Other ways to use AI in GIS
- Assistants inside QGIS. The plugin repository has assistant plugins, such as QGIS Agent and AI Copilot, that turn a request in a chat panel into PyQGIS. Some can use a local model through Ollama, which keeps your data on your computer.
- Imagery. GeoAI segments, classifies, and detects objects in satellite and aerial images, with a QGIS plugin. segment-geospatial applies Meta's Segment Anything Model to outline buildings, fields, or water.
- ArcGIS Pro. Esri's ArcGIS Pro assistant, in beta for ArcGIS Pro 3.8, answers questions, carries out actions, and writes ArcPy. It needs an organizational account, and Esri says not to enter production or sensitive data.
- PostGIS. mcp-postgis lets an agent read your schema and run spatial queries. Give it a database role that can only read, and set
MCP_POSTGIS_MODE=read_only. - Files. A coding agent such as Claude Code, Cursor, or Codex can run
ogr2ogr, DuckDB's spatial extension, or a GeoPandas script in your terminal, with no MCP server at all.
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.