Skip site navigation (1) Skip section navigation (2)

Re: how to check if a point is contained in a polygon ?

From: Julien Cigar <jcigar(at)ulb(dot)ac(dot)be>
To: Richard Huxton <dev(at)archonet(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: how to check if a point is contained in a polygon ?
Date: 2008-05-07 17:00:23
Message-ID: 1210179623.2585.19.camel@frodon.be-bif.ulb.ac.be (view raw or flat)
Thread:
Lists: pgsql-sql
Oops, you're right .. I'm still running 8.1 and I missed this note in
the documentation :

"Note: Before PostgreSQL 8.2, the containment operators @> and <@ were
respectively called ~ and @. These names are still available, but are
deprecated and will eventually be retired."

thanks

On Wed, 2008-05-07 at 15:38 +0100, Richard Huxton wrote:
> Julien Cigar wrote:
> > Hello,
> > 
> > I'm busy to work on an application where the user can select (with
> > precision) an area on a map (for example the contours of a lake) and I
> > have to retrieve all the data (specimen observations) within this area. 
> > 
> > I have a list of coordinates pair [(lat1, long1), (lat2, long2), (lat3,
> > long3), (..., ...)] which form a polygon. In my database every specimen
> > has a pair of coordinates where it has been collected.
> 
> Are you familiar with the PostGIS project - if you're doing a lot of 
> this, it might be worthwhile looking into.
> 
> http://www.postgis.org/
> 
> > Is there an SQL function to check if a point is contained in a polygon
> > shape (before I start to write my own) ?
> > 
> > I tried something like :
> > 
> > rodentia=> select point '(-8,25)' <@ polygon
> > '((-3,10),(8,18),(-3,30),(-10,20))';
> 
> Works both ways around here:
> 
> SELECT point '(-8,25)' <@ polygon '((-3,10),(8,18),(-3,30),(-10,20))';
> 
> SELECT polygon '((-3,10),(8,18),(-3,30),(-10,20))' @> point '(-8,25)';
> 
> I'm running 8.3, but it seems to be in 8.2 too.
> 
> Try \do '<@' from psql to see what operators are available.
> 
-- 
Julien Cigar
Belgian Biodiversity Platform
http://www.biodiversity.be
Université Libre de Bruxelles (ULB)
Campus de la Plaine CP 257
Bâtiment NO, Bureau 4 N4 115C (Niveau 4)
Boulevard du Triomphe, entrée ULB 2
B-1050 Bruxelles
Mail: jcigar(at)ulb(dot)ac(dot)be
@biobel: http://biobel.biodiversity.be/person/show/471
Tel : 02 650 57 52


In response to

pgsql-sql by date

Next:From: Matthew T. O'ConnorDate: 2008-05-08 03:28:10
Subject: Joining with result of a plpgsql function
Previous:From: Julien CigarDate: 2008-05-07 16:25:36
Subject: how to check if a point is contained in a polygon ?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group