[postgis-devel] [postgis-users] Raster clipping vs. intersection

Bborie Park dustymugs at gmail.com
Sun Dec 1 16:07:01 PST 2013


The behavior of ST_Clip and ST_Intersection for raster and geometry are
very different.

ST_Intersection() converts the raster into a set of geometries and then
returns the intersection of the input geometry and the raster's geometries.

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.

So, their answers will differ.

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.

-bborie


On Sun, Dec 1, 2013 at 3:35 PM, Paragon Corporation <lr at pcorp.us> wrote:

> In doing some tests I was somewhat surprised to find out that doing an
> ST_Clip operation first before an ST_Intersection operation is
> significantly
> faster than just doing a straight ST_Intersection.
>
> Unfortunately the answers are different and I'm not sure what I am losing.
>
> I'm guessing with ST_Clip when a pixel only partially intersects a geometry
> it is thrown out and with ST_Intersection if a pixel intersects a geometry
> it is included.  Is that correct.
>
> This is running in PostGIS 2.1.1 (don't have 2.0 readily set up to compare)
>
>
> For example:
> -- gives an answer of 1258.409 but returns it in 14,431 ms  (without
> aggregation returns 307 rows)
>
> SELECT SUM((gval).val* ST_Area((gval).geom))
>      / ST_Area(ST_Union((gval).geom)) As avg_elesqm
> FROM (
> SELECT ST_Intersection(rast,1,buf.geom) As gval
> FROM kauai
>      INNER JOIN
> (SELECT ST_Buffer(
>       ST_GeomFromText('POINT(444205 2438785)',26904),
>         100) As geom
> ) As buf ON
>     ST_Intersects(rast,buf.geom)) As foo;
>
>
> -- The same operation but adding a ST_Clip step --
> For example:
> -- gives an answer of 1236.834495 but returns it in 511 ms (without
> aggregation returns 281 rows)
>
> SELECT SUM((gval).val* ST_Area((gval).geom))
>      / ST_Area(ST_Union((gval).geom)) As avg_elesqm
> FROM (
> SELECT ST_Intersection(ST_Clip(rast,buf.geom),1,buf.geom) As gval
> FROM kauai
>      INNER JOIN
> (SELECT ST_Buffer(
>       ST_GeomFromText('POINT(444205 2438785)',26904),
>         100) As geom
> ) As buf ON
>     ST_Intersects(rast,buf.geom)) As foo;
>
>
>
> Thanks,
> Regina
>
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20131201/08734e28/attachment.html>


More information about the postgis-devel mailing list