AI-Assisted Analysis
Prerequisites
Section titled “Prerequisites”spatialpackCLI installed (pip install -e ".[full]")- An existing Spatial Pack with at least one vector layer (GeoParquet)
- AI gateway configured with one of the following:
ANTHROPIC_API_KEYenvironment variable set, orOPENROUTER_API_KEYenvironment variable set
1. Check your AI gateway configuration
Section titled “1. Check your AI gateway configuration”Verify the gateway is configured and can reach the language model provider.
spatialpack ai config showExpected output:
AI Gateway Configuration Provider: anthropic Model: claude-haiku-4-5-20251001 Status: configuredIf the configuration is missing, set your API key:
# For Anthropicexport ANTHROPIC_API_KEY=sk-...your-key
# For OpenRouterexport OPENROUTER_API_KEY=sk-or-...your-key2. Analyze a spatial data source
Section titled “2. Analyze a spatial data source”Run spatialpack ai analyze on a source file to generate an enrichment YAML. The AI profiles the data — examining column names, types, value distributions, and geometry characteristics — and proposes human-readable field descriptions, display names, and formatting rules.
spatialpack ai analyze ./layers/cadastre.parquetExpected output:
AI Analysis Source: ./layers/cadastre.parquet Features: 12,345 Columns: 8 Profiling: complete
Enrichment Proposals: lot_number -> "Lot Number" (identifier) area_m2 -> "Area (m2)" (numeric, format: 0,000.0) zoning -> "Zoning Classification" (categorical) geometry -> kept as-is
Output: enrichments/cadastre.yamlThe AI reads a sample of the data (up to 10,000 rows by default), infers the semantic meaning of each column, and writes an enrichment YAML file. The enrichment file captures display names, descriptions, formatting rules, and column visibility settings.
3. Preview proposals without writing files
Section titled “3. Preview proposals without writing files”Use --dry-run to see what the AI would propose without creating any files.
spatialpack ai analyze ./layers/roads.parquet --dry-runExpected output:
AI Analysis (dry run) Source: ./layers/roads.parquet
Proposals: road_name -> "Road Name" (text) road_class -> "Road Classification" (categorical) speed_limit_kmh -> "Speed Limit (km/h)" (numeric) length_m -> "Length (m)" (numeric, format: 0,000.0)
No files written (dry run mode).Review the proposals before committing them to disk. This is useful when exploring unfamiliar datasets.
4. Customize the analysis model
Section titled “4. Customize the analysis model”Override the default model for more detailed analysis on complex datasets.
spatialpack ai analyze ./layers/energy_infrastructure.parquet \ --model claude-sonnet-4-20250514Higher-capability models produce more nuanced field descriptions and better detect domain-specific terminology (e.g., distinguishing “transmission” from “distribution” lines in energy datasets).
5. Accept all proposals in CI mode
Section titled “5. Accept all proposals in CI mode”Skip interactive review and accept all AI proposals. This is useful in automated pipelines where human review happens at a later stage.
spatialpack ai analyze ./layers/bushfire_prone.parquet --accept-allExpected output:
AI Analysis Source: ./layers/bushfire_prone.parquet Features: 2,847 Mode: accept-all (CI) Output: enrichments/bushfire_prone.yamlThe --accept-all flag writes the enrichment file without pausing for review. Combine with --overwrite to replace an existing enrichment file.
6. Set routing rules for AI tasks
Section titled “6. Set routing rules for AI tasks”Configure the AI gateway to route different task types to different models and providers. Use faster, cheaper models for routine profiling and more capable models for complex analysis.
spatialpack ai config set enrichment \ --model claude-haiku-4-5-20251001 \ --provider anthropic \ --max-tokens 4096Expected output:
Gateway Configuration Updated Task type: enrichment Model: claude-haiku-4-5-20251001 Provider: anthropic Max tokens: 4096This sets the default model for all enrichment tasks. Individual commands can still override the model with the --model flag.
7. Use enrichment results in a pipeline
Section titled “7. Use enrichment results in a pipeline”Once you have an enrichment YAML file, the pipeline automatically discovers and applies it during conversion. Place the enrichment file in the enrichments/ directory with a filename matching the layer ID.
stages: - name: convert_cadastre action: convert.shp input: cadastre output: "layers/cadastre.parquet" options: crs: EPSG:4326 bbox: ${pack.region.bbox} layer: id: cadastre title: "Cadastre Boundaries" type: vectorWith enrichments/cadastre.yaml present, the convert stage automatically applies the AI-generated display names, descriptions, and formatting rules to the output GeoParquet file.
Next steps
Section titled “Next steps”- CLI ai reference — Full options for
spatialpack ai analyzeandspatialpack ai config - Pipeline Architecture — How enrichment integrates with the automated build pipeline
- What is a Spatial Pack — Understanding the pack structure that enrichment enhances