[postgis-users] Raster clipping vs. intersection
Paragon Corporation
lr at pcorp.us
Sun Dec 1 15:35:58 PST 2013
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
More information about the postgis-users
mailing list