Overview
LLMs can write syntactically fluent Python GIS code with pandas and geopandas — but the code may be *geographically* wrong. The paper GeoContra: From Fluent GIS Code to Verifiable Spatial Analysis with Geography-Grounded Repair (Yinhao Xiao, Rongbo Xiao, Yihan Zhang; arXiv:2605.00782, 2026-05-01) proposes a framework to verify and repair such code.
The Problem: Fluent but Geographically Illiterate Code
LLM-generated spatial analysis code may run perfectly while producing incorrect results:
- Using the wrong coordinate reference system (CRS), treating latitude/longitude as meters
- Computing straight-line (planar) distance while ignoring the Earth's curvature
- Ignoring topology, treating overlapping polygons as independent
- Mixing projection systems so datasets from different regions can't align
- Coordinate semantics: what CRS the input uses, what CRS the output should use
- Topological constraints: whether polygons may overlap, how boundaries are handled
- Unit constraints: kilometers vs. miles, square meters vs. hectares
- Spatial predicates: required spatial relations (contains, intersects, adjacent)
- Forbidden shortcuts: patterns that look correct but are geographically wrong
- Two polygons "intersect," but projection error makes the intersection area off by 100x
- Buffer analysis "succeeds" but the buffers are badly distorted due to an unsuitable projection
- Distance calculation "outputs a number" but is completely wrong because lat/lon was treated as Cartesian coordinates
Code that runs but produces wrong results is the most dangerous kind of error.
The Approach: Geography as Executable Contracts
GeoContra encodes geographic knowledge into executable contracts for each spatial analysis task:
After code generation, GeoContra performs static rule checking — verifying the code satisfies the geographic contract *before* execution.
Why Static Checking Beats Run-Then-Verify
In GIS, a "successful" run can be deceptive:
The Repair Loop: From Fluent to Verifiable
Current LLM GIS code is syntactically fluent but semantically fragile. GeoContra's repair strategy:
1. Detect: static analysis finds which geographic contract is violated 2. Locate: identify which line/function causes the violation 3. Repair: propose fixes from a geographic knowledge base (e.g., "use geodesic distance here, not Euclidean") 4. Verify: re-run static checks on the repaired code
The goal is not faster code generation, but *trustworthy* code generation.
Key Insight: Precise Definitions Matter
Like Feynman's insistence on definitions, "distance" in GIS has many meanings — Euclidean, geodesic (shortest path on the sphere), Manhattan, driving distance over a road network. An LLM knows the word "distance" but not necessarily which definition fits a given geographic context.
GeoContra's lesson: to make AI reliable in spatial analysis, geographic knowledge must shift from implicit common sense to explicit contracts.
Practical Takeaways
If you use AI to generate geospatial code, don't just check whether it runs. Ask:
1. Is this CRS appropriate for data at this latitude? 2. Does this distance computation account for Earth's curvature? 3. Are topological relations preserved under this projection? 4. Are unit conversions correct in this context?
Correctness in spatial analysis is not just syntactic and logical — it is geographic-semantic. Only when an AI system understands CRS semantics, respects topological constraints, and knows when to use geodesic distance can it be a competent geospatial analyst rather than a geographic illiterate.
---
Reference: GeoContra: From Fluent GIS Code to Verifiable Spatial Analysis with Geography-Grounded Repair. Yinhao Xiao, Rongbo Xiao, Yihan Zhang. arXiv:2605.00782, 2026-05-01.