Re: PostGIS return multiple points - Mailing list pgsql-general

From Szymon Guz
Subject Re: PostGIS return multiple points
Date
Msg-id AANLkTik9N2+QNY+BMcTbhh0mEZ29fLjsS8bqcAVunfV4@mail.gmail.com
Whole thread Raw
In response to PostGIS return multiple points  (trevor1940 <antonys@nsom.org.uk>)
List pgsql-general


On 28 October 2010 10:00, trevor1940 <antonys@nsom.org.uk> wrote:

Hi

I have a PostGIS table and I wish to get the location/name of multiple
points at once the command for selecting one point is

select PolyName from MyPolygones where st_Contains(the_geom,
GeomFromText('point($LAT $LONG)4326');

where $LAT $LONG are perl varables
So how can i do this if iI have 100 points without hitting the database 100
times?


hi,
Hi,
you could create one query using MULTIPOINT, something like:

ST_MPointFromText('MULTIPOINT($LAT1 $LONG1, $LAT2 $LONG2 ... $LAT100 $LONG100 )', 4326)

now you could find all polygons:

SELECT DISTINCT PolyName 
FROM MyPolygones 
WHERE ST_INTERSECTS(the_geom, 
    ST_MPointFromText('MULTIPOINT($LAT1 $LONG1, $LAT2 $LONG2 ... $LAT100 $LONG100 )', 4326)
);

where:
    ST_INTERSECTS returns true if geometries have any common point
    ST_MPointFromText creates brand new and shiny new MULTIPOINT geometry containing all the points

regards
Szymon
 

pgsql-general by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: moving database objects from one schema to other
Next
From: akp geek
Date:
Subject: Re: moving database objects from one schema to other