Introduction

This course covers agentic coding workflows specializing in geospatial data science. You will get hands-on experience setting up your agent and understand how to use Skills and MCP servers to augment domain-specific capabilities. We cover best practices for using coding agents to rapidly solve complex problems - grounded in established science and human-in-the-loop validation. We cover hands-on examples using Claude Code - including crime hotspot mapping, route optimization, and object detection from aerial imagery. You will also learn how to use agents to manage a personal knowledge base and create a website that automatically updates with new information.


Installation and Preparation

Sign-up for GitHub

Visit GitHub.com and create a free account. If you already have an account, skip this step.

Install Git and GitHub CLI

Follow our Git and GitHub CLI Installation Guide install and configure Git and GitHub CLI.

Install Conda and Setup an Environment

We will use conda to install the required Python packages and manage local development environment.

Follow our step-by-step Conda Installation Guide to install Miniconda for your operating system.

  1. (Windows users), search for Anaconda Powershell Prompt and launch it. (Mac/Linux users): Launch a Terminal window. Run the following commands to create a fresh environment and activate it.
conda create --name claude_code_workshop -y
conda activate claude_code_workshop
  1. Now your environment is ready. We will install the required packages from conda-forge.
conda install -c conda-forge pandas geopandas matplotlib jupyterlab rioxarray

Your local development environment is now ready.

Install Visual Studio Code

We recommend Visual Studio Code (VS Code) editor for this workshop.

Follow our step-by-step Visual Studio Code Installation Guide to install and configure VS Code on your system.

Install Claude Code

Follow our step-by-step Claude Code Installation Guide to install and configure Claude Code on your system.

Sign-up for OpenRouteService API

OpenRouteService (ORS) provides a free API for routing, distance matrix, geocoding, route optimization etc. using OpenStreetMap data. We will use the Optimization API in this course.

We will obtain a key from OpenRouteService so we can use their API. The API is maintained by HeiGIT (Heidelberg Institute for Geoinformation Technology). Visit HeiGIT Sign Up page and create an account. Once your account is activated, you can visit the Dashboard and copy the long string displayed under Basic Key.

Get the Data Package

The code examples and reference materials used in this workshop are supplied to you in the claude_code_geospatial.zip file. Unzip this file to a directory - preferably to the <home folder>/Desktop/claude_code_geospatial/ folder.

Download claude_code_geospatial.zip.

Note: Certification and Support are only available for participants in our paid instructor-led classes.

1. Setting up Your Agent

A good practice is to always setup a CLAUDE.md file for your project. This file contains instructions and rules to be followed when working inside the project directory. If you already have a directory with some code or have cloned a Git repository, Claude Code can automatically create the CLAUDE.md file using the /init command. Here we are starting with a blank project, so we will create a new CLAUDE.md file with instructions.

  1. On your computer, launch Visual Studio Code. Click Open Folder… and select the <home folder>/Desktop/claude_code_geospatial/ where you have unzipped the data package.

  1. We will create a new file at the root of this folder. Select New File….

  1. Enter the name of the file exactly as CLAUDE.md. Note that the filename is case sensitive and needs to have the .md extension.

  1. Paste the following content and save the file.
# CLAUDE.md

## Geospatial Stack Preferences

- Prefer Python-based approaches
- Use existing packages instead of building solutions from scratch
- My preference for geospatial packages are below
  - Pandas for tabular data
  - GeoPandas for vector geospatial data
  - XArray ecosystem (rioxarray, xarray-spatial etc) for raster geospatial data
  - Scikit-learn for Machine Learning
  - GeoAI (geoai-py) for Deep Learning
- Web Apps
  - Streamlit for data driven apps
  - Leaflet for interactive mapping apps
  - Self contained HTML for small apps

## Other Preferences

- Write code that is simple to understand and explain
- Always install python packages in a conda environment. Never install anything in the base environment. Ask to change or create a new environment before installing.
- Do not use emojis

  1. Now we will start Claude Code. (Windows users), search for Anaconda Powershell Prompt and launch it. (Mac/Linux users): Launch a Terminal window. Use the cd command to change the current working directory to the project directory.

Windows

cd Desktop\claude_code_geospatial

Mac/Linux

cd Desktop/claude_code_geospatial

  1. Once you are inside the project folder, launch Claude Code by entering the following command.
claude

  1. The first time you start Claude Code inside a directory, there will be a security notification. You can choose Yes, I trust this folder. At the prompt, you can invoke several commands for configuration. You can type /help to see all available commands. Let’s run a few commands. First enable Plan Mode by entering the /plan command. Next choose the model using the /model command. The default model choice is good for now, and you can change the model at any time.

Now we are ready to use Claude Code for our first data analysis task.

2. Geospatial Data Analysis (Mapping Crime Hotspots)

We will now use Claude Code to do some data exploration, cleaning and analysis. This will give you a feel of how agents work and how to guide them. We will take the Police.uk data on street-level crime for the City of London Police and identify crime hotspots.

2.1 Exploratory Data Analysis (EDA)

  1. Enter the following prompt into Claude Code and press Enter. Make sure the Plan mode is on. This will ensure Claude Code will first make an implementation plan and wait for your approval before diving into coding.
I would like to do an exploratory data analysis of crime data in the folder london_crime_2024. 

* Give me a summary of the rows, columns and any missing data. 
* Flag any data quality issues. 
* Create charts showing different types of crime and monthly patterns.

  1. As the project-level CLAUSE.md states, all the work needs to be done in a conda virtual envrionment. Claude will prompt you to choose an environment. Choose the claude_code_workshop environment created for this class and press Enter.

  1. For the Output format, choose Python script + saved PNGs.

  1. Review the answers and select Submit answers. Press Enter.

Depending on your operating system, Claude Code version, and selected model, you may see a slightly different set of questions.

  1. Now Claude Code will go through the data and come up with a plan for building the required script for exploratory data analysis. You can review the plan and edit it as per your requirements. Use the Ctrl+G shortcut to open an editor with the plan and make any necessary edits. Once you are satisfied, confirm the execution by selecting Yes, and use auto mode.

  1. Claude Code will write the Python scripts and run it using the installed packages in the conda environment.

  1. Once done, it will prints the summary of its findings.

  1. The analysis will also produce some charts in the output/ subfolder.

2.2 Data Cleaning and Spatial Analysis

Now that we have a good understanding of the data structure, we can ask Claude to help us with analyzing the data. In this section, we will go through the workflow of identifying hotspots off thefts. Starting with data cleaning, we will iteratively improve our analysis and learn how we can use existing references (research papers, manuals etc.) to ground the behavior of the model.

  1. Back in Claude Code, switch to the plan mode. You can use Shift+Tab till you see plan mode on. Enter the following prompt. Claude Code will ask you clarifying questions. Select All 7 theft-family categories for Theft scope.
I want to analyze thefts data. Suggest which categories should be merged.

  1. For the merge goal, select Align to official ONS groupings.

  1. Select Submit answers and press Enter.

  1. Review the plan and make any adjustments if required. Select Yes, and use auto mode to proceed.

  1. Review the summary and enter the following prompt to implement them.
Filter to data to only for the 7 theft-family categories and 
write a single merged CSV with those records.
Remove missing data and unnecessary fields.

  1. Claude will produce a merge script and the output CSV file.

  1. This is the cleaned version of our original dataset. We can use this for mapping hotspots. Switch to the plan mode (Shift+Tab) and enter the following prompt.
I want to map the theft hotspots. 
Suggest what would be the best technique for the analysis.

  1. Answer the clarifying questions and select the Kernel Density Estimation (KDE) as the technique. Select Submit answers and press Enter.

  1. Once the analysis is planned, enter the following prompt to build the script.
Create a static visualiztion using matplotlib using gaussian_kde.

  1. Claude Code will produce a script and a map with hotspot visualization.

  1. While this is a good starting point, we can improve it by providing well-known and high quality reference material to guide the implementation. We have provided an extract of a research report Mapping Crime: Understanding Hot Spots in your data package that contains useful tips and best practices for crime mapping. We can improve our analysis by using this reference. Enter the plan mode (Shift+Tab) and write the following prompt.
I have some reference material for crime mapping in documents/hotspots.pdf. 
Incorporate suggestions from that and give me an updated plan.

  1. Select the option to use the Quartic kernel and deny option to extend the analysis beyond the scope of the original request.

  1. Once the plan is ready, review it. We can be explicit about the desired output, so you can select Tell Claude what to change.

  1. Ask for the following change.
Save the updated script and chart with the _v2 suffix.

  1. Claude Code will build the required script and produce the new hotspot visualization.

  1. The new map is much more interpretable and based in scientifically validated technique. Let’s extract the hotspots. Enter the following prompt.
Use the criteria "Greater than 5x mean" to extract hotspots and convert then to polygons.
Save the results as a GeoJSON london_theft_hotspots.geojson.

  1. The raster hotspots will be vectorized using the given threshold and saved as a GeoJSON file.

  1. We can visualize and explore the results in GeoLibre. Open https://web.geolibre.app/ in a browser. Drag and drop the GeoJSON file and verify the results.

2.3 Monitoring Usage

It’s a good practice to keep an eye on your token usage and costs. You can use the following command to know the utilization in the current session and how much quota is left in your plan.

/usage

3 Using Web APIs (Route Optimization)

In this section, we will learn how to use Claude Code to build Jupyter notebooks for data analysis and interactively guide the agent to reach the desired solution and validate the results. We will be implementing a real-world scenario of optimizing delivery routes based on a route optimization algorithm.

In your data package, you will find the following files in the data/route_optimization/ folder.

We will use Claude Code to build a Jupyter Notebook that builds an end-to-end workflow that loadis the data, finds optimal delivery routes and writes PDF manifests with delivery schedule for each store.

3.1 Using Claude Code in VS Code

Let’s install the Claude Code for VS Code extension.

  1. Click the Extensions button on the left-hand panel. Search for Claude and select the Claude Code for VS Code by Anthropic extension.

  1. Click Install.

  1. Once installed, it can be invoked from the Toggle Chat button and selecting the Claude Code tab.

3.2 Building Notebooks

Now that we have Claude Code running inside VS Code, we can prompt it to build a Jupyter notebook for us.

  1. Ensure the workshop folder claude_code_geospatial is open in VS Code. Enter the following prompt.
I want to build a notebook to find optimal delivery routes. 
Create a new notebook scripts/route_optimization.ipynb
Read the .geojson files in data/route_optimization/ folder and
display the data on an interactive map.

  1. This is a simple and straightforward task. Our project level CLAUDE.md already has preferences listed for how to setup the environment and what packages to use. Claude Code will start creating the notebook and will pause periodically for confirmation. You can choose Yes to proceed.

  1. Once the task finishes, a new notebook route_optimization.ipynb will be created in the scripts/ folder as instructed.

  1. Locate the notebook in the Explorer tab and double-click to open it. The notebook will have the datasets visualized on an interactive map.

3.3 Interactive Data Analysis

Now, let’s build the core of our data analysis to find the optimal delivery routes. This is a complex problem that requires a lot more context and direction. We will use the Plan mode and guide Claude Code towards building the code that solves the problem.

  1. Make sure the notebook route_optimization.ipynb is open. Open Claude Code from the Toggle Chat button.

  1. Switch to the Plan mode.

  1. Enter the following prompt.
I want to use OpenRouteService API. 
Give me options on different approaches to plan for the most optimal delivery routes from each store. 

Here are the constrants:

- A single trip will consist of 10 deliveries at maximum.
- The delivery will originate at a grocery store and end at the same delivery store.
- All stores are capable of fulfilling the order but can do a maximum of 5 delivery trips each day.

I want to know the most optimal route to minimize the distance traveled along with a schedule of the trips.

  1. Claude Code will trigger the AskUserQuestion tool to collect more information. For the Vehicle Routing Problem (VRS) approach, select the ORS Optimization API (VROOM).

  1. We need to enter our API key. Select Other and enter the API key in the response below, replacing the <your-api-key> with your actual API key. If you do have your key handy, you can login to your HeiGIT Account and copy the long string displayed under Basic Key.
Yes, I have a key. Save the API key in a separate cell in the notebook.

ORS_API_KEY='<your-api-key>'

  1. For the Conda env, select the claude_code_workshop conda environment that we have setup. You can then click Submit answers.

  1. As we are asking for delivery schedules, you may be prompted to choose store operating hours. We keep things simple and choose Trip order per store listing.

  1. After obtaining the necessary information, Claude Code will kick-off an agent to do the planning. Approve any permissions it may need.

  1. The OpenRouteService API has limits on how many Origin-Destination pairs it can solve. If you get prompted to choose for an approach, choose Two-stage: assign + batch, then ORS Optimization per trip approach.

  1. Once the plan it ready, it will be opened in VS Code. Review the plan and suggest any changes by adding comments. You can select any text and enter comments on what you would like changed. For example, in the initial plan that Claude Code came up with - it wanted to use the openrouteservice Python package. We can instead ask it to use the API directly instead of a client library by adding a comment like below.
Instead, use the REST API directly.

  1. After adding the comment, choose Send feedback and keep planning.

  1. Once the plan is modified and you are satisfied, choose Yes, and auto-accept.

  1. Claude Code will now start implementing the plan.

  1. Once the notebook is built, it will also test it to ensure it runs without any errors. Once everything is done, it will print a summary.

  1. Open the notebook and review the results. You will see the map with the planned routes for all the delivery locations.

3.4 Validation and Export

When building with AI - you need to spend most of your time validating the results and guiding the model. Let’s learn some techniques for validation.

  1. When reviewing the initial output of the delivery route, you will notice that some of the routes are very long and does not look optimal. We can ask Claude Code to fix this using the following prompt.
I see that some stores are not assigned any deliveries even if they are quite close to an address. 
The assignment tries to assign 10 deliveries in each route - 
making some of them quite long while nearby stores end up without any deliveries.
Update the plan to address this problem.

  1. Claude Code will go through the notebook and come up with a fix. Give your approval to apply the fix.

  1. Your prompt will also force Claude to do a more thorough validation of the results.

  1. The updated routes look much better, but we still need to do a closer inspection. We can export the results in any vector data format, so we can use a GIS to view and verify it better. Enter the below prompt.
Save the routes as a single GeoJSON file in the outputs/route_optimization/
folder so I can validate the results.

  1. A new file routes.geojson will be created. Locate it in the VS Code Explorer. Right-click and select Reveal in File Explorer to open the folder on your computer.

  1. We can visualize and explore the results in GeoLibre. Open https://web.geolibre.app/ in a browser. Drag and drop routes.geojson, along with the source data Delivery_Locations.geojson and Grocery_Store_Locations.geojson and verify the results.

  1. Once we are satistfied with the output, we can generate PDF manifests with the planned routes. These files are the output from our analysis that can be handed over to the operations team for implementation. Enter the following prompt. If prompted for a PDF library, choose Install reportlab and click Submit answers.
Generate PDF manifests in the outputs/route_optimization/ folder containing
delivery order and addresses for each trip.
1 manifest per store.

  1. The code will be added to the notebook and PDFs will be generated.

  1. The PDFs now contain delivery routes for each store.

4. Using Skills

4.1 Installing a Skill

4.2 Using a Skill

4.3 Useful Geospatial Skills

5. Building a Personal Knowledge Website

5.1 Understanding the AI Second Brain

5.2 Setting up your personal knowledge base

5.3 Creating and publishing your website

6. Using GeoAI (Object Detection)

6.1 Configuring an MCP Server

6.2 Building Notebooks in the Cloud

6.3 Using Deep Learning Models

License

This course material is licensed under a Creative Commons Attribution 4.0 International (CC BY 4.0). You are free to re-use and adapt the material but are required to give appropriate credit to the original author as below:

Agentic Coding for Geospatial course by Ujaval Gandhi www.spatialthoughts.com

© 2026 Spatial Thoughts www.spatialthoughts.com


If you want to report any issues with this page, please comment below.