]> granicus.if.org Git - postgis/commitdiff
Addition of two-raster ST_Intersection function set in raster-space well as another...
authorBborie Park <bkpark at ucdavis.edu>
Thu, 15 Dec 2011 23:47:25 +0000 (23:47 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Thu, 15 Dec 2011 23:47:25 +0000 (23:47 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8434 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_pg/rtpostgis.sql.in.c
raster/rt_pg/rtpostgis_drop.sql.in.c
raster/test/regress/Makefile.in
raster/test/regress/rt_intersection.sql [new file with mode: 0644]
raster/test/regress/rt_intersection_expected [new file with mode: 0644]

index a29500a20b25d3597b206276ead16434c350d008..2530575ba2704ec04d705c0d0b85b9e17e8ef97e 100644 (file)
@@ -3218,15 +3218,144 @@ CREATE OR REPLACE FUNCTION st_intersection(geomin geometry, rast raster, band in
        $$
        LANGUAGE 'plpgsql' IMMUTABLE STRICT;
 
-CREATE OR REPLACE FUNCTION st_intersection(rast raster, geom geometry)
-       RETURNS SETOF geomval
-       AS $$ SELECT (gv).geom, (gv).val FROM st_intersection($2, $1, 1) gv; $$
-       LANGUAGE SQL IMMUTABLE STRICT;
+-----------------------------------------------------------------------
+-- ST_Intersection (2-raster in raster space)
+-----------------------------------------------------------------------
+
+CREATE OR REPLACE FUNCTION _st_intersection(
+       rast1 raster, band1 int,
+       rast2 raster, band2 int,
+       extenttype text DEFAULT 'INTERSECTION',
+       returnband text DEFAULT 'BOTH',
+       otheruserfunc regprocedure DEFAULT NULL
+)
+       RETURNS raster
+       AS $$
+       DECLARE
+               rtn raster;
+               _returnband text;
+       BEGIN
+               -- returnband
+               _returnband := upper(returnband);
+               IF _returnband NOT IN ('FIRST', 'SECOND', 'BOTH', 'OTHER') THEN
+                       RAISE EXCEPTION 'Unknown value provided for returnband: %', returnband;
+                       RETURN NULL;
+               END IF;
+
+               -- returnband is OTHER, otheruserfunc provided?
+               IF _returnband = 'OTHER' AND otheruserfunc IS NULL THEN
+                       RAISE EXCEPTION 'Function must be provided for otheruserfunc if return band is OTHER';
+                       RETURN NULL;
+               END IF;
+
+               rtn := NULL;
+               CASE
+                       WHEN _returnband = 'FIRST' THEN
+                               rtn := ST_MapAlgebraExpr(rast1, band1, rast2, band2, 'rast1', NULL, extenttype);
+                       WHEN _returnband = 'SECOND' THEN
+                               rtn := ST_MapAlgebraExpr(rast2, band2, rast1, band1, 'rast1', NULL, extenttype);
+                       WHEN _returnband = 'OTHER' THEN
+                               rtn := ST_MapAlgebraFct(rast1, band1, rast2, band2, otheruserfunc, NULL, extenttype);
+                       ELSE -- BOTH
+                               rtn := ST_MapAlgebraExpr(rast1, band1, rast2, band2, 'rast1', NULL, extenttype);
+                               rtn := ST_AddBand(rtn, ST_MapAlgebraExpr(rast2, band2, rast1, band1, 'rast1', NULL, extenttype));
+               END CASE;
+
+               RETURN rtn;
+       END;
+       $$ LANGUAGE 'plpgsql' STABLE;
+
+CREATE OR REPLACE FUNCTION st_intersection(
+       rast1 raster, band1 int,
+       rast2 raster, band2 int,
+       returnband text DEFAULT 'BOTH',
+       otheruserfunc regprocedure DEFAULT NULL
+)
+       RETURNS raster AS
+       $$ SELECT _st_intersection($1, $2, $3, $4, 'INTERSECTION', $5, $6) $$
+       LANGUAGE 'sql' STABLE;
+
+CREATE OR REPLACE FUNCTION st_intersection(
+       rast1 raster, band1 int,
+       rast2 raster, band2 int,
+       otheruserfunc regprocedure
+)
+       RETURNS raster AS
+       $$ SELECT _st_intersection($1, $2, $3, $4, 'INTERSECTION', 'OTHER', $5) $$
+       LANGUAGE 'sql' STABLE;
+
+CREATE OR REPLACE FUNCTION st_intersection(
+       rast1 raster,
+       rast2 raster,
+       returnband text DEFAULT 'BOTH',
+       otheruserfunc regprocedure DEFAULT NULL
+)
+       RETURNS raster AS
+       $$ SELECT _st_intersection($1, 1, $2, 1, 'INTERSECTION', $3, $4) $$
+       LANGUAGE 'sql' STABLE;
+
+CREATE OR REPLACE FUNCTION st_intersection(
+       rast1 raster,
+       rast2 raster,
+       otheruserfunc regprocedure
+)
+       RETURNS raster AS
+       $$ SELECT _st_intersection($1, 1, $2, 1, 'INTERSECTION', 'OTHER', $3) $$
+       LANGUAGE 'sql' STABLE;
+
+-----------------------------------------------------------------------
+-- ST_Intersection (raster, geometry in raster space)
+-----------------------------------------------------------------------
+
+CREATE OR REPLACE FUNCTION st_intersection(
+       rast1 raster, band1 int,
+       geom geometry,
+       extenttype text DEFAULT 'INTERSECTION',
+       otheruserfunc regprocedure DEFAULT NULL
+)
+       RETURNS raster AS $$
+       DECLARE
+               rtn raster;
+       BEGIN
+               rtn := NULL;
+
+               IF $5 IS NULL THEN
+                       rtn := _st_intersection($1, $2, ST_AsRaster($3, $1), 1, $4, 'FIRST');
+               ELSE
+                       rtn := _st_intersection($1, $2, ST_AsRaster($3, $1), 1, $4, 'OTHER', $5);
+               END IF;
 
-CREATE OR REPLACE FUNCTION st_intersection(rast raster, band integer, geom geometry)
-       RETURNS SETOF geomval
-       AS $$ SELECT (gv).geom, (gv).val FROM st_intersection($3, $1, $2) gv; $$
-       LANGUAGE SQL IMMUTABLE STRICT;
+               RETURN rtn;
+       END;
+       $$ LANGUAGE 'plpgsql' STABLE;
+
+CREATE OR REPLACE FUNCTION st_intersection(
+       rast1 raster, band1 int,
+       geom geometry,
+       otheruserfunc regprocedure
+)
+       RETURNS raster AS
+       $$ SELECT st_intersection($1, $2, $3, 'INTERSECTION', $4) $$
+       LANGUAGE 'sql' STABLE;
+
+CREATE OR REPLACE FUNCTION st_intersection(
+       rast1 raster,
+       geom geometry,
+       extenttype text DEFAULT 'INTERSECTION',
+       otheruserfunc regprocedure DEFAULT NULL
+)
+       RETURNS raster AS
+       $$ SELECT st_intersection($1, 1, $2, $3, $4) $$
+       LANGUAGE 'sql' STABLE;
+
+CREATE OR REPLACE FUNCTION st_intersection(
+       rast1 raster,
+       geom geometry,
+       otheruserfunc regprocedure
+)
+       RETURNS raster AS
+       $$ SELECT st_intersection($1, 1, $2, 'INTERSECTION', $3) $$
+       LANGUAGE 'sql' STABLE;
 
 -----------------------------------------------------------------------
 -- st_union aggregate
@@ -4142,10 +4271,10 @@ CREATE OR REPLACE FUNCTION AddRasterConstraints (
                                        WHEN kw = 'srid' THEN
                                                RAISE NOTICE 'Adding SRID constraint';
                                                rtn := _add_raster_constraint_srid(schema, $2, $3);
-                                       WHEN kw = 'scale_x' OR kw = 'scalex' THEN
+                                       WHEN kw IN ('scale_x', 'scalex') THEN
                                                RAISE NOTICE 'Adding scale-X constraint';
                                                rtn := _add_raster_constraint_scale(schema, $2, $3, 'x');
-                                       WHEN kw = 'scale_y' OR kw = 'scaley' THEN
+                                       WHEN kw IN ('scale_y', 'scaley') THEN
                                                RAISE NOTICE 'Adding scale-Y constraint';
                                                rtn := _add_raster_constraint_scale(schema, $2, $3, 'y');
                                        WHEN kw = 'scale' THEN
@@ -4153,10 +4282,10 @@ CREATE OR REPLACE FUNCTION AddRasterConstraints (
                                                rtn := _add_raster_constraint_scale(schema, $2, $3, 'x');
                                                RAISE NOTICE 'Adding scale-Y constraint';
                                                rtn := _add_raster_constraint_scale(schema, $2, $3, 'y');
-                                       WHEN kw = 'blocksize_x' OR kw = 'blocksizex' OR kw = 'width' THEN
+                                       WHEN kw IN ('blocksize_x', 'blocksizex', 'width') THEN
                                                RAISE NOTICE 'Adding blocksize-X constraint';
                                                rtn := _add_raster_constraint_blocksize(schema, $2, $3, 'width');
-                                       WHEN kw = 'blocksize_y' OR kw = 'blocksizey' OR kw = 'height' THEN
+                                       WHEN kw IN ('blocksize_y', 'blocksizey', 'height') THEN
                                                RAISE NOTICE 'Adding blocksize-Y constraint';
                                                rtn := _add_raster_constraint_blocksize(schema, $2, $3, 'height');
                                        WHEN kw = 'blocksize' THEN
@@ -4164,19 +4293,19 @@ CREATE OR REPLACE FUNCTION AddRasterConstraints (
                                                rtn := _add_raster_constraint_blocksize(schema, $2, $3, 'width');
                                                RAISE NOTICE 'Adding blocksize-Y constraint';
                                                rtn := _add_raster_constraint_blocksize(schema, $2, $3, 'height');
-                                       WHEN kw = 'same_alignment' OR kw = 'samealignment' OR kw = 'alignment' THEN
+                                       WHEN kw IN ('same_alignment', 'samealignment', 'alignment') THEN
                                                RAISE NOTICE 'Adding alignment constraint';
                                                rtn := _add_raster_constraint_alignment(schema, $2, $3);
-                                       WHEN kw = 'regular_blocking' OR kw = 'regularblocking' THEN
+                                       WHEN kw IN ('regular_blocking', 'regularblocking') THEN
                                                RAISE NOTICE 'Adding regular blocking constraint';
                                                rtn := _add_raster_constraint_regular_blocking(schema, $2, $3);
-                                       WHEN kw = 'num_bands' OR kw = 'numbands' THEN
+                                       WHEN kw IN ('num_bands', 'numbands') THEN
                                                RAISE NOTICE 'Adding number of bands constraint';
                                                rtn := _add_raster_constraint_num_bands(schema, $2, $3);
-                                       WHEN kw = 'pixel_types' OR kw = 'pixeltypes' THEN
+                                       WHEN kw IN ('pixel_types', 'pixeltypes') THEN
                                                RAISE NOTICE 'Adding pixel type constraint';
                                                rtn := _add_raster_constraint_pixel_types(schema, $2, $3);
-                                       WHEN kw = 'nodata_values' OR kw = 'nodatavalues' OR kw = 'nodata' THEN
+                                       WHEN kw IN ('nodata_values', 'nodatavalues', 'nodata') THEN
                                                RAISE NOTICE 'Adding nodata value constraint';
                                                rtn := _add_raster_constraint_nodata_values(schema, $2, $3);
                                        WHEN kw = 'extent' THEN
@@ -4373,10 +4502,10 @@ CREATE OR REPLACE FUNCTION DropRasterConstraints (
                                        WHEN kw = 'srid' THEN
                                                RAISE NOTICE 'Dropping SRID constraint';
                                                rtn := _drop_raster_constraint_srid(schema, $2, $3);
-                                       WHEN kw = 'scale_x' OR kw = 'scalex' THEN
+                                       WHEN kw IN ('scale_x', 'scalex') THEN
                                                RAISE NOTICE 'Dropping scale-X constraint';
                                                rtn := _drop_raster_constraint_scale(schema, $2, $3, 'x');
-                                       WHEN kw = 'scale_y' OR kw = 'scaley' THEN
+                                       WHEN kw IN ('scale_y', 'scaley') THEN
                                                RAISE NOTICE 'Dropping scale-Y constraint';
                                                rtn := _drop_raster_constraint_scale(schema, $2, $3, 'y');
                                        WHEN kw = 'scale' THEN
@@ -4384,10 +4513,10 @@ CREATE OR REPLACE FUNCTION DropRasterConstraints (
                                                rtn := _drop_raster_constraint_scale(schema, $2, $3, 'x');
                                                RAISE NOTICE 'Dropping scale-Y constraint';
                                                rtn := _drop_raster_constraint_scale(schema, $2, $3, 'y');
-                                       WHEN kw = 'blocksize_x' OR kw = 'blocksizex' OR kw = 'width' THEN
+                                       WHEN kw IN ('blocksize_x', 'blocksizex', 'width') THEN
                                                RAISE NOTICE 'Dropping blocksize-X constraint';
                                                rtn := _drop_raster_constraint_blocksize(schema, $2, $3, 'width');
-                                       WHEN kw = 'blocksize_y' OR kw = 'blocksizey' OR kw = 'height' THEN
+                                       WHEN kw IN ('blocksize_y', 'blocksizey', 'height') THEN
                                                RAISE NOTICE 'Dropping blocksize-Y constraint';
                                                rtn := _drop_raster_constraint_blocksize(schema, $2, $3, 'height');
                                        WHEN kw = 'blocksize' THEN
@@ -4395,19 +4524,19 @@ CREATE OR REPLACE FUNCTION DropRasterConstraints (
                                                rtn := _drop_raster_constraint_blocksize(schema, $2, $3, 'width');
                                                RAISE NOTICE 'Dropping blocksize-Y constraint';
                                                rtn := _drop_raster_constraint_blocksize(schema, $2, $3, 'height');
-                                       WHEN kw = 'same_alignment' OR kw = 'samealignment' OR kw = 'alignment' THEN
+                                       WHEN kw IN ('same_alignment', 'samealignment', 'alignment') THEN
                                                RAISE NOTICE 'Dropping alignment constraint';
                                                rtn := _drop_raster_constraint_alignment(schema, $2, $3);
-                                       WHEN kw = 'regular_blocking' OR kw = 'regularblocking' THEN
+                                       WHEN kw IN ('regular_blocking', 'regularblocking') THEN
                                                RAISE NOTICE 'Dropping regular blocking constraint';
                                                rtn := _drop_raster_constraint_regular_blocking(schema, $2, $3);
-                                       WHEN kw = 'num_bands' OR kw = 'numbands' THEN
+                                       WHEN kw IN ('num_bands', 'numbands') THEN
                                                RAISE NOTICE 'Dropping number of bands constraint';
                                                rtn := _drop_raster_constraint_num_bands(schema, $2, $3);
-                                       WHEN kw = 'pixel_types' OR kw = 'pixeltypes' THEN
+                                       WHEN kw IN ('pixel_types', 'pixeltypes') THEN
                                                RAISE NOTICE 'Dropping pixel type constraint';
                                                rtn := _drop_raster_constraint_pixel_types(schema, $2, $3);
-                                       WHEN kw = 'nodata_values' OR kw = 'nodatavalues' OR kw = 'nodata' THEN
+                                       WHEN kw IN ('nodata_values', 'nodatavalues', 'nodata') THEN
                                                RAISE NOTICE 'Dropping nodata value constraint';
                                                rtn := _drop_raster_constraint_nodata_values(schema, $2, $3);
                                        WHEN kw = 'extent' THEN
index 685bd5ffa39b2afea4b0d8784b02bf2162a287ae..aec8add3693da39eac155c56f247b59170760e74 100644 (file)
@@ -326,3 +326,7 @@ DROP FUNCTION _drop_st_samealignment();
 DROP FUNCTION IF EXISTS _st_intersects(raster, integer, raster, integer);
 DROP FUNCTION IF EXISTS st_intersects(raster, integer, raster, integer);
 DROP FUNCTION IF EXISTS st_intersects(raster, raster);
+
+-- functions have changed dramatically
+DROP FUNCTION IF EXISTS st_intersection(rast raster, band integer, geom geometry);
+DROP FUNCTION IF EXISTS st_intersection(rast raster, geom geometry);
index 5d5c43cc266ab980b22ac15da91353cfa6c02492..fee90f8d9eff04fcab7980f56141ccd3fcbdbc1d 100644 (file)
@@ -91,12 +91,13 @@ TEST_UTILITY = \
        rt_mapalgebrafct.sql \
        rt_mapalgebraexpr_2raster.sql \
        rt_mapalgebrafct_2raster.sql \
-    create_rt_mapalgebrafctngb_test.sql \
-    rt_mapalgebrafctngb.sql \
+       create_rt_mapalgebrafctngb_test.sql \
+       rt_mapalgebrafctngb.sql \
        rt_mapalgebrafctngb_userfunc.sql \
-    rt_reclass.sql \
+       rt_reclass.sql \
        rt_resample.sql \
        rt_asraster.sql \
+       rt_intersection.sql \
        $(NULL)
 
 TEST_GIST = \
diff --git a/raster/test/regress/rt_intersection.sql b/raster/test/regress/rt_intersection.sql
new file mode 100644 (file)
index 0000000..9614a6a
--- /dev/null
@@ -0,0 +1,224 @@
+DROP TABLE IF EXISTS raster_intersection;
+CREATE TABLE raster_intersection (
+       rid integer,
+       rast raster
+);
+DROP TABLE IF EXISTS raster_intersection_out;
+CREATE TABLE raster_intersection_out (
+       rid1 integer,
+       rid2 integer,
+       rast raster
+);
+CREATE OR REPLACE FUNCTION make_test_raster(
+       rid integer,
+       width integer DEFAULT 2,
+       height integer DEFAULT 2,
+       ul_x double precision DEFAULT 0,
+       ul_y double precision DEFAULT 0,
+       skew_x double precision DEFAULT 0,
+       skew_y double precision DEFAULT 0,
+       initvalue double precision DEFAULT 1,
+       nodataval double precision DEFAULT 0
+)
+       RETURNS void
+       AS $$
+       DECLARE
+               x int;
+               y int;
+               rast raster;
+       BEGIN
+               rast := ST_MakeEmptyRaster(width, height, ul_x, ul_y, 1, 1, skew_x, skew_y, 0);
+               rast := ST_AddBand(rast, 1, '8BUI', initvalue, nodataval);
+
+
+               INSERT INTO raster_intersection VALUES (rid, rast);
+
+               RETURN;
+       END;
+       $$ LANGUAGE 'plpgsql';
+-- no skew
+SELECT make_test_raster(0, 4, 4, -2, -2);
+SELECT make_test_raster(1, 2, 2, 0, 0, 0, 0, 2);
+SELECT make_test_raster(2, 2, 2, 1, -1, 0, 0, 3);
+SELECT make_test_raster(3, 2, 2, 1, 1, 0, 0, 4);
+SELECT make_test_raster(4, 2, 2, 2, 2, 0, 0, 5);
+
+-- skew
+SELECT make_test_raster(10, 4, 4, -2, -2, 1, -1);
+SELECT make_test_raster(11, 2, 2, 0, 0, 1, -1, 2);
+SELECT make_test_raster(12, 2, 2, 1, -1, 1, -1, 3);
+SELECT make_test_raster(13, 2, 2, 1, 1, 1, -1, 4);
+SELECT make_test_raster(14, 2, 2, 2, 2, 1, -1, 5);
+
+DROP FUNCTION make_test_raster(integer, integer, integer, double precision, double precision, double precision, double precision, double precision, double precision);
+
+INSERT INTO raster_intersection_out
+       (SELECT r1.rid, r2.rid, ST_Intersection(
+               r1.rast, r2.rast
+       )
+       FROM raster_intersection r1
+       JOIN raster_intersection r2
+               ON r1.rid != r2.rid
+       WHERE r1.rid = 0
+               AND r2.rid BETWEEN 1 AND 9
+       ) UNION ALL (
+       SELECT r1.rid, r2.rid, ST_Intersection(
+               r1.rast, r2.rast
+       )
+       FROM raster_intersection r1
+       JOIN raster_intersection r2
+               ON r1.rid != r2.rid
+       WHERE r1.rid = 10
+               AND r2.rid BETWEEN 11 AND 19)
+;
+
+INSERT INTO raster_intersection_out
+       (SELECT r1.rid, r2.rid, ST_Intersection(
+               r1.rast, r2.rast, 'FIRST'
+       )
+       FROM raster_intersection r1
+       JOIN raster_intersection r2
+               ON r1.rid != r2.rid
+       WHERE r1.rid = 0
+               AND r2.rid BETWEEN 1 AND 9
+       ) UNION ALL (
+       SELECT r1.rid, r2.rid, ST_Intersection(
+               r1.rast, r2.rast, 'FIRST'
+       )
+       FROM raster_intersection r1
+       JOIN raster_intersection r2
+               ON r1.rid != r2.rid
+       WHERE r1.rid = 10
+               AND r2.rid BETWEEN 11 AND 19)
+;
+
+INSERT INTO raster_intersection_out
+       (SELECT r1.rid, r2.rid, ST_Intersection(
+               r1.rast, r2.rast, 'SECOND'
+       )
+       FROM raster_intersection r1
+       JOIN raster_intersection r2
+               ON r1.rid != r2.rid
+       WHERE r1.rid = 0
+               AND r2.rid BETWEEN 1 AND 9
+       ) UNION ALL (
+       SELECT r1.rid, r2.rid, ST_Intersection(
+               r1.rast, r2.rast, 'SECOND'
+       )
+       FROM raster_intersection r1
+       JOIN raster_intersection r2
+               ON r1.rid != r2.rid
+       WHERE r1.rid = 10
+               AND r2.rid BETWEEN 11 AND 19)
+;
+
+CREATE OR REPLACE FUNCTION raster_intersection_other(
+       rast1 double precision,
+       rast2 double precision,
+       VARIADIC userargs text[]
+)
+       RETURNS double precision
+       AS $$
+       DECLARE
+       BEGIN
+               IF rast1 IS NOT NULL AND rast2 IS NOT NULL THEN
+                       RETURN sqrt(power(rast1, 2) + power(rast2, 2));
+               ELSE
+                       RETURN NULL;
+               END IF;
+
+               RETURN NULL;
+       END;
+       $$ LANGUAGE 'plpgsql' IMMUTABLE;
+
+INSERT INTO raster_intersection_out
+       (SELECT r1.rid, r2.rid, ST_Intersection(
+               r1.rast, r2.rast, 'raster_intersection_other(double precision, double precision, text[])'::regprocedure
+       )
+       FROM raster_intersection r1
+       JOIN raster_intersection r2
+               ON r1.rid != r2.rid
+       WHERE r1.rid = 0
+               AND r2.rid BETWEEN 1 AND 9
+       ) UNION ALL (
+       SELECT r1.rid, r2.rid, ST_Intersection(
+               r1.rast, r2.rast, 'raster_intersection_other(double precision, double precision, text[])'::regprocedure
+       )
+       FROM raster_intersection r1
+       JOIN raster_intersection r2
+               ON r1.rid != r2.rid
+       WHERE r1.rid = 10
+               AND r2.rid BETWEEN 11 AND 19)
+;
+
+INSERT INTO raster_intersection_out
+       (SELECT r1.rid, r2.rid, ST_Intersection(
+               r1.rast, ST_ConvexHull(r2.rast)
+       )
+       FROM raster_intersection r1
+       JOIN raster_intersection r2
+               ON r1.rid != r2.rid
+       WHERE r1.rid = 1
+               AND r2.rid BETWEEN 2 AND 9
+       ) UNION ALL (
+       SELECT r1.rid, r2.rid, ST_Intersection(
+               r1.rast, ST_ConvexHull(r2.rast)
+       )
+       FROM raster_intersection r1
+       JOIN raster_intersection r2
+               ON r1.rid != r2.rid
+       WHERE r1.rid = 11
+               AND r2.rid BETWEEN 10 AND 19)
+;
+
+INSERT INTO raster_intersection_out
+       (SELECT r1.rid, r2.rid, ST_Intersection(
+               r1.rast, ST_ConvexHull(r2.rast), 'raster_intersection_other(double precision, double precision, text[])'::regprocedure
+       )
+       FROM raster_intersection r1
+       JOIN raster_intersection r2
+               ON r1.rid != r2.rid
+       WHERE r1.rid = 1
+               AND r2.rid BETWEEN 1 AND 9
+       ) UNION ALL (
+       SELECT r1.rid, r2.rid, ST_Intersection(
+               r1.rast, ST_ConvexHull(r2.rast), 'raster_intersection_other(double precision, double precision, text[])'::regprocedure
+       )
+       FROM raster_intersection r1
+       JOIN raster_intersection r2
+               ON r1.rid != r2.rid
+       WHERE r1.rid = 11
+               AND r2.rid BETWEEN 10 AND 19)
+;
+
+SELECT
+       rid1,
+       rid2,
+       round(upperleftx::numeric, 3) AS upperleftx,
+       round(upperlefty::numeric, 3) AS upperlefty,
+       width,
+       height,
+       round(scalex::numeric, 3) AS scalex,
+       round(scaley::numeric, 3) AS scaley,
+       round(skewx::numeric, 3) AS skewx,
+       round(skewy::numeric, 3) AS skewy,
+       srid,
+       numbands,
+       pixeltype,
+       hasnodata,
+       round(nodatavalue::numeric, 3) AS nodatavalue,
+       round(firstvalue::numeric, 3) AS firstvalue,
+       round(lastvalue::numeric, 3) AS lastvalue
+FROM (
+       SELECT
+               rid1,
+               rid2,
+               (ST_Metadata(rast)).*,
+               (ST_BandMetadata(rast, 1)).*,
+               ST_Value(rast, 1, 1, 1) AS firstvalue,
+               ST_Value(rast, 1, ST_Width(rast), ST_Height(rast)) AS lastvalue
+       FROM raster_intersection_out
+) AS r;
+
+DROP TABLE IF EXISTS raster_intersection;
+DROP TABLE IF EXISTS raster_intersection_out;
diff --git a/raster/test/regress/rt_intersection_expected b/raster/test/regress/rt_intersection_expected
new file mode 100644 (file)
index 0000000..1535385
--- /dev/null
@@ -0,0 +1,144 @@
+NOTICE:  table "raster_intersection" does not exist, skipping
+NOTICE:  table "raster_intersection_out" does not exist, skipping
+NOTICE:  The two rasters provided have no intersection.  Returning no band raster
+NOTICE:  The two rasters provided have no intersection.  Returning no band raster
+NOTICE:  rt_raster_copy_band: Second raster has no band
+NOTICE:  RASTER_copyband: Could not add band to raster. Returning original raster.
+NOTICE:  The two rasters provided have no intersection.  Returning no band raster
+NOTICE:  The two rasters provided have no intersection.  Returning no band raster
+NOTICE:  rt_raster_copy_band: Second raster has no band
+NOTICE:  RASTER_copyband: Could not add band to raster. Returning original raster.
+NOTICE:  The two rasters provided have no intersection.  Returning no band raster
+NOTICE:  The two rasters provided have no intersection.  Returning no band raster
+NOTICE:  The two rasters provided have no intersection.  Returning no band raster
+NOTICE:  The two rasters provided have no intersection.  Returning no band raster
+NOTICE:  The two rasters provided have no intersection.  Returning no band raster
+NOTICE:  The two rasters provided have no intersection.  Returning no band raster
+NOTICE:  The two rasters provided have no intersection.  Returning no band raster
+PL/pgSQL function "st_intersection" line 7 at assignment
+NOTICE:  The two rasters provided have no intersection.  Returning no band raster
+PL/pgSQL function "st_intersection" line 7 at assignment
+NOTICE:  The two rasters provided have no intersection.  Returning no band raster
+PL/pgSQL function "st_intersection" line 7 at assignment
+NOTICE:  The two rasters provided have no intersection.  Returning no band raster
+PL/pgSQL function "st_intersection" line 9 at assignment
+NOTICE:  The two rasters provided have no intersection.  Returning no band raster
+PL/pgSQL function "st_intersection" line 9 at assignment
+NOTICE:  The two rasters provided have no intersection.  Returning no band raster
+PL/pgSQL function "st_intersection" line 9 at assignment
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Raster provided has no bands
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+NOTICE:  Could not find raster band of index 1 when getting pixel value. Returning NULL
+0|1|0.000|0.000|2|2|1.000|1.000|0.000|0.000|0|2|8BUI|t|0.000|1.000|1.000
+0|2|1.000|-1.000|1|2|1.000|1.000|0.000|0.000|0|2|8BUI|t|0.000|1.000|1.000
+0|3|1.000|1.000|1|1|1.000|1.000|0.000|0.000|0|2|8BUI|t|0.000|1.000|1.000
+0|4|0.000|0.000|0|0|0.000|0.000|0.000|0.000|0|0|||||
+10|11|0.000|0.000|2|2|1.000|1.000|1.000|-1.000|0|2|8BUI|t|0.000|1.000|1.000
+10|12|1.000|-1.000|2|2|1.000|1.000|1.000|-1.000|0|2|8BUI|t|0.000|1.000|1.000
+10|13|1.000|1.000|2|1|1.000|1.000|1.000|-1.000|0|2|8BUI|t|0.000|1.000|1.000
+10|14|0.000|0.000|0|0|0.000|0.000|0.000|0.000|0|0|||||
+0|1|0.000|0.000|2|2|1.000|1.000|0.000|0.000|0|1|8BUI|t|0.000|1.000|1.000
+0|2|1.000|-1.000|1|2|1.000|1.000|0.000|0.000|0|1|8BUI|t|0.000|1.000|1.000
+0|3|1.000|1.000|1|1|1.000|1.000|0.000|0.000|0|1|8BUI|t|0.000|1.000|1.000
+0|4|0.000|0.000|0|0|0.000|0.000|0.000|0.000|0|0|||||
+10|11|0.000|0.000|2|2|1.000|1.000|1.000|-1.000|0|1|8BUI|t|0.000|1.000|1.000
+10|12|1.000|-1.000|2|2|1.000|1.000|1.000|-1.000|0|1|8BUI|t|0.000|1.000|1.000
+10|13|1.000|1.000|2|1|1.000|1.000|1.000|-1.000|0|1|8BUI|t|0.000|1.000|1.000
+10|14|0.000|0.000|0|0|0.000|0.000|0.000|0.000|0|0|||||
+0|1|0.000|0.000|2|2|1.000|1.000|0.000|0.000|0|1|8BUI|t|0.000|2.000|2.000
+0|2|1.000|-1.000|1|2|1.000|1.000|0.000|0.000|0|1|8BUI|t|0.000|3.000|3.000
+0|3|1.000|1.000|1|1|1.000|1.000|0.000|0.000|0|1|8BUI|t|0.000|4.000|4.000
+0|4|0.000|0.000|0|0|0.000|0.000|0.000|0.000|0|0|||||
+10|11|0.000|0.000|2|2|1.000|1.000|1.000|-1.000|0|1|8BUI|t|0.000|2.000|2.000
+10|12|1.000|-1.000|2|2|1.000|1.000|1.000|-1.000|0|1|8BUI|t|0.000|3.000|3.000
+10|13|1.000|1.000|2|1|1.000|1.000|1.000|-1.000|0|1|8BUI|t|0.000|4.000|4.000
+10|14|0.000|0.000|0|0|0.000|0.000|0.000|0.000|0|0|||||
+0|1|0.000|0.000|2|2|1.000|1.000|0.000|0.000|0|1|8BUI|t|0.000|2.000|2.000
+0|2|1.000|-1.000|1|2|1.000|1.000|0.000|0.000|0|1|8BUI|t|0.000|3.000|3.000
+0|3|1.000|1.000|1|1|1.000|1.000|0.000|0.000|0|1|8BUI|t|0.000|4.000|4.000
+0|4|0.000|0.000|0|0|0.000|0.000|0.000|0.000|0|0|||||
+10|11|0.000|0.000|2|2|1.000|1.000|1.000|-1.000|0|1|8BUI|t|0.000|2.000|2.000
+10|12|1.000|-1.000|2|2|1.000|1.000|1.000|-1.000|0|1|8BUI|t|0.000|3.000|3.000
+10|13|1.000|1.000|2|1|1.000|1.000|1.000|-1.000|0|1|8BUI|t|0.000|4.000|4.000
+10|14|0.000|0.000|0|0|0.000|0.000|0.000|0.000|0|0|||||
+1|2|1.000|0.000|1|1|1.000|1.000|0.000|0.000|0|1|8BUI|t|0.000|2.000|2.000
+1|3|1.000|1.000|1|1|1.000|1.000|0.000|0.000|0|1|8BUI|t|0.000|2.000|2.000
+1|4|0.000|0.000|0|0|0.000|0.000|0.000|0.000|0|0|||||
+11|10|0.000|0.000|0|0|0.000|0.000|0.000|0.000|0|0|||||
+11|12|0.000|0.000|0|0|0.000|0.000|0.000|0.000|0|0|||||
+11|13|1.000|-1.000|1|2|1.000|1.000|1.000|-1.000|0|1|8BUI|t|0.000||2.000
+11|14|2.000|0.000|1|1|1.000|1.000|1.000|-1.000|0|1|8BUI|t|0.000||
+1|2|1.000|0.000|1|1|1.000|1.000|0.000|0.000|0|1|8BUI|t|0.000|2.000|2.000
+1|3|1.000|1.000|1|1|1.000|1.000|0.000|0.000|0|1|8BUI|t|0.000|2.000|2.000
+1|4|0.000|0.000|0|0|0.000|0.000|0.000|0.000|0|0|||||
+11|10|0.000|0.000|0|0|0.000|0.000|0.000|0.000|0|0|||||
+11|12|0.000|0.000|0|0|0.000|0.000|0.000|0.000|0|0|||||
+11|13|1.000|-1.000|1|2|1.000|1.000|1.000|-1.000|0|1|8BUI|t|0.000||2.000
+11|14|2.000|0.000|1|1|1.000|1.000|1.000|-1.000|0|1|8BUI|t|0.000||