Skip to main content

LUP Student Papers

LUND UNIVERSITY LIBRARIES

Augmenting geospatial intelligence: enhancing code generation for OSM data extraction and processing using large language models

Steinmann, Luca Tim LU (2025) In Student thesis series INES NGEM01 20251
Dept of Physical Geography and Ecosystem Science
Abstract
Geospatial data analysis plays a critical role in a wide range of applications, from urban planning and environmental monitoring to disaster response and infrastructure management. However, it remains technically demanding and largely inaccessible to non-experts due to the complexity of geospatial data structures, domain-specific tools, and the need for advanced programming knowledge. A particular challenge lies in the efficient and accurate extraction and processing of heterogeneous geodata, such as that found in OpenStreetMap (OSM), which requires both semantic understanding and syntactic precision.
This master's thesis explores how Large Language Models (LLMs) can be adapted to autonomously generate domain-specific Python code -... (More)
Geospatial data analysis plays a critical role in a wide range of applications, from urban planning and environmental monitoring to disaster response and infrastructure management. However, it remains technically demanding and largely inaccessible to non-experts due to the complexity of geospatial data structures, domain-specific tools, and the need for advanced programming knowledge. A particular challenge lies in the efficient and accurate extraction and processing of heterogeneous geodata, such as that found in OpenStreetMap (OSM), which requires both semantic understanding and syntactic precision.
This master's thesis explores how Large Language Models (LLMs) can be adapted to autonomously generate domain-specific Python code - specifically PyQGIS scripts - for robust and efficient geodata processing. The study focuses on three adaptation strategies: Fine-Tuning, Retrieval-Augmented Generation (RAG), and Prompt Engineering. Each method contributes differently to enhancing the LLM’s ability to handle the intricacies of OSM data. A modular system of eight autonomous code-generating agents is developed, combining these methods in different configurations. Their performance is systematically evaluated using twenty geospatial test queries, designed with varying complexity levels, and assessed across multiple metrics including success rate, efficiency (iterations needed), code quality (CodeBLEU), and geodata output quality.
The results indicate that fine-tuning the LLM significantly improves the semantic and syntactic quality of the generated code, increases success rates, and reduces the number of iterations needed to produce valid outputs. Prompt engineering further enhances model stability, output structure, and factual reliability, showing particularly strong effects on execution success and response efficiency. RAG proves especially useful for queries involving rare or ambiguous OSM tags, helping to contextualize user input with relevant metadata, though its impact is more limited in terms of code structure.
Despite computational constraints, such as the use of a 4-bit quantised 70B LLaMA model and QLoRA-based fine-tuning, the findings demonstrate that LLMs can be effectively integrated into GIS workflows through targeted, low-resource adaptation strategies. This work contributes a novel combination of methods to the emerging field of geocoding with LLMs, and lays the groundwork for future research at the intersection of geoinformatics, machine learning, and autonomous agents. The modular architecture and evaluation framework also provide a scalable blueprint for applying LLMs to other complex, domain-specific coding tasks. (Less)
Popular Abstract
Teaching AI to Speak GIS
OpenStreetMap (OSM) is one of the world’s largest and most important open geodata platforms. It contains detailed information about streets, parks, buildings, bus stops, and much more. This data is used in urban planning, disaster response, and environmental studies. However, working directly with OSM data is often difficult and technical. It typically requires advanced programming knowledge and a deep understanding of geospatial data structures.
This thesis explores how Large Language Models (LLMs), advanced AI systems trained on human language and code, can be adapted to automatically generate Python scripts that extract the desired geodata from OSM. The core idea: instead of writing complex code by hand, a... (More)
Teaching AI to Speak GIS
OpenStreetMap (OSM) is one of the world’s largest and most important open geodata platforms. It contains detailed information about streets, parks, buildings, bus stops, and much more. This data is used in urban planning, disaster response, and environmental studies. However, working directly with OSM data is often difficult and technical. It typically requires advanced programming knowledge and a deep understanding of geospatial data structures.
This thesis explores how Large Language Models (LLMs), advanced AI systems trained on human language and code, can be adapted to automatically generate Python scripts that extract the desired geodata from OSM. The core idea: instead of writing complex code by hand, a user should be able to ask the AI in plain English (e.g., “Find all wind turbines in southern Sweden”) and receive the actual OSM data.
To make this possible, three methods were combined:
• Fine-tuning, where the AI is retrained on examples of geodata-related code;
• Prompt engineering, which provides the AI with precise instructions and structure for its responses;
• Retrieval-Augmented Generation (RAG), a technique where the AI gets additional real-time information from a database of OSM tagging rules and definitions.
Eight autonomous coding robots (called agents) were built using different combinations of these methods. They were tested with 20 geodata queries of varying complexity, ranging from simple filters (like finding playgrounds) to more advanced tasks (such as identifying specific types of infrastructure in specific regions). The agents were evaluated for correctness, code quality, efficiency, and accuracy of the geodata results.
The findings show that fine-tuning and prompt engineering clearly improve the AI’s ability to generate functional and accurate code. RAG proved useful especially for more complex queries involving rare or ambiguous OSM tags. Even with computational limitations, the adapted language models performed reliably and with high success rates.
This work demonstrates how AI systems can be adapted for domain-specific geodata processing, bridging the gap between natural language and expert-level code. The methods developed here lay the groundwork for future tools that can make complex geospatial data more accessible to professionals across various disciplines. (Less)
Please use this url to cite or link to this publication:
author
Steinmann, Luca Tim LU
supervisor
organization
course
NGEM01 20251
year
type
H2 - Master's Degree (Two Years)
subject
keywords
Physical Geography and Ecosystem analysis, LLMs, Fine-Tuning, RAG, Prompt Engineering, GeoAI, OSM
publication/series
Student thesis series INES
report number
715
language
English
id
9203891
date added to LUP
2025-06-25 09:15:54
date last changed
2025-06-25 09:15:54
@misc{9203891,
  abstract     = {{Geospatial data analysis plays a critical role in a wide range of applications, from urban planning and environmental monitoring to disaster response and infrastructure management. However, it remains technically demanding and largely inaccessible to non-experts due to the complexity of geospatial data structures, domain-specific tools, and the need for advanced programming knowledge. A particular challenge lies in the efficient and accurate extraction and processing of heterogeneous geodata, such as that found in OpenStreetMap (OSM), which requires both semantic understanding and syntactic precision.
This master's thesis explores how Large Language Models (LLMs) can be adapted to autonomously generate domain-specific Python code - specifically PyQGIS scripts - for robust and efficient geodata processing. The study focuses on three adaptation strategies: Fine-Tuning, Retrieval-Augmented Generation (RAG), and Prompt Engineering. Each method contributes differently to enhancing the LLM’s ability to handle the intricacies of OSM data. A modular system of eight autonomous code-generating agents is developed, combining these methods in different configurations. Their performance is systematically evaluated using twenty geospatial test queries, designed with varying complexity levels, and assessed across multiple metrics including success rate, efficiency (iterations needed), code quality (CodeBLEU), and geodata output quality.
The results indicate that fine-tuning the LLM significantly improves the semantic and syntactic quality of the generated code, increases success rates, and reduces the number of iterations needed to produce valid outputs. Prompt engineering further enhances model stability, output structure, and factual reliability, showing particularly strong effects on execution success and response efficiency. RAG proves especially useful for queries involving rare or ambiguous OSM tags, helping to contextualize user input with relevant metadata, though its impact is more limited in terms of code structure.
Despite computational constraints, such as the use of a 4-bit quantised 70B LLaMA model and QLoRA-based fine-tuning, the findings demonstrate that LLMs can be effectively integrated into GIS workflows through targeted, low-resource adaptation strategies. This work contributes a novel combination of methods to the emerging field of geocoding with LLMs, and lays the groundwork for future research at the intersection of geoinformatics, machine learning, and autonomous agents. The modular architecture and evaluation framework also provide a scalable blueprint for applying LLMs to other complex, domain-specific coding tasks.}},
  author       = {{Steinmann, Luca Tim}},
  language     = {{eng}},
  note         = {{Student Paper}},
  series       = {{Student thesis series INES}},
  title        = {{Augmenting geospatial intelligence: enhancing code generation for OSM data extraction and processing using large language models}},
  year         = {{2025}},
}