ShapefileGPT: a multi-agent large language model framework for automated shapefile processing

Qingming Lin, Rui Hu, Huaxia Li, Sensen Wu, Yongdan Li, Kai Fang, Hailin Feng, Zhenhong Du, Liuchang Xu

TL;DR

ShapefileGPT is a multi-agent Large Language Model (LLM) framework designed to automate complex Geographic Information System (GIS) tasks. By utilizing a "Planner-Worker" architecture and a specialized library of 27 GIS functions, it achieves a 95.24% task success rate—more than doubling the performance of standard GPT-4o in handling spatial vector data.

What Problem Does This Paper Address?

While Large Language Models (LLMs) have revolutionized text and code generation, they consistently stumble when faced with spatial vector data, specifically the industry-standard Shapefile format.

Processing Shapefiles typically requires specialized expertise in software like ArcGIS or libraries like GeoPandas. For researchers in adjacent fields (like public health or urban planning), this creates a high technical barrier. When general-purpose LLMs like GPT-4 attempt these tasks, they often "hallucinate" spatial relationships or generate code that fails to account for the intricate topological constraints of geographic data. The authors aim to bridge this gap by creating an agentic system that understands GIS logic natively.

Methods

The authors propose a vertical multi-agent architecture that moves away from raw code generation toward structured tool-calling.

  • The Planner Agent: Acts as the "brain." It interprets the user’s natural language query, decomposes it into a sequential subtask list, and monitors execution. Crucially, it manages a "Planning Loop" that allows for error detection and retries if a subtask fails.
  • The Worker Agent: Acts as the "hands." It receives instructions from the Planner and selects the appropriate tool from a specialized Function Library.
  • Specialized Function Library: Instead of asking the LLM to write Python from scratch, the authors developed 27 pre-validated functions covering data reading, geometric operations (buffers, clips, overlays), and spatial queries.
  • Dual-Format Documentation: The system uses YAML-formatted documentation for the LLM’s context (for readability and token efficiency) and JSON for backend validation.

Datasets

The paper introduces a new Shapefile Task Benchmark to evaluate performance:

  • Content: 42 standardized tasks derived from authoritative GIS textbooks.
  • Categories: Geometric Operations (22 tasks), Queries and Computations (7), Distance and Direction (7), and "Other" operations like coordinate transformations (6).
  • Structure: Each task includes a structured definition, input/output paths, and ground-truth function call sequences for evaluation.

Key Insights and Ideas

  • Tool-Calling > Code Generation: The "aha moment" here is that LLMs are much better at selecting the right tool than writing the tool from scratch. By providing a "sandbox" of 27 validated GIS functions, the framework eliminates the syntax errors common in standard LLM outputs.
  • The Necessity of the Planner: Ablation studies showed that removing the Planner agent significantly reduced the system's fault tolerance. The Planner’s ability to "observe" the result of a step and "re-think" the next subtask is what allows the system to handle multi-step spatial analyses (e.g., "create a buffer, then clip it, then calculate the area").
  • Few-Shot Prompting is Essential: Providing the Worker agent with specific examples of how to call the GIS APIs drastically reduced redundant function calls and improved the "Parameter Accuracy" to 100% across all tested configurations.

Key Results

The framework was tested against several state-of-the-art models using the new benchmark:

Model / Framework Accuracy Success Rate
GPT-4-Turbo (Baseline) 33.33% 35.71%
GPT-4o (Baseline) 42.86% 45.24%
ShapefileGPT 92.86% 95.24%
  • Reliability: ShapefileGPT effectively solved complex spatial joins and overlay analyses that caused standard GPT models to fail.
  • Efficiency: Using GPT-4o-mini as the "Worker" and GPT-4o as the "Planner" provided the best balance of high success rates and lower "repeat call" rates, suggesting that smaller models are highly capable when given strict API documentation.

Limitations and Future Work

  • Token Consumption: The multi-agent loops and extensive API documentation result in high token usage, which could become expensive for very large-scale projects.
  • Hallucinations in Complex Geometry: While reduced, the model can still struggle with extremely irregular data or complex boundary conditions that aren't covered by the current function library.
  • Dataset Scale: The benchmark consists of 42 tasks; the authors acknowledge the need to expand this to a broader range of real-world, "messy" GIS scenarios.
  • Future Directions: The authors suggest moving toward local model inference to reduce costs and improving context-handling mechanisms to further mitigate hallucinations.

Summary updated

BibTeX
@article{lin2025shapefilegpt,
  author = {Qingming Lin and Rui Hu and Huaxia Li and Sensen Wu and Yongdan Li and Kai Fang and Hailin Feng and Zhenhong Du and Liuchang Xu},
  title = {{ShapefileGPT: a multi-agent large language model framework for automated shapefile processing}},
  journal = {International Journal of Digital Earth},
  year = {2025},
  doi = {10.1080/17538947.2025.2577884},
}
Figure