CGD-QCSF: A Code Generation-Driven Query–Computation Separation Framework for Natural Language Geospatial Analysis
Zhiyuan Le, Hao Li, Yuanxun Mei, Miaomiao Ren, Haizhen Chen, Yinying Zhou, Lu LiGeospatial data provide an important basis for urban governance, resource management, disaster assessment, and public health analysis by linking spatial locations, attribute information, and dynamic processes. However, complex geospatial analysis still requires substantial expertise in spatial databases, spatial SQL, and GIS computation tools. Although large language model-based Text-to-SQL methods have lowered the barrier to natural language-driven data querying, most existing approaches rely on single-step SQL generation and remain unstable for spatial tasks that involve attribute retrieval, spatial relationship evaluation, geometric operations, and statistical aggregation. To address this limitation, this paper proposes a Code Generation-Driven Query–Computation Separation Framework (CGD-QCSF). The framework is based on the separation of query and computation, and decomposes complex geospatial analysis into a staged execution process. CGD-QCSF coordinates intent understanding, schema pre-filtering, planning, execution state management, SQL generation, and spatiotemporal computation. A structured planner and an execution state manager coordinate task decomposition, capability-aware routing, and evidence-based recovery. A SQL Code Generation Agent (SCGA) handles database access, attribute filtering, and intermediate data extraction, while a Spatiotemporal Computation Agent (STCA) performs out-of-database spatial computation and statistical aggregation in an isolated Python sandbox. We construct a benchmark of 200 tasks, covering easy, medium, and hard spatial tasks. In the main experiment with Qwen3.7-Plus as the foundation model, CGD-QCSF achieves a Strict Structured Accuracy (SSA) of 90.5%. Removing the Planner reduces SSA to 84.5%, while removing the STCA reduces it to 70.5%. The ablation experiments show that removing either the Python sandbox or the Planner Agent degrades performance on complex tasks. These results indicate that CGD-QCSF extends complex geospatial analysis from single-step SQL generation into a multi-staged execution process. By explicitly separating query and computation, the framework reduces interference between spatial computation logic and database schema information, thereby improving the stability and success rate of natural language-driven geospatial analysis.