Write an index-accelerated proximity query with PostGIS ST_DWithin using geography vs geometry types correctly
domain: postgis.net · 4 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗
Steps
Store or cast points as geography to get distance filtering directly in meters via ST_DWithin(geog_col, point, meters)
For geometry columns, remember distance is expressed in the SRID's native units (degrees for EPSG:4326) — reproject to a metric SRID first if needed
Create a GIST index on the column: CREATE INDEX ... USING GIST (geom_or_geog_col)
Use ST_DWithin rather than filtering on ST_Distance for radius queries
Known gotchas
ST_Distance does not use the spatial index — only ST_DWithin (and similar index-aware predicates) do
forgetting to reproject a geometry column before ST_DWithin silently returns degree-scaled (wrong-magnitude) results instead of an error
Give your agent this knowledge — and 15,500+ more routes
One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp
Need this verified for your stack — or a route we don't have yet?