<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Courier New";}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:1937055624;
        mso-list-template-ids:-1771766272;}
@list l0:level1
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:.5in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level2
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:1.0in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:"Courier New";
        mso-bidi-font-family:"Times New Roman";}
@list l0:level3
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:1.5in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Wingdings;}
@list l0:level4
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:2.0in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Wingdings;}
@list l0:level5
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:2.5in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Wingdings;}
@list l0:level6
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:3.0in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Wingdings;}
@list l0:level7
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:3.5in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Wingdings;}
@list l0:level8
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:4.0in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Wingdings;}
@list l0:level9
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:4.5in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Wingdings;}
ol
        {margin-bottom:0in;}
ul
        {margin-bottom:0in;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><b>Hi Steve,<o:p></o:p></b></p><p class=MsoNormal><b><o:p> </o:p></b></p><p class=MsoNormal>I tried that<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><pre>select powerplants.gid, plantname<o:p></o:p></pre><pre>   from powerplants, pca_huc<o:p></o:p></pre><pre>  where state = 'CA'<o:p></o:p></pre><pre>        AND NOT st_contains(pca_huc.geom,powerplants.geom)<o:p></o:p></pre><pre>  order by powerplants.gid;<o:p></o:p></pre><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal> but got some 44,000 rows in the result. There are 1477 powerplants (points) and 299 pca_huc polygons. The powerplants don’t all fall inside the polygons, and I want to get the list of those that fall outside.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>In a desktop gis I can quickly select and see that 102 powerplants fall outside: so I should not be getting 44,0000 rows in the result…<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>V<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><b><o:p> </o:p></b></p><p class=MsoNormal><b><o:p> </o:p></b></p><div class=MsoNormal align=center style='text-align:center'><hr size=2 width="100%" align=center></div><pre>Did you try:<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>select powerplants.gid, plantname<o:p></o:p></pre><pre>   from powerplants, pca_huc<o:p></o:p></pre><pre>  where state = 'CA'<o:p></o:p></pre><pre>        AND NOT st_contains(pca_huc.geom,powerplants.geom)<o:p></o:p></pre><pre>  order by powerplants.gid;<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>This should give you all power plants in CA and not in your contains <o:p></o:p></pre><pre>clause. What is the coverage of pca_huc table? If this covers all of CA <o:p></o:p></pre><pre>then there is not possible result. The would be like say where a=1 and <o:p></o:p></pre><pre>not a=1.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>-Steve W<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>On 9/29/2011 1:21 PM, Vishal Mehta wrote:<o:p></o:p></pre><pre>><i> I have a point layer and a polygon layer. How do I select points that<o:p></o:p></i></pre><pre>><i> are NOT contained within polygons?<o:p></o:p></i></pre><pre>><i><o:p> </o:p></i></pre><pre>><i> For example, this query correctly selects points contained by polygons<o:p></o:p></i></pre><pre>><i><o:p> </o:p></i></pre><pre>><i> --<o:p></o:p></i></pre><pre>><i><o:p> </o:p></i></pre><pre>><i> select powerplants.gid, plantname<o:p></o:p></i></pre><pre>><i><o:p> </o:p></i></pre><pre>><i> from powerplants, pca_huc<o:p></o:p></i></pre><pre>><i><o:p> </o:p></i></pre><pre>><i> where state = 'CA'<o:p></o:p></i></pre><pre>><i><o:p> </o:p></i></pre><pre>><i> AND<o:p></o:p></i></pre><pre>><i><o:p> </o:p></i></pre><pre>><i> st_contains(pca_huc.geom,powerplants.geom)<o:p></o:p></i></pre><pre>><i><o:p> </o:p></i></pre><pre>><i> order by powerplants.gid;<o:p></o:p></i></pre><pre>><i><o:p> </o:p></i></pre><pre>><i> --<o:p></o:p></i></pre><pre>><i><o:p> </o:p></i></pre><pre>><i> I tried to get the inverse selection using st_disjoint instead of<o:p></o:p></i></pre><pre>><i> st_contains , but that did not work. I also tried using NOT and EXCEPT<o:p></o:p></i></pre><pre>><i> without success (although I may not have constructed the latter queries<o:p></o:p></i></pre><pre>><i> correctly..)<o:p></o:p></i></pre><pre>><i><o:p> </o:p></i></pre><pre>><i> Thanks!<o:p></o:p></i></pre><pre>><i><o:p> </o:p></i></pre><pre>><i> Vishal</i><o:p></o:p></pre><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><i><a href="http://sei-us.org/about/staff_person/19">Vishal K. Mehta</a>, Ph.D.<o:p></o:p></i></p><p class=MsoNormal><i>Staff Scientist,<o:p></o:p></i></p><p class=MsoNormal><i>Stockholm Environment Institute-US<o:p></o:p></i></p><p class=MsoNormal><i>400 F St, Davis, CA 95616<o:p></o:p></i></p><p class=MsoNormal><i><a href="http://sei-us.org/">http://sei-us.org/</a><o:p></o:p></i></p><p class=MsoNormal><i><o:p> </o:p></i></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p></div></body></html>