From: Bborie Park Date: Sun, 27 Jul 2014 17:06:54 +0000 (+0000) Subject: shortcut ST_Clip if clipping geometry extent fully contains raster extent. Ticket... X-Git-Tag: 2.2.0rc1~933 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d053d965951498ceba9ac8cb4366f2d69a768583;p=postgis shortcut ST_Clip if clipping geometry extent fully contains raster extent. Ticket #2829 git-svn-id: http://svn.osgeo.org/postgis/trunk@12833 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/NEWS b/NEWS index 890f3b2ff..b59c50e2f 100644 --- a/NEWS +++ b/NEWS @@ -56,6 +56,8 @@ PostGIS 2.2.0 - #2754, SFCGAL can now be installed with CREATE EXTENSION Vincent Mora (Oslandia) - #2828, Convert ST_Envelope(raster) from SQL to C + - #2829, Shortcut ST_Clip(raster) if geometry fully contains the raster + and no NODATA specified * Bug Fixes * diff --git a/raster/rt_pg/rtpostgis.sql.in b/raster/rt_pg/rtpostgis.sql.in index f90eee62b..205bd907e 100644 --- a/raster/rt_pg/rtpostgis.sql.in +++ b/raster/rt_pg/rtpostgis.sql.in @@ -6602,7 +6602,7 @@ CREATE AGGREGATE st_union(raster, text) ( -- ST_Clip ----------------------------------------------------------------------- -CREATE OR REPLACE FUNCTION st_clip( +CREATE OR REPLACE FUNCTION _st_clip( rast raster, nband integer[], geom geometry, nodataval double precision[] DEFAULT NULL, crop boolean DEFAULT TRUE @@ -6611,6 +6611,25 @@ CREATE OR REPLACE FUNCTION st_clip( AS 'MODULE_PATHNAME', 'RASTER_clip' LANGUAGE 'c' IMMUTABLE; +CREATE OR REPLACE FUNCTION st_clip( + rast raster, nband integer[], + geom geometry, + nodataval double precision[] DEFAULT NULL, crop boolean DEFAULT TRUE +) + RETURNS raster + AS $$ + DECLARE + contains boolean; + BEGIN + -- short-cut if geometry's extent fully contains raster's extent + IF (nodataval IS NULL OR array_length(nodataval, 1) < 1) AND geom ~ ST_Envelope(rast) THEN + RETURN rast; + END IF; + + RETURN _ST_Clip($1, $2, $3, $4, $5); + END; + $$ LANGUAGE 'plpgsql' IMMUTABLE; + CREATE OR REPLACE FUNCTION st_clip( rast raster, nband integer, geom geometry,