Thread: PostGIS return multiple points

PostGIS return multiple points

From
trevor1940
Date:
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?

--
View this message in context:
http://postgresql.1045698.n5.nabble.com/PostGIS-return-multiple-points-tp3240107p3240107.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

Re: PostGIS return multiple points

From
maarten
Date:
hey,

I haven't used postgis yet, however,

assuming the normal rules still apply and st_Contains returns
true/false:

SELECT ... WHERE st_Contains(point1) OR st_Contains(point2) OR ...

or using the IN statement:
SELECT ... WHERE true IN (st_Contains(point1),st_Contains(point2),...)

That should give you a list of all polynames.
The trick is figuring out what polyname goes with which point.  But I
leave that as an exercise to the reader, as it's tea time.

regards,
Maarten

On Thu, 2010-10-28 at 01:00 -0700, trevor1940 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?
>
> --
> View this message in context:
http://postgresql.1045698.n5.nabble.com/PostGIS-return-multiple-points-tp3240107p3240107.html
> Sent from the PostgreSQL - general mailing list archive at Nabble.com.
>


Re: PostGIS return multiple points

From
ludwig@kni-online.de
Date:

Just some thoughts:- create a multipoint with 100 vertices instead of a single point and query once with st_Intersect
- prepare the single-point-query and execute the prepared query 100 times with the changing coordinates

Ludwig



----- Ursprüngliche Nachricht -----
Von: trevor1940
Gesendet: 28.10.10 10:00 Uhr
An: pgsql-general@postgresql.org
Betreff: [GENERAL] PostGIS return multiple points

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? -- View this message in context: http://postgresql.1045698.n5.nabble.com/PostGIS-return-multiple-points-tp3240107p3240107.html Sent from the PostgreSQL - general mailing list archive at Nabble.com. -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general

Re: PostGIS return multiple points

From
Szymon Guz
Date:


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