| 1 | = Examples Inside Polygon = |
| 2 | |
| 3 | |
| 4 | '''Reinhold Stahlmann [http://postgis.refractions.net/pipermail/postgis-users/2004-January/003867.html asks]:''' |
| 5 | |
| 6 | "How can I built an (OGC-conforming) SQL query with PostGIS to select all Points of a given Point-Dataset who have their Geometry within a specific Polygon-Geometry chosen by a label-Field of the Polygon? For example: All PostGIS-Users.name (Point-Geometry) within 'Sweden' (Polygon-Geometry)" |
| 7 | |
| 8 | '''Chris Hodgson [http://postgis.refractions.net/pipermail/postgis-users/2004-January/003868.html answers]:''' |
| 9 | |
| 10 | {{{ |
| 11 | SELECT user.name, user.the_geom |
| 12 | FROM user |
| 13 | WHERE |
| 14 | within( user.the_geom, |
| 15 | (SELECT the_geom |
| 16 | FROM Country |
| 17 | WHERE Country.name = 'Sweden') |
| 18 | ) |
| 19 | AND |
| 20 | the_geom && |
| 21 | (SELECT user.the_geom |
| 22 | FROM Country |
| 23 | WHERE Country.name = 'Sweden') |
| 24 | |
| 25 | }}} |
| 26 | |
| 27 | |
| 28 | '''Paul Ramsey tries a different approach:''' |
| 29 | |
| 30 | |
| 31 | {{{ |
| 32 | SELECT user.name, user.the_geom |
| 33 | FROM user, |
| 34 | (SELECT the_geom |
| 35 | FROM Country |
| 36 | WHERE Country.name = 'Sweden') as country |
| 37 | WHERE |
| 38 | within( user.the_geom, country.the_geom ) |
| 39 | AND |
| 40 | the_geom && country.the_geom |
| 41 | |
| 42 | }}} |