Can large language models generate geospatial code?

Shuyang Hou, Zhangxiao Shen, Jianyuan Liang, Haoyue Jiao, Anqi Zhao, Yaxian Qing, Dehua Peng, Zhipeng Gui, Xuefeng Guan, Longgang Xiang, Huayi WuGeo-spatial Information Science 2025

TL;DR

This paper introduces GeoCode-Eval, a novel framework and benchmark dataset (GeoCode-Bench) to rigorously assess the ability of Large Language Models (LLMs) to generate geospatial code. They found that while LLMs show promise, current models struggle with domain-specific knowledge, leading to "coding hallucinations" and incomplete or incorrect code, highlighting the need for specialized training and evaluation.

What Problem Does This Paper Address?

The increasing demand for processing spatiotemporal data and performing geospatial modeling has led to a growing need for automated geospatial code generation. Large Language Models (LLMs) have shown potential in code generation, but their effectiveness in the specialized domain of geospatial coding remains uncertain. This is largely due to a lack of domain-specific knowledge and code corpora, which can result in LLMs refusing to generate code or producing "coding hallucinations" (incorrect or nonsensical code). This gap hinders advancements in geospatial research and applications. The paper aims to address this by providing a comprehensive evaluation framework and benchmark to assess and improve LLM capabilities in this area.

Methods

The authors developed the GeoCode-Eval (GCE) framework, which evaluates LLMs across three dimensions: "Cognition and Memory," "Comprehension and Interpretation," and "Innovation and Creation," further broken down into eight capability levels. To support this framework, they constructed the GeoCode-Bench dataset. This dataset comprises a variety of question types, including multiple-choice, fill-in-the-blank, true/false, and subjective tasks (code summarization, generation, completion, and correction).

The evaluation process involved:

  • Data Collection: Gathering real geospatial code, platform documentation, function documentation, and built-in dataset information from sources like GitHub, Wikipedia, and official platform websites.
  • Dataset Construction: Using a combination of expert experience, the Self-Instruct framework, and rule-based methods to automatically generate evaluation questions.
  • Expert Correction: Reviewing and validating all questions by experts to ensure accuracy, uniqueness, and clarity.
  • Evaluation Scheme: Employing an "Answer-Judge-Analyze" (AJA) framework. This involved designing specific prompts for LLMs to answer questions, followed by expert and GPT-4 scoring based on explicit criteria for each question type.
  • Prompting Strategies: Investigating the impact of different prompting methods, including single-round vs. multi-round inquiry, zero-shot vs. few-shot answering, and Chain of Thought (CoT) reasoning.
  • Fine-tuning Case Study: Demonstrating a two-stage optimization approach by fine-tuning the Code Llama-7B model on Google Earth Engine (GEE) specific data to create GEECode-GPT.

Datasets

  • GeoCode-Bench: A newly introduced benchmark dataset specifically designed for evaluating geospatial code generation capabilities of LLMs. It contains:
  • 5,000 multiple-choice questions
    • 1,500 fill-in-the-blank questions
    • 1,500 true/false questions
    • 1,000 subjective tasks (code summarization, generation, completion, and correction)
  • GEE JavaScript scripts and related task instructions: Used for fine-tuning the Code Llama-7B model to create GEECode-GPT.
  • GJCode-PT (pre-training corpus) and GJCode-SFT (instruction data): Constructed from GEE JavaScript scripts for the fine-tuning case study.

Key Insights and Ideas

  • Domain Specialization is Crucial: LLMs trained on general code corpora struggle with the nuances of geospatial code. This highlights that simply having a large model isn't enough; it needs exposure to domain-specific data and tasks.
  • "Coding Hallucinations" are a Major Hurdle: The paper confirms that LLMs often generate incorrect or nonsensical code in the geospatial domain, a problem that needs to be addressed for practical applications.
  • Evaluation Framework Matters: The GCE framework provides a structured way to dissect LLM capabilities, revealing strengths and weaknesses across different aspects of geospatial code generation. This is more insightful than a single accuracy score.
  • Prompting Strategies Have an Impact: While CoT reasoning generally improved performance, it could sometimes negatively affect readability, suggesting a trade-off that needs careful consideration.
  • Fine-tuning Can Significantly Boost Performance: The GEECode-GPT case study demonstrates that targeted fine-tuning on domain-specific data can substantially improve an LLM's ability to generate geospatial code.

Key Results

  • Platform/Toolkit Knowledge: Commercial closed-source models (GPT-4, Claude-3-Opus) achieved very high accuracy (Acc@1 > 0.94), while open-source general-purpose models lagged slightly. Code generation models performed poorly, likely due to insufficient geospatial knowledge in their training data.
  • Function Knowledge: GPT-4 led with 0.7435 Acc@1, but overall performance was weaker than for platform knowledge. Open-source models showed improvement with voting strategies, while code generation models had uneven performance.
  • Built-in Dataset Knowledge: All models struggled significantly, with even the best (GPT-4) achieving only 0.4325 Acc@1. Code generation models performed particularly poorly, indicating a lack of knowledge in this area.
  • Entity Recognition: Commercial models excelled (Acc@1 > 0.85). Open-source general-purpose models performed well, while code generation models were weaker, especially on functional processes.
  • Code Summarization: GPT-4 achieved high scores (0.924 direct, 0.996 with CoT), demonstrating strong completeness and accuracy. CoT generally improved performance but could impact readability.
  • Code Generation: Executability was generally low across all models (ranging from 0.208 to 0.584 with CoT). Models struggled to combine correct syntax with interpreted instructions, leading to non-executable code. GPT-4 and Claude-3-Opus showed good readability.
  • Code Completion: Models performed well in Position Accuracy but had mediocre Content Accuracy, indicating syntax knowledge gaps. Executability was poor, with some models even showing a decline.
  • Code Correction: Scores were generally lower than code completion, with most models failing to reach a 0.6 passing threshold. Models struggled to accurately locate errors, and corrected code often contained syntax or logical errors.
  • Fine-tuning Impact: The GEECode-GPT model showed significant improvements in subjective tasks (summarization, generation, completion, correction) on the GEE platform, ranging from 2.6% to 37.6% compared to its base model.

Limitations and Future Work

  • Limitations:
    • The study acknowledges that even advanced models exhibit uneven performance across different capability levels, indicating no model achieved a "fully balanced radar chart."
    • The performance of code generation models was relatively weaker, possibly due to training on general code corpora diluting geospatial knowledge.
  • The built-in dataset knowledge was particularly challenging for all models due to scattered information and limited systematic integration in training corpora.
  • Future Work:
    • Expand exploration into other capability boundaries of LLMs in the geospatial domain.
  • Investigate ways to enhance LLM performance through both usage strategy optimization and model structure improvement.
  • Focus on collecting larger and more representative geospatial domain corpora to build more reliable and specialized geospatial code generation models.

Summary updated

BibTeX
@inproceedings{hou2025can,
  author = {Shuyang Hou and Zhangxiao Shen and Jianyuan Liang and Haoyue Jiao and Anqi Zhao and Yaxian Qing and Dehua Peng and Zhipeng Gui and Xuefeng Guan and Longgang Xiang and Huayi Wu},
  title = {{Can large language models generate geospatial code?}},
  booktitle = {Geo-spatial Information Science},
  year = {2025},
  url = {https://openreview.net/forum?id=1oUpsVILfN},
}
Figure