wiki:UsersWikiExamplesInsidePolygon

Examples Inside Polygon

Reinhold Stahlmann asks:

"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)"

Chris Hodgson answers:

SELECT user.name, user.the_geom
FROM user
WHERE
  within( user.the_geom,
   (SELECT the_geom
    FROM Country
    WHERE Country.name = 'Sweden')
  )
  AND
  the_geom &&
  (SELECT user.the_geom
   FROM Country
   WHERE Country.name = 'Sweden')

Paul Ramsey tries a different approach:

SELECT user.name, user.the_geom
FROM user,
 (SELECT the_geom
  FROM Country
  WHERE Country.name = 'Sweden') as country
WHERE
  within( user.the_geom, country.the_geom )
 AND
  the_geom && country.the_geom

Last modified 16 years ago Last modified on 04/14/09 09:13:34
Note: See TracWiki for help on using the wiki.