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

  1. Store or cast points as geography to get distance filtering directly in meters via ST_DWithin(geog_col, point, meters)
  2. 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
  3. Create a GIST index on the column: CREATE INDEX ... USING GIST (geom_or_geog_col)
  4. Use ST_DWithin rather than filtering on ST_Distance for radius queries

Known gotchas

Related routes

Query Convex data using index-backed reads (withIndex, order, take, first, unique) instead of full table scans
docs.convex.dev · 10 steps · unrated
Find points near a location or member in Redis with GEOSEARCH
redis.io · 6 steps · unrated

Give your agent this knowledge — and 18,200+ more routes

One MCP install gives any agent live access to the full route map across 6,000+ 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?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans