[postgis-users] Raster clipping vs. intersection

49 views
Skip to first unread message

Paragon Corporation

unread,
Dec 1, 2013, 6:35:58 PM12/1/13
to PostGIS Users Discussion, PostGIS Development Discussion
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
postgi...@lists.osgeo.org
http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users

Bborie Park

unread,
Dec 1, 2013, 7:07:01 PM12/1/13
to PostGIS Users Discussion, PostGIS Development Discussion
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
Reply all
Reply to author
Forward
0 new messages