Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using PostGIS 2.0.1 and need to determine whether a circle (center + radius) intersects a county boundary (polygon).

The query I'm using is this:

SELECT DISTINCT( FROM siteareas_poly sa, userlocations ul, 
            clienttypes ct INNER JOIN users_clienttypes uct on = uct.clienttype_id 
            INNER JOIN users u on uct.user_id = 
            WHERE = 'concord' and = 2 
            AND ul.geog_lnglat is not null
            AND  ST_Intersects(st_exteriorring(sa.boundary), ST_BUFFER(ul.geog_lnglat,ul.radius_km * 1000)::geometry)

where the ul.geog_lnglat is a


and the sa.boundary is


I've tried a few variations on this and always gotten no results, when I expect to get at least one, as I have a row in userlocations that lies in that county (by zip lookup).

Am I making any glaring errors in my approach?

share|improve this question
up vote 2 down vote accepted

Use ST_DWithin. You will need to convert both to either planer geometry or geography types.

For example, to use ST_DWithin on geography inputs:

FROM ...
  AND ST_DWithin(ST_Transform(sa.boundary, 4326)::geography,
                 ul.radius_km * 1000);
share|improve this answer
Thanks Mike - I hadn't noticed the alternate parameters for ST_DWithin(). I tried your suggestion but got ERROR: Coordinate values are out of range [-180 -90, 180 90] for GEOGRAPHY type - what should I be looking for? – TomL Jun 19 '12 at 19:15
Shifted coordinates? – Nicklas Avén Jun 20 '12 at 6:08
@TomL I'm guessing the spatial reference (SRID) for your sa.boundary is not WGS84 Long/Lat, so you need to transform it; see the updated answer. – Mike T Jun 20 '12 at 7:17
Thanks again - this answer has actually helped me think more clearly about the geometry of the question. Of course it's just a question of the point being within radius distance of the geometry - no need for a circle to be drawn. – TomL Jun 20 '12 at 13:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.