From geosql
Build cost-safe Geospatial SQL for BigQuery, Snowflake, Wherobots and Postgres and/or render results on an interactive Dekart map.
How this skill is triggered — by the user, by Claude, or both
Slash command
/geosql:geosqlThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
This skill uses the following CLIs:
This skill uses the following CLIs:
dekart for running BigQuery, Snowflake, Wherobots and Postgres SQLs and rendering mapsbq to run BigQuery SQL when dekart BigQuery integration is not available.snow to run Snowflake SQL when dekart Snowflake integration is not available.Before using CLIs, verify availability if it was not done before:
for c in bq snow dekart; do command -v $c >/dev/null && echo $c=ok || echo $c=missing; done
If no CLI is available, suggest installing the dekart CLI: pip install dekart && dekart init. dekart init is an interactive command that must be run by the user.
The user has 3 options in dekart init:
docker run -p 8080:8080 dekartxyz/dekart, more secure, requires Docker)Help the user pick the best installation option for their needs.
If dekart is available, check available connectors:
dekart call --name list_connections --args '{}' --json
If dekart available but not init, ask user to dekart init
Use the matching reference for per-database SQL, CLI examples, and engine-specific caveats:
references/bigquery.mdreferences/snowflake.mdreferences/postgres.mdreferences/wherobots.mdFollow these steps in order. Do NOT write a final query until steps 1-3 are complete. Combine each step with examples in matching dialect reference.
Discover available data objects before writing any query: start with database/share availability (where applicable), then confirm schemas, tables, and columns. Always verify exact object names and column types from the warehouse metadata; do not assume from general knowledge.
When multiple tables match the entity, sample each candidate for attribute density and prefer the richer source. Richer attributes enable stronger visual encoding in Step 5 and a stronger map validation case.
When the user asks about a named area (city, district, country), query division_area first to discover how it is actually stored (subtype, class, naming conventions). Do not assume from general knowledge.
Use the dialect reference for target-area SQL and fallbacks. Extract the exact bbox constants from the result. Use the full precision values returned by the query, do not round or truncate them.
ST_INTERSECTS against the real geometry from division_area for geographic correctness. bbox alone is rectangular and overshoots.ST_INTERSECTS.SELECT *.LIMIT for exploration.bbox overlap filter direction. The scan gate must use the OVERLAP pattern, not containment. The feature's bbox must overlap the target area:
-- CORRECT (overlap): feature extends into our area
AND bbox.xmax >= <area_xmin> -- feature's right edge is east of area's left
AND bbox.xmin <= <area_xmax> -- feature's left edge is west of area's right
AND bbox.ymax >= <area_ymin> -- feature's top edge is above area's bottom
AND bbox.ymin <= <area_ymax> -- feature's bottom edge is below area's top
-- WRONG (containment): do NOT use this
AND bbox.xmin >= <area_xmin> -- WRONG
AND bbox.xmax <= <area_xmax> -- WRONG
Use the dialect reference for draft query examples and engine-specific syntax. For map output, select a geometry column aliased exactly as lowercase geometry.
cast 64-bit integer fields to 32-bit int or double. Any numeric column bound to a Kepler visual channel (color, stroke width, size, height) must NOT be a 64-bit integer.
Do NOT present the query to the user without validating it first.
dekart, the mandatory dekart call --name update_query prepare step is also the dry-run gate; read dry_run.valid and dry_run.estimated_bytes_processed from that response before running dekart run-query.
If using bq CLI, run the query with bq query --use_legacy_sql=false --dry_run --format=json '<SQL>' and parse the JSON output for totalBytesProcessed.COUNT(*) (or equivalent) to confirm count is reasonable. If count is zero, debug before presenting.GEOGRAPHY, compute total area (for example SUM(ST_AREA(geometry))) and return units in square meters (and optionally km²).GEOGRAPHY, compute total length (for example SUM(ST_LENGTH(geometry))) and return units in meters (and optionally km).geometry, measurements are CRS units. For EPSG:4326 geometry, do not report meters; transform/cast first or label the result as CRS units.Iterate. Fix issues in small steps. Do not run broad or full extraction queries unless explicitly requested. All validation must be done in SQL.
Maps catch what rows cannot: misplaced points, duplicates, coverage gaps.
If user has dekart with configured warehouse connection, create and validate map by default.
If dekart is not installed, init or has no connectors but bq or snow CLIs available, then answer first (SQL + results + cost), then propose creating a map as "Next step" section with 2-3 explaining map benefits for this specific question.
Do not claim visual insights until the styled snapshot is rendered and inspected; never dress row-derived facts as map observations.
Make sure maps are beautifully styled and communicate a clear insight. Always add a map title, dataset name, and layer names, and optionally include a README when the user asks for insight.
If dekart CLI is missing, ask the user to pip install dekart && dekart init and wait until the user confirms with ready, done, or ok. If unauthed, ask to run dekart init.
bq CLIUse bq CLI directly. Always use standard SQL and enforce a budget. Full command examples and guardrails: references/bigquery.md.
snow CLIUse snow sql directly for Snowflake data and keep queries bounded. Full command examples and guardrails: references/snowflake.md.
dekart CLIUse this when dekart CLI is available.
bq or snow and create a map that way.The CLI stores map artifacts in this hierarchy:
report: top-level map container.dataset: one data layer slot inside a report, may contain a SQL query or uploaded file.file: uploaded data artifact attached to a dataset.query: SQL attached to a dataset/connection and executed asynchronously.job: execution instance for a query (dekart run-query handles run -> wait -> fetch after the query has already been prepared).Important IDs:
create_report returns the canonical report_id at result.report.id, result.report_id, or result.idcreate_dataset returns the dataset id at result.id.dekart run-query --json returns dataset_id, query_id, job_id, terminal status, and result_file.report_url fields returned directly by MCP tools may miss host name; resolve the user-facing URL with dekart report-url --report-id <report_id> --json.map_config, every layer config.dataId, filter dataId, and tooltip key must use the report dataset_id, not query_id, file_id, source table name, or dataset label.For real SQL, inline JSON is fragile because SQL often contains quotes and newlines. Save SQL to a file, then pass it to update_query through an args JSON file before running dekart run-query. The args file must be a JSON object with the prepared query id and SQL text, for example:
{
"query_id": "<query_id>",
"query_text": "<full SQL text>"
}
Control plane depends on execution mode:
report and dataset, create/update the query explicitly, then run dekart run-query for run -> wait -> fetch rows.report -> create dataset -> create file, then upload CSV and complete multipart flow.Choose exactly one flow after gate/confirmation:
list_connections shows at least one usable warehouse connector.dekart call, prepare each dataset query with create_dataset, create_query + update_query, then run dekart run-query --query-id <query_id> --out-dir <dir> --wait --json.report -> dataset -> file -> upload-file.Do not run both flows for the same task unless user explicitly asks.
dekart --help, dekart tools --help, dekart call --help, dekart upload-file --help.ready, done, or ok. If user declines or is silent, stop; do not export CSV, do not create reports.--max_rows is mandatory because BigQuery CLI defaults to 100 rows when omitted.
2>&1 when output is redirected to .csv.bq query ... --format=csv --max_rows=50000 'SELECT ...' | dekart upload-file --stdin --file-id <file_id> --name result.csv --mime-type text/csvsnow sql --format CSV --silent --query "<SQL with LIMIT 50000>" | dekart upload-file --stdin --file-id <file_id> --name result.csv --mime-type text/csvdekart tools.report_id and returns the dataset id as result.iddataset_iddekart upload-file and use returned complete payload/status.
bq query ... --format=csv --max_rows=50000 'SELECT ...' | dekart upload-file --stdin --file-id <file_id> --name result.csv --mime-type text/csvsnow sql --format CSV --silent --query "<SQL with LIMIT 50000>" | dekart upload-file --stdin --file-id <file_id> --name result.csv --mime-type text/csvdekart upload-file --file /tmp/result.csv --file-id <file_id>completed.dekart snapshot --report-id <report_id> --out /tmp/<report_id>-snapshot.pngreport_url, and image (when available) in final response.dekart --help, dekart run-query --help, dekart snapshot --help.list_connections shows at least one usable connector; do not use this flow when Dekart is missing or no usable connector exists.dekart call --name list_connections --args '{}' --jsonreport_id and returns the dataset id as result.iddataset_iddekart call --name create_report --args '{}' --json -> capture report_id from result.report.id, result.report_id, or result.id.dekart call --name create_dataset --args '{"report_id":"<report_id>"}' --json -> capture dataset_id from result.id, result.dataset_id, or result.dataset.id. Note that datasets are single slot, re-running query owerwrites prevoise data.
– Save SQL to a file. SQL must include geospatial output aliased exactly as lowercase "geometry" for the final map query.dekart call --name create_query --args '{"dataset_id":"<scratch_dataset_id>","connection_id":"<id>"}' --jsonupdate_query; for BigQuery, this response is the dry-run cost gate:
dekart call --name update_query --args-file /tmp/update-query-args.json --json
The args file must contain {"query_id":"<scratch_query_id>","query_text":"<full SQL text>"}.dry_run.valid is true and cost is acceptable, execute and fetch:
dekart run-query --query-id <scratch_query_id> --out-dir <dir> --wait --jsonresult_file from the JSON response; do not guess .csv or .parquet.dekart preview <result_file> --limit 20; inspect columns/types with dekart preview <result_file> --schema.run-query --json returns dataset_id, query_id, job_id, terminal status, and result_file.result_file as successful fetch.empty result (metadata/SHOW statement?), rewrite discovery SQL to return rows.dekart call, the canonical tool payload status path is result.query_job.job_status.dekart call --name create_query --args '{"dataset_id":"<map_layer_dataset_id>","connection_id":"<id>"}' --jsonupdate_query from the final SQL file and apply the BigQuery dry-run gate when applicable.
The args file must contain {"query_id":"<map_layer_query_id>","query_text":"<full SQL text>"}.dekart run-query --query-id <map_layer_query_id> --out-dir <dir> --wait --jsonupdate_query or run-query it again. Run any later validation (area, length, counts, previews) on the scratch query from step 6 — re-running the map-layer query overwrites the layer with the new result and blanks the map.dekart snapshot --report-id <report_id> --out /tmp/<report_id>-snapshot.pngreport_url, and image (when available) in final response:
report_id, dataset_id, query_id, job_id, terminal status, and report_url.dekart init, dekart config on your own. Ask user to re-run dekart init if needed.dekart init and confirm before retrying.dekart commands through | tail or | head; those buffers can hide progress until EOF and look idle.dekart run-query --wait, which blocks and returns directly.snapshot timeout), ask the user to enable local snapshots:
dekart snapshot-local install
Then retry snapshot with dekart snapshot --report-id <report_id>.layer.config.dataId points to the report dataset idfieldsToShow keys and filter dataId values also use the report dataset idreport_path as a Map URL or user-facing link or manually user facing report URL.dekart report-url --report-id <report_id> --json; do not treat MCP report_url or report_path fields as canonical.After upload, review the map snapshot and tune the layer. These rules override Claude's default styling instincts. Full reference: references/map-styling.md.
Non-obvious rules:
0.5-4 px, lines stroke 0.5-1.5 px, polygon borders 0.5-1 px hairline. Do not clamp LIMIT below 50k unless cost forces it.When uncertain about a specific pixel value or palette, read references/map-styling.md.
Use H3 when the user requests spatial aggregation, heatmaps, density, or cell-based rollups.
Confirm the function exists before using it. Use the dialect reference for engine-specific H3 functions.
Cost rules:
WHERE + hardcoded bbox first, then compute H3.h3 + aggregate metrics before adding boundaries.COUNT(*) previews before geometry-heavy ST_H3_BOUNDARY output.7-9 for city scale.bq query unavailable or auth fails: return exact fix commands only, no auto-install.snow sql unavailable or auth fails: ask user to install/configure snow, then retry using snow sql.SHOW DATABASES LIKE 'OVERTURE_MAPS__%' returns no rows): ask user to install Overture data from Snowflake Marketplace, then continue.dekart init; do not attempt a CLI workaround.geometry_columns errors): ask the user to run CREATE EXTENSION postgis;, then continue.dekart init; do not attempt a CLI workaround.update_query dry-run for BigQuery, COUNT(*)/bounded preview for Snowflake, tightly bounded COUNT(*)/preview execution through Dekart connector mode for Wherobots).Searches MemPalace before answering questions about past work, people, projects, or prior decisions. Returns verbatim stored content instead of guessing from model memory.
Guides Payload CMS config (payload.config.ts), collections, fields, hooks, access control, APIs. Debugs validation errors, security, relationships, queries, transactions, hook behavior.
Implements vector databases with Pinecone, Weaviate, Qdrant, Milvus, pgvector for semantic search, RAG, recommendations, and similarity systems. Optimizes embeddings, indexing, and hybrid search.
npx claudepluginhub dekart-xyz/geosql --plugin geosql