<div dir="ltr">The behavior of ST_Clip and ST_Intersection for raster and geometry are very different.<div><br></div><div>ST_Intersection() converts the raster into a set of geometries and then returns the intersection of the input geometry and the raster's geometries.</div>

<div><br></div><div>ST_Clip() does the exact opposite. The input geometry is converted to a raster after which the geometry's raster is passed into a map-algebra operation with the input raster.</div><div><br></div><div>

So, their answers will differ.</div><div><br></div><div>It should be noted that the ST_Clip() operation should be faster as it all parts of it happens in C while the ST_Intersection() bounces back and forth between SQL and C.</div>

<div><br></div><div>-bborie</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Dec 1, 2013 at 3:35 PM, Paragon Corporation <span dir="ltr"><<a href="mailto:lr@pcorp.us" target="_blank">lr@pcorp.us</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In doing some tests I was somewhat surprised to find out that doing an<br>
ST_Clip operation first before an ST_Intersection operation is significantly<br>
faster than just doing a straight ST_Intersection.<br>
<br>
Unfortunately the answers are different and I'm not sure what I am losing.<br>
<br>
I'm guessing with ST_Clip when a pixel only partially intersects a geometry<br>
it is thrown out and with ST_Intersection if a pixel intersects a geometry<br>
it is included.  Is that correct.<br>
<br>
This is running in PostGIS 2.1.1 (don't have 2.0 readily set up to compare)<br>
<br>
<br>
For example:<br>
-- gives an answer of 1258.409 but returns it in 14,431 ms  (without<br>
aggregation returns 307 rows)<br>
<br>
SELECT SUM((gval).val* ST_Area((gval).geom))<br>
     / ST_Area(ST_Union((gval).geom)) As avg_elesqm<br>
FROM (<br>
SELECT ST_Intersection(rast,1,buf.geom) As gval<br>
FROM kauai<br>
     INNER JOIN<br>
(SELECT ST_Buffer(<br>
      ST_GeomFromText('POINT(444205 2438785)',26904),<br>
        100) As geom<br>
) As buf ON<br>
    ST_Intersects(rast,buf.geom)) As foo;<br>
<br>
<br>
-- The same operation but adding a ST_Clip step --<br>
For example:<br>
-- gives an answer of 1236.834495 but returns it in 511 ms (without<br>
aggregation returns 281 rows)<br>
<br>
SELECT SUM((gval).val* ST_Area((gval).geom))<br>
     / ST_Area(ST_Union((gval).geom)) As avg_elesqm<br>
FROM (<br>
SELECT ST_Intersection(ST_Clip(rast,buf.geom),1,buf.geom) As gval<br>
FROM kauai<br>
     INNER JOIN<br>
(SELECT ST_Buffer(<br>
      ST_GeomFromText('POINT(444205 2438785)',26904),<br>
        100) As geom<br>
) As buf ON<br>
    ST_Intersects(rast,buf.geom)) As foo;<br>
<br>
<br>
<br>
Thanks,<br>
Regina<br>
<br>
<br>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a><br>
</blockquote></div><br></div>