[postgis-users] geos based spatial queries
David Blasby
dblasby at refractions.net
Thu Nov 20 13:37:22 PST 2003
strk wrote:
> dblasby wrote:
>
>>Peter Aberline wrote:
>>
>>
>>>select count(*)
>>>from points
>>>where within(points.the_geom, (select the_geom from states where
>>>state_name = 'BigState')) = true;
>>
>>try:
>>
>>SELECT count(*) FROM points WHERE
>> within(points.the_geom, (select the_geom from states where
>>state_name = 'BigState') AND
>>points.the_geom && (select the_geom from states where state_name =
>>'BigState')
>
>
> I'd try:
>
> SELECT count(*) FROM points p, states s
> WHERE s.state_name = 'BigState' -- a btree here
> AND p.the_geom && s.the_geom -- a GiST here
> AND within(p.the_geom, s.the_geom); -- is really needed ?
>
> --strk;
The within() is important - "&&" is only bounding box, while 'within()'
is peformed on the actual geometry.
You could also do a "distance(p.the_geom,s.the_geom) <=0" instead of the
within.
dave
More information about the postgis-users
mailing list