<div class="gmail_quote">Hi,
<div><br></div><div>I am using postgis-2.0SVN (revision 7065, I think - I downloaded it on Monday).</div><div><br></div><div>I am doing an analysis in which I need to test 50,000 points in a vector table against a binary raster (with 0 set as NoData and 1 being the area of interest). From what I can find online (Amazon has not sent my copy of Postgis in Action yet), the following is the canonical way of doing this:</div>

<div><br></div><div>select V.id, ST_Intersection(R.rast, V.the_geom) as pts</div><div>from raster R, vector V</div><div>where ST_Intersects(R.rast, V.the_geom)</div><div><br></div><div><div>
All I really need is:</div><div><br></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div><font face="'arial narrow', sans-serif">select V.id</font></div>
</div><div><div><font face="'arial narrow', sans-serif">from raster R, vector V</font></div></div><div><div><div><font face="'arial narrow', sans-serif">where ST_Intersects(R.rast, V.the_geom)</font></div>

</div></div></blockquote><div><div><br></div><div>and I was hoping that it would be a faster way to do this.</div></div><div><br></div><div>However, when I run a test on my data, however, with "LIMIT 10", the equivalent code takes 24,926 ms. </div>

<div><br></div><div>Doing something more complicated, like this (because ST_Intersection seems to return empty geometries for the NoData areas):</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px">

<div><font face="'arial narrow', sans-serif">select V.id, ST_IsEmpty((ST_Intersection(R.rast, V.the_geom)).geom) as ptest</font></div><div><font face="'arial narrow', sans-serif">from raster R, vector V</font></div>

<div><font face="'arial narrow', sans-serif">LIMIT 10;</font></div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>-- then I filter these results for ptest = FALSE</div>
</blockquote><div><br></div><div>takes 589 ms.</div><div><br></div><div>I tried scaling this up to LIMIT 100 (359,304  and 6,444 ms, respectively) and 1000 (1,980,397 and 61,628 ms). </div><div><br></div><div>This is a huge difference. Is this the best way to use ST_Intersection/ST_Intersects? Am I doing something wrong here? Would I be better off converting this to a vector? Any tips on optimizing this query would be appreciated (I have to run the same query against several different rasters, plus I want to understand how to do this right).</div>
<div><br></div><div>JP</div></div>