[postgis-users] Returning polygons if any of a polygon input points lie in the polygons

Hugues François hugues.francois at irstea.fr
Tue Nov 18 07:52:05 PST 2014


Hi,

 

I think ST_Intersects will meet your needs :

 

SELECT  zone,gid,state,name,ST_Asgeojson( geom ) 

FROM polys 

WHERE ST_Intersects(ST_GeomFromText('POLYGON((-109 42,-108 42, -108 43; -109 43, -109 42))', 4269), geom)

 

Hugues.

 

 

Hugues François

Tourisme et systèmes d’information

Irstea – DTM

 

+33 (0)4.76.76.27.44

+33 (0)6.77.66.21.31

 

De : postgis-users-bounces at lists.osgeo.org [mailto:postgis-users-bounces at lists.osgeo.org] De la part de Joseph Spenner
Envoyé : mardi 18 novembre 2014 16:44
À : PostGIS Users Discussion
Objet : Re: [postgis-users] Returning polygons if any of a polygon input points lie in the polygons

 

Something I did notice though-- it seems that if the input polygon completely surrounds a polygon stored in my database, it is not included in the result.  I read something about this here: http://postgis.net/docs/ST_Overlaps.html

 

  "Returns TRUE if the Geometries "spatially overlap". By that we mean they intersect, but one does not completely contain another."

 

I do need the polygons which are completely contained as well.  Can this be done?

 

Thanks again for the help.  I'm getting there!

 

Regards,

Joseph Spenner

 

  

 

 

 

________________________________

From: Joseph Spenner <joseph85750 at yahoo.com>
To: Rémi Cura <remi.cura at gmail.com>; PostGIS Users Discussion <postgis-users at lists.osgeo.org> 
Sent: Tuesday, November 18, 2014 8:35 AM
Subject: Re: [postgis-users] Returning polygons if any of a polygon input points lie in the polygons

 

Rémi:

  Yes, that worked perfectly.  Thanks!

  My input poly will be stored in another database (maybe just another table).   It would be nice to perform the query all on 1 line (get the poly and use it for the query), but I can query the first table first to get the input poly, then use that for the 2nd query without too much difficulty.


Thanks again for the responses!

 

Regards,

Joseph Spenner

 

 

If life gives you lemons, keep them-- because hey.. free lemons. 

 


"~heart~ Sticker"  fixer:  http://microflush.org/stuff/stickers/heartFix.html 

 

 

 

 

________________________________

From: Rémi Cura <remi.cura at gmail.com>
To: PostGIS Users Discussion <postgis-users at lists.osgeo.org> 
Cc: Joseph Spenner <joseph85750 at yahoo.com> 
Sent: Tuesday, November 18, 2014 4:20 AM
Subject: Re: [postgis-users] Returning polygons if any of a polygon input points lie in the polygons

 

Something like this?



 

SELECT  zone,gid,state,name,ST_Asgeojson( geom ) 



FROM polys 

WHERE ST_Overlaps(ST_GeomFromText('POLYGON((-109 42,-108 42, -108 43; -109 43, -109 42))', 4269), geom)=TRUE;

 

Cheers,
Rémi-C

 

2014-11-18 9:00 GMT+01:00 Hugues François <hugues.francois at irstea.fr>:



 

Hello,

 

Maybe I don’t understand your problem very well but I think your query for points should work with a polygon using ST_GeomFromText (http://www.postgis.org/docs/ST_GeomFromText.html) for your input polygon or a subquery if it stored into your DB.

 

Hugues.

 

De : postgis-users-bounces at lists.osgeo.org [mailto:postgis-users-bounces at lists.osgeo.org] De la part de Joseph Spenner
Envoyé : lundi 17 novembre 2014 22:35
À : PostGIS Users Discussion
Objet : [postgis-users] Returning polygons if any of a polygon input points lie in the polygons

 

Hello, I'm trying to perform a query which will return any polygons which have any points in common with an input polygon.

 

So, if I have Polygon A.

In my database, I have several other polygons stored.

 

I want to submit a query with Polygon A as the input, which will return all of the polygons in my database which have any points in common with Polygon A.

 

Can this be done?


I found this:

http://postgis.net/docs/ST_Overlaps.html

 

But from what I can tell, it only returns a T or F.   I need to fetch the actual polygons if T.

 

I'm currently able to query with points as input:

 

select zone,gid,state,name,ST_Asgeojson( geom ) from polys where ST_Intersects(ST_PointFromText('POINT(-109 42)', 4269), geom);

 

But now I have a need to use polygons as input.

 

Any help would be great.

 

Thanks!

 

Regards,

Joseph Spenner

 

 


_______________________________________________
postgis-users mailing list
postgis-users at lists.osgeo.org
http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20141118/8bd0fc5e/attachment.html>


More information about the postgis-users mailing list