[postgis-users] point in polygon or equivalent

Michael Fuhr mike at fuhr.org
Mon Jan 2 20:01:09 PST 2006


On Mon, Jan 02, 2006 at 07:17:00PM -0800, Mark Wright wrote:
> What is the benefit to using the contains() or within() functions
> rather than the ~ operator? I've tested both and they give the same
> results in the same amount of time (plus or minus about 20
> miliseconds).

The operator checks bounding boxes; the function checks the
geometries themselves.  Example:

  +-----------+
  |           | A
  |   +-------+
  |   |  +--+
  |   |  |  | B
  |   |  +--+
  +---+

A's bounding box contains B's bounding box so A ~ B would be true,
but A doesn't actually contain B so contains(A, B) would be false.
Bounding box searches can use an index so they're a fast way to
find possible matches; the function identifies matches with certainty
but it's more expensive, especially for complex geometries, so you
want to avoid calling it when it's known that it will return false.

-- 
Michael Fuhr



More information about the postgis-users mailing list