[postgis-users] st_within maddness

Kevin Galligan kg at kagii.com
Fri Jul 24 06:49:02 PDT 2009


I'm sure there's something simple I'm missing here, but we've hit the
"pull hair out" stage, so I'm hoping there's a kind soul out there
that can clear things up.

Here's the summary.  I have made a large grid of boxes, which are
represented as polygons.  I'd like to pick a center point, "draw" a
circle, and select all boxes that fall completely within that circle.
It seems like it should be pretty simple, and it looks like all the
parts line up, but the select never returns anything.

Here's the simplest example I can do to show what's not working...

--Create box table, 900913 projection, the "google mercator" if you
will, and insert a single box, 100 meters by 100 meters
create table rresp.testwithin(id int);
SELECT AddGeometryColumn ('rresp','testwithin','bbox',900913,'POLYGON',2);
insert into rresp.testwithin(id, bbox) values(1,
ST_SetSRID(ST_MakeBox2D(ST_Point(-8232000, 4980000),ST_Point(-8231900,
4980100)),900913));

--Select out the "circle" geometry, just to see that it makes sense.
Notice the center point is the lower left of the box, but the radius
--is significantly bigger than the box, so it *should* fall inside
select asewkt(ST_Buffer(ST_SetSRID(ST_MakePoint(-8232000,
4980000),900913), 500));

--Run query.  Returns nothing.
select asewkt(bbox) from rresp.testwithin where st_within(bbox,
ST_Buffer(ST_SetSRID(ST_MakePoint(-8232000, 4980000),900913), 500));


Any thoughts?  It seems like this should be pretty simple and work,
but I can't get it to return anything.  Using a bigger box instead of
the "circle" works...

select asewkt(bbox) from rresp.testwithin where st_within(bbox,
ST_SetSRID(ST_MakeBox2D(ST_Point(-8233000, 4979000),ST_Point(-8231000,
4981000)),900913));

I'm lost.

Thanks in advance,
-Kevin



More information about the postgis-users mailing list