Chain-of-programming (CoP): empowering large language models for geospatial code generation task
Shuyang Hou, Haoyue Jiao, Zhangxiao Shen, Jianyuan Liang, Anqi Zhao, Xiaopu Zhang, Jianxun Wang, Huayi Wu
Abstract
Large Language Models (LLMs) have driven the development of geospatial code generation but face challenges such as incomplete user requirements and insufficient knowledge of platform-specific syntax, often leading to ‘code hallucination.’ To address this issue, this paper proposes the Chain-of-Programming (CoP) framework, which divides the generation process into five steps: requirement analysis, algorithm design, code implementation, debugging, and annotation. The framework incorporates a shared information pool, knowledge base retrieval, and user feedback mechanisms, enabling end-to-end code generation without the need for model fine-tuning. Based on geospatial problem classification and evaluation benchmarks, CoP significantly improves the logical clarity, syntactical correctness, and executability of the generated code, achieving performance improvements ranging from 3.0% to 48.8%. Comparative and ablation experiments further validate the advantages of CoP and the necessity of its core components. Case studies on building visualization and fire data analysis demonstrate the practical value of the framework. This study also develops and open-sources a prototype system, offering a systematic, step-by-step solution for LLM-based geospatial code generation and providing valuable insights for code generation in other specialized domains.