[postgis-users] Buffer vs. Expand

CYW cyw at dls.net
Wed May 31 19:23:58 PDT 2006


Many thanks.
_cyw_

-----Original Message-----
From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of Paul
Ramsey
Sent: Wednesday, May 31, 2006 7:59 PM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] Buffer vs. Expand

You have fallen into the "I need a buffer" trap.  You want a distance test:

SELECT AsText(geom) FROM point_table 
WHERE
  geom && Expand(GeometryFromText('POINT(10000 20000)',2769),900) 
AND
  Distance(geom,GeometryFromText('POINT(10000 20000)',2769) < 900

The first clause forces an index scan, followed by the exact test for
falling
within the desired range.  In specific answer to your question, Expand()
creates
an expanded bounding box, while Buffer() creates an expanded feature.
Expand()
is great for creating expanded bounding boxes for index filters as shown
above,
but not useful for much else.

P

PS - You don't generally need a buffer unless you are going to actually do
something with the buffer geometry later (like intersect it with something
else
to make a new geometry).

Quoting CYW <cyw at dls.net>:

> I need to find points that is within a certain range of a given point.
> Initially I tried a query below:
> 
> SELECT AsText(geom) from point_table where geom &&
>         Buffer(GeometryFromText('POINT(10000 20000 )', 2769),900));
> 
> Then I noticed that I should also be able to use another function Expand
> instead of Buffer.
> 
> Reading the manual, I can't tell which one is better here.
> 
> Additionally, is there a function that can give me the closest point or
how
> should I formulate a query for that?
> 
> Any suggestions?
> 
> Thanks,
> _cyw_
> 
> 
> 
> Manual excerpts below.
> ------------------------------------
> Buffer(geometry, double, [integer])
> 
>     Returns a geometry that represents all points whose distance from this
> Geometry is less than or equal to distance. Calculations are in the
Spatial
> Reference System of this Geometry. The optional third parameter sets the
> number of segment used to approximate a quarter circle (defaults to 8).
> 
> expand(geometry, float)
> 
>     This function returns a bounding box expanded in all directions from
the
> bounding box of the input geometry, by an amount specified in the second
> argument. Very useful for distance() queries, to add an index filter to
the
> query.
> 
> 
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
> 




_______________________________________________
postgis-users mailing list
postgis-users at postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users





More information about the postgis-users mailing list