spatial-queries

Implements bounding-box SQL filters and Haversine distance calculations for proximity queries on Montréal open datasets.

1|Updated Mar 13, 2026
One-click install
npx skills add https://github.com/alistaircroll/montreal-open-data --skill spatial-queries-alistaircroll
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: spatial-queries
Source: https://github.com/alistaircroll/montreal-open-data/tree/main/skills/geo/spatial-queries
Command: npx skills add https://github.com/alistaircroll/montreal-open-data --skill spatial-queries-alistaircroll

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires requests.

What problem does it solve? CKAN DataStore lacks PostGIS, so location-based questions like "trees near me" or "crime within 1 km" cannot use native spatial functions. This Skill provides the bounding-box-plus-Haversine pattern needed to answer proximity queries against Montréal's geolocated open data. ## Core Features & Use Cases - Bounding Box SQL Pattern: Convert a radius around a point into lat/lon bounds and filter server-side with CAST and BETWEEN before transferring data. - Haversine Client-Side Filtering: Refine bounding-box results to exact circular distances in meters using a Python distance function. - Ready-Made Query Recipes: Includes patterns for nearby trees, crime near an address, nearest BIXI station via the GBFS API, and facilities within a radius, plus Montréal geographic constants and island bounds. - Use Case: A user asks "which crimes were reported within 1 km of 3575 Parc Avenue this year?" The agent geocodes the address, builds a bounding box, queries the crime dataset via CKAN SQL, and Haversine-filters the results. ## Quick Start Ask the agent to find all trees within 500 meters of a given Montréal address or coordinate.

Frequently Asked Questions about spatial-queries

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I query locations within a radius in CKAN DataStore?

CKAN DataStore has no PostGIS, so convert the radius to a lat/lon bounding box and filter server-side with CAST and BETWEEN in SQL. Then apply a Haversine distance filter client-side to keep only points within the exact radius.

How to find the nearest BIXI station with available bikes?

Fetch station_information.json and station_status.json from the BIXI GBFS API, then sort stations by Haversine distance from the user's coordinates. Join with the status feed to report available bikes at the nearest stations.

Why does a WHERE clause on latitude fail in CKAN SQL queries?

Latitude and longitude fields are stored as text in CKAN DataStore, so numeric comparisons fail without casting. Use CAST("Latitude" AS FLOAT) in the WHERE clause and add IS NOT NULL checks for records missing coordinates.

What are the limitations of bounding box proximity searches?

A bounding box is a square, so corner results can exceed the intended radius and must be filtered client-side with Haversine. Also, some datasets use MTM8 projected coordinates that must be converted to WGS84 first, and crime coordinates are deliberately offset for privacy.

Can I use PostGIS functions like ST_DWithin on Montréal open data?

No, the CKAN DataStore backend does not include PostGIS, so spatial functions like ST_DWithin are unavailable. The supported approach is a bounding-box SQL filter followed by precise client-side distance calculation.