1

How to find all the polygons inside of a polygon? I tried ST_Intersects and ST_Contains but they are booleans variables. I have a list of polygons in WKT format, so I am trying to pull all the polygons given a region in their WKT format.

Does anyone have an idea how to approach this?

select geom from polygon where 
ST_Intersects(ST_GeographyFromText
('POLYGON((210000 2400000, 300000 2300000, 330000 3708400, 210000 2400000))'), 
polygon.geom);
  • Please share the SQL you tried. – WKT Jun 7 '16 at 12:54
  • @WKT I added in the SQL. Please take a look. – moffittime Jun 7 '16 at 13:31
  • What is the end result you are looking for? Have you looked at ST_Intersection? – kflaw Jun 7 '16 at 14:25
  • The result of your ST_geografyFromText is "POLYGON((120 -60,120 -40,-120 40,120 -60))" . Is it correct ? This cast is probably not what you want... – WKT Jun 7 '16 at 14:34
  • @kflaw the end result should be a list of polygons in WKT formats that are inside of the given polygon. – moffittime Jun 7 '16 at 14:36
2

You are missing ST_AsText, as @WKT mentions above. This should work for you:

select ST_AsText(geom) from polygon
where ST_Intersects(ST_GeographyFromText
('POLYGON((210000 2400000, 300000 2300000, 330000 3708400, 210000 2400000))'), 
polygon.geom);
  • why the downvote? I tested this with my own data (using different coordinates) and it worked. – kflaw Jun 7 '16 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.