Text‐to‐SpatialSQL: A LLM Based Method for Generating Spatial SQL Queries With Geo‐Knowledge Extracted From Software User Manual
Yicheng Ma, Yifan Zhang, Wenbo Zhang, Xinru Zhao, Wenhao YuABSTRACT
SQL statement design is a fundamental task in spatial databases and GIS. However, the inherent complexity of spatial SQL queries presents a significant challenge for non‐expert users. Although large language models (LLMs) have been widely used for SQL generation in traditional databases, their effectiveness in handling spatial queries remains constrained due to the specialized nature of spatiotemporal data and operations. To address this limitation, we propose a novel framework that integrates Retrieval‐Augmented Generation (RAG) with LLMs. Our method automatically extracts domain‐specific knowledge from spatial database documentation, constructs an application‐oriented knowledge graph, and leverages prompt engineering to generate standardized spatial SQL queries. Experimental results on benchmark datasets demonstrate significant improvements in execution accuracy (EX) and component matching rate (CM) across queries of varying schema complexity, validating the framework's efficacy in automating spatial query generation.