From: Bborie Park Date: Mon, 23 Jul 2012 17:49:18 +0000 (+0000) Subject: Addition of ST_Contains and regression tests. Ticket is #1914 X-Git-Tag: 2.1.0beta2~775 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=38dd49660f490fd9be9f89c28ab48676deed2fe4;p=postgis Addition of ST_Contains and regression tests. Ticket is #1914 git-svn-id: http://svn.osgeo.org/postgis/trunk@10089 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/raster/rt_pg/rt_pg.c b/raster/rt_pg/rt_pg.c index ed5faa08e..119e29a6b 100644 --- a/raster/rt_pg/rt_pg.c +++ b/raster/rt_pg/rt_pg.c @@ -276,6 +276,9 @@ Datum RASTER_overlaps(PG_FUNCTION_ARGS); /* determine if two rasters touch */ Datum RASTER_touches(PG_FUNCTION_ARGS); +/* determine if the first raster contains the second raster */ +Datum RASTER_contains(PG_FUNCTION_ARGS); + /* determine if two rasters are aligned */ Datum RASTER_sameAlignment(PG_FUNCTION_ARGS); @@ -10219,6 +10222,125 @@ Datum RASTER_touches(PG_FUNCTION_ARGS) PG_RETURN_BOOL(touches); } +/** + * See if the first raster contains the second raster + */ +PG_FUNCTION_INFO_V1(RASTER_contains); +Datum RASTER_contains(PG_FUNCTION_ARGS) +{ + const int set_count = 2; + rt_pgraster *pgrast[2]; + int pgrastpos[2] = {-1, -1}; + rt_raster rast[2] = {NULL}; + uint32_t bandindex[2] = {0}; + uint32_t hasbandindex[2] = {0}; + + uint32_t i; + uint32_t j; + uint32_t k; + uint32_t numBands; + int rtn; + int contains; + + for (i = 0, j = 0; i < set_count; i++) { + /* pgrast is null, return null */ + if (PG_ARGISNULL(j)) { + for (k = 0; k < i; k++) { + rt_raster_destroy(rast[k]); + PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]); + } + PG_RETURN_NULL(); + } + pgrast[i] = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(j)); + pgrastpos[i] = j; + j++; + + /* raster */ + rast[i] = rt_raster_deserialize(pgrast[i], FALSE); + if (!rast[i]) { + elog(ERROR, "RASTER_contains: Could not deserialize the %s raster", i < 1 ? "first" : "second"); + for (k = 0; k <= i; k++) { + if (k < i) + rt_raster_destroy(rast[k]); + PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]); + } + PG_RETURN_NULL(); + } + + /* numbands */ + numBands = rt_raster_get_num_bands(rast[i]); + if (numBands < 1) { + elog(NOTICE, "The %s raster provided has no bands", i < 1 ? "first" : "second"); + if (i > 0) i++; + for (k = 0; k < i; k++) { + rt_raster_destroy(rast[k]); + PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]); + } + PG_RETURN_NULL(); + } + + /* band index */ + if (!PG_ARGISNULL(j)) { + bandindex[i] = PG_GETARG_INT32(j); + if (bandindex[i] < 1 || bandindex[i] > numBands) { + elog(NOTICE, "Invalid band index (must use 1-based) for the %s raster. Returning NULL", i < 1 ? "first" : "second"); + if (i > 0) i++; + for (k = 0; k < i; k++) { + rt_raster_destroy(rast[k]); + PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]); + } + PG_RETURN_NULL(); + } + hasbandindex[i] = 1; + } + else + hasbandindex[i] = 0; + POSTGIS_RT_DEBUGF(4, "hasbandindex[%d] = %d", i, hasbandindex[i]); + POSTGIS_RT_DEBUGF(4, "bandindex[%d] = %d", i, bandindex[i]); + j++; + } + + /* hasbandindex must be balanced */ + if ( + (hasbandindex[0] && !hasbandindex[1]) || + (!hasbandindex[0] && hasbandindex[1]) + ) { + elog(NOTICE, "Missing band index. Band indices must be provided for both rasters if any one is provided"); + for (k = 0; k < set_count; k++) { + rt_raster_destroy(rast[k]); + PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]); + } + PG_RETURN_NULL(); + } + + /* SRID must match */ + if (rt_raster_get_srid(rast[0]) != rt_raster_get_srid(rast[1])) { + elog(ERROR, "The two rasters provided have different SRIDs"); + for (k = 0; k < set_count; k++) { + rt_raster_destroy(rast[k]); + PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]); + } + PG_RETURN_NULL(); + } + + rtn = rt_raster_contains( + rast[0], (hasbandindex[0] ? bandindex[0] - 1 : -1), + rast[1], (hasbandindex[1] ? bandindex[1] - 1 : -1), + &contains + ); + for (k = 0; k < set_count; k++) { + rt_raster_destroy(rast[k]); + PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]); + } + + if (!rtn) { + elog(ERROR, "RASTER_contains: Unable to test that the first raster contains the second raster"); + PG_RETURN_NULL(); + } + + PG_RETURN_BOOL(contains); +} + /** * See if two rasters are aligned */ diff --git a/raster/rt_pg/rtpostgis.sql.in.c b/raster/rt_pg/rtpostgis.sql.in.c index 6a993e087..3f875fc3a 100644 --- a/raster/rt_pg/rtpostgis.sql.in.c +++ b/raster/rt_pg/rtpostgis.sql.in.c @@ -3430,6 +3430,107 @@ CREATE OR REPLACE FUNCTION st_touches(geom geometry, rast raster, nband integer LANGUAGE 'sql' IMMUTABLE COST 1000; +----------------------------------------------------------------------- +-- ST_Contains(raster, raster) +----------------------------------------------------------------------- + +CREATE OR REPLACE FUNCTION _st_contains(rast1 raster, nband1 integer, rast2 raster, nband2 integer) + RETURNS boolean + AS 'MODULE_PATHNAME', 'RASTER_contains' + LANGUAGE 'c' IMMUTABLE STRICT + COST 1000; + +CREATE OR REPLACE FUNCTION st_contains(rast1 raster, nband1 integer, rast2 raster, nband2 integer) + RETURNS boolean + AS $$ SELECT $1 && $3 AND CASE WHEN $2 IS NULL OR $4 IS NULL THEN st_contains(st_convexhull($1), st_convexhull($3)) ELSE _st_contains($1, $2, $3, $4) END $$ + LANGUAGE 'sql' IMMUTABLE + COST 1000; + +CREATE OR REPLACE FUNCTION st_contains(rast1 raster, rast2 raster) + RETURNS boolean + AS $$ SELECT st_contains($1, NULL::integer, $2, NULL::integer) $$ + LANGUAGE 'sql' IMMUTABLE + COST 1000; + +----------------------------------------------------------------------- +-- ST_Contains(raster, geometry) +----------------------------------------------------------------------- + +CREATE OR REPLACE FUNCTION _st_contains(rast raster, geom geometry, nband integer DEFAULT NULL) + RETURNS boolean + AS $$ + DECLARE + gr raster; + scale double precision; + BEGIN + IF ST_Contains(ST_ConvexHull(rast), geom) IS NOT TRUE THEN + RETURN FALSE; + ELSEIF nband IS NULL THEN + RETURN TRUE; + END IF; + + -- scale is set to 1/100th of raster for granularity + SELECT least(scalex, scaley) / 100. INTO scale FROM ST_Metadata(rast); + gr := _st_asraster(geom, scale, scale); + IF gr IS NULL THEN + RAISE EXCEPTION 'Unable to convert geometry to a raster'; + RETURN FALSE; + END IF; + + RETURN ST_Contains(rast, nband, gr, 1); + END; + $$ LANGUAGE 'plpgsql' IMMUTABLE + COST 1000; + +CREATE OR REPLACE FUNCTION st_contains(rast raster, geom geometry, nband integer DEFAULT NULL) + RETURNS boolean + AS $$ SELECT $1::geometry && $2 AND _st_contains($1, $2, $3) $$ + LANGUAGE 'sql' IMMUTABLE + COST 1000; + +CREATE OR REPLACE FUNCTION st_contains(rast raster, nband integer, geom geometry) + RETURNS boolean + AS $$ SELECT $1::geometry && $3 AND _st_contains($1, $3, $2) $$ + LANGUAGE 'sql' IMMUTABLE + COST 1000; + +----------------------------------------------------------------------- +-- ST_Contains(geometry, raster) +----------------------------------------------------------------------- + +-- This function can not be STRICT +CREATE OR REPLACE FUNCTION _st_contains(geom geometry, rast raster, nband integer DEFAULT NULL) + RETURNS boolean AS $$ + DECLARE + gr raster; + scale double precision; + BEGIN + IF ST_Contains(geom, ST_ConvexHull(rast)) IS NOT TRUE THEN + RETURN FALSE; + ELSEIF nband IS NULL THEN + RETURN TRUE; + END IF; + + -- scale is set to 1/100th of raster for granularity + SELECT least(scalex, scaley) / 100. INTO scale FROM ST_Metadata(rast); + gr := _st_asraster(geom, scale, scale); + IF gr IS NULL THEN + RAISE EXCEPTION 'Unable to convert geometry to a raster'; + RETURN FALSE; + END IF; + + RETURN ST_Contains(gr, 1, rast, nband); + END; + $$ LANGUAGE 'plpgsql' IMMUTABLE + COST 1000; + +-- This function can not be STRICT +CREATE OR REPLACE FUNCTION st_contains(geom geometry, rast raster, nband integer DEFAULT NULL) + RETURNS boolean AS + $$ SELECT $1 && $2::geometry AND _st_contains($1, $2, $3); $$ + LANGUAGE 'sql' IMMUTABLE + COST 1000; + ----------------------------------------------------------------------- -- ST_Intersection(geometry, raster) in geometry-space ----------------------------------------------------------------------- diff --git a/raster/test/regress/Makefile.in b/raster/test/regress/Makefile.in index e14ed9b1e..c6fbadde6 100644 --- a/raster/test/regress/Makefile.in +++ b/raster/test/regress/Makefile.in @@ -127,6 +127,7 @@ TEST_SREL = \ rt_intersects \ rt_overlaps \ rt_touches \ + rt_contains \ rt_samealignment TEST_BUGS = \ diff --git a/raster/test/regress/rt_contains.sql b/raster/test/regress/rt_contains.sql new file mode 100644 index 000000000..c3e394f2d --- /dev/null +++ b/raster/test/regress/rt_contains.sql @@ -0,0 +1,481 @@ +SET client_min_messages TO warning; + +DROP TABLE IF EXISTS raster_contains_rast; +DROP TABLE IF EXISTS raster_contains_geom; +CREATE TABLE raster_contains_rast ( + rid integer, + rast raster +); +CREATE TABLE raster_contains_geom ( + gid integer, + geom geometry +); +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 +) + 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', 1, 0); + + + INSERT INTO raster_contains_rast VALUES (rid, rast); + + RETURN; + END; + $$ LANGUAGE 'plpgsql'; +SELECT make_test_raster(0, 2, 2, -1, -1); +SELECT make_test_raster(1, 2, 2); +SELECT make_test_raster(2, 3, 3); +DROP FUNCTION make_test_raster(integer, integer, integer, double precision, double precision, double precision, double precision); + +INSERT INTO raster_contains_rast VALUES (10, ( + SELECT + ST_SetValue(rast, 1, 1, 1, 0) + FROM raster_contains_rast + WHERE rid = 1 +)); +INSERT INTO raster_contains_rast VALUES (11, ( + SELECT + ST_SetValue(rast, 1, 2, 1, 0) + FROM raster_contains_rast + WHERE rid = 1 +)); +INSERT INTO raster_contains_rast VALUES (12, ( + SELECT + ST_SetValue( + ST_SetValue( + ST_SetValue(rast, 1, 1, 1, 0), + 1, 2, 1, 0 + ), + 1, 1, 2, 0 + ) + FROM raster_contains_rast + WHERE rid = 1 +)); +INSERT INTO raster_contains_rast VALUES (13, ( + SELECT + ST_SetValue( + ST_SetValue( + ST_SetValue( + ST_SetValue(rast, 1, 1, 1, 0), + 1, 2, 1, 0 + ), + 1, 1, 2, 0 + ), + 1, 2, 2, 0 + ) + FROM raster_contains_rast + WHERE rid = 1 +)); +INSERT INTO raster_contains_rast VALUES (14, ( + SELECT + ST_SetUpperLeft(rast, 2, 0) + FROM raster_contains_rast + WHERE rid = 1 +)); +INSERT INTO raster_contains_rast VALUES (15, ( + SELECT + ST_SetScale( + ST_SetUpperLeft(rast, 0.1, 0.1), + 0.4, 0.4 + ) + FROM raster_contains_rast + WHERE rid = 1 +)); +INSERT INTO raster_contains_rast VALUES (16, ( + SELECT + ST_SetScale( + ST_SetUpperLeft(rast, -0.1, 0.1), + 0.4, 0.4 + ) + FROM raster_contains_rast + WHERE rid = 1 +)); + +INSERT INTO raster_contains_rast VALUES (20, ( + SELECT + ST_SetUpperLeft(rast, -2, -2) + FROM raster_contains_rast + WHERE rid = 2 +)); +INSERT INTO raster_contains_rast VALUES (21, ( + SELECT + ST_SetValue( + ST_SetValue( + ST_SetValue(rast, 1, 1, 1, 0), + 1, 2, 2, 0 + ), + 1, 3, 3, 0 + ) + FROM raster_contains_rast + WHERE rid = 20 +)); +INSERT INTO raster_contains_rast VALUES (22, ( + SELECT + ST_SetValue( + ST_SetValue( + rast, 1, 3, 2, 0 + ), + 1, 2, 3, 0 + ) + FROM raster_contains_rast + WHERE rid = 21 +)); +INSERT INTO raster_contains_rast VALUES (23, ( + SELECT + ST_SetValue( + ST_SetValue( + rast, 1, 3, 1, 0 + ), + 1, 1, 3, 0 + ) + FROM raster_contains_rast + WHERE rid = 22 +)); + +INSERT INTO raster_contains_rast VALUES (30, ( + SELECT + ST_SetSkew(rast, -0.5, 0.5) + FROM raster_contains_rast + WHERE rid = 2 +)); +INSERT INTO raster_contains_rast VALUES (31, ( + SELECT + ST_SetSkew(rast, -1, 1) + FROM raster_contains_rast + WHERE rid = 2 +)); +INSERT INTO raster_contains_rast VALUES (32, ( + SELECT + ST_SetSkew(rast, 1, -1) + FROM raster_contains_rast + WHERE rid = 2 +)); + +SELECT + '1.1', + r1.rid, + r2.rid, + ST_Contains(r1.rast, NULL, r2.rast, NULL) +FROM raster_contains_rast r1 +JOIN raster_contains_rast r2 + ON r1.rid != r2.rid +WHERE r1.rid = 0; + +SELECT + '1.2', + r1.rid, + r2.rid, + ST_Contains(r1.rast, 1, r2.rast, 1) +FROM raster_contains_rast r1 +JOIN raster_contains_rast r2 + ON r1.rid != r2.rid +WHERE r1.rid = 0; + +SELECT + '1.3', + r1.rid, + r2.rid, + ST_Contains(r1.rast, NULL, r2.rast, NULL) +FROM raster_contains_rast r1 +JOIN raster_contains_rast r2 + ON r1.rid != r2.rid +WHERE r2.rid = 0; + +SELECT + '1.4', + r1.rid, + r2.rid, + ST_Contains(r1.rast, 1, r2.rast, 1) +FROM raster_contains_rast r1 +JOIN raster_contains_rast r2 + ON r1.rid != r2.rid +WHERE r2.rid = 0; + +-- point +INSERT INTO raster_contains_geom VALUES ( + 1, ( + SELECT ST_SetSRID(ST_MakePoint(0, 0), 0) + ) +), ( + 2, ( + SELECT ST_SetSRID(ST_MakePoint(0.1, 0.1), 0) + ) +), ( + 3, ( + SELECT ST_SetSRID(ST_MakePoint(-0.1, -0.1), 0) + ) +), ( + 4, ( + SELECT ST_SetSRID(ST_MakePoint(-1, -1), 0) + ) +), ( + 5, ( + SELECT ST_SetSRID(ST_MakePoint(-1.1, -1), 0) + ) +), ( + 6, ( + SELECT ST_SetSRID(ST_MakePoint(-1, -1.1), 0) + ) +), ( + 7, ( + SELECT ST_SetSRID(ST_MakePoint(-1.5, -1.5), 0) + ) +), ( + 8, ( + SELECT ST_SetSRID(ST_MakePoint(3, 3), 0) + ) +); + +-- multipoint +INSERT INTO raster_contains_geom VALUES ( + 11, ( + SELECT ST_Collect(geom) FROM raster_contains_geom WHERE gid BETWEEN 1 AND 10 + ) +), ( + 12, ( + SELECT ST_Collect(geom) FROM raster_contains_geom WHERE gid BETWEEN 3 AND 10 + ) +), ( + 13, ( + SELECT ST_Collect(geom) FROM raster_contains_geom WHERE gid BETWEEN 4 AND 10 + ) +), ( + 14, ( + SELECT ST_Collect(geom) FROM raster_contains_geom WHERE gid BETWEEN 5 AND 10 + ) +), ( + 15, ( + SELECT ST_Collect(geom) FROM raster_contains_geom WHERE gid BETWEEN 6 AND 10 + ) +); + +-- linestring +INSERT INTO raster_contains_geom VALUES ( + 21, ( + SELECT ST_SetSRID(ST_MakeLine(ARRAY[ + ST_MakePoint(1, 1), + ST_MakePoint(1, 0) + ]), 0) + ) +), ( + 22, ( + SELECT ST_SetSRID(ST_MakeLine(ARRAY[ + ST_MakePoint(-1, -1), + ST_MakePoint(1, 1), + ST_MakePoint(1, 0) + ]), 0) + ) +), ( + 23, ( + SELECT ST_SetSRID(ST_MakeLine(ARRAY[ + ST_MakePoint(-1, -1), + ST_MakePoint(-1, 1), + ST_MakePoint(1, 1), + ST_MakePoint(1, -1) + ]), 0) + ) +), ( + 24, ( + SELECT ST_SetSRID(ST_MakeLine(ARRAY[ + ST_MakePoint(-1.1, 1.1), + ST_MakePoint(1.1, 1.1), + ST_MakePoint(1.1, -1.1), + ST_MakePoint(-1.1, -1.1), + ST_MakePoint(-1.1, 1.1) + ]), 0) + ) +), ( + 25, ( + SELECT ST_SetSRID(ST_MakeLine(ARRAY[ + ST_MakePoint(-2, 1), + ST_MakePoint(1, 2), + ST_MakePoint(2, -1), + ST_MakePoint(-1, -2), + ST_MakePoint(-2, 1) + ]), 0) + ) +), ( + 26, ( + SELECT ST_SetSRID(ST_MakeLine(ARRAY[ + ST_MakePoint(-0.5, 0.5), + ST_MakePoint(0, 0.5), + ST_MakePoint(0, 0), + ST_MakePoint(0, -0.5), + ST_MakePoint(-0.5, 0.5) + ]), 0) + ) +), ( + 27, ( + SELECT ST_SetSRID(ST_MakeLine(ARRAY[ + ST_MakePoint(0.5, 0.5), + ST_MakePoint(1, 1), + ST_MakePoint(1, 0), + ST_MakePoint(0.5, 0.5) + ]), 0) + ) +), ( + 28, ( + SELECT ST_SetSRID(ST_MakeLine(ARRAY[ + ST_MakePoint(1, 1), + ST_MakePoint(0, 2), + ST_MakePoint(1, 2), + ST_MakePoint(1, 1) + ]), 0) + ) +), ( + 29, ( + SELECT ST_SetSRID(ST_MakeLine(ARRAY[ + ST_MakePoint(0, 2), + ST_MakePoint(1, 2), + ST_MakePoint(1, 4), + ST_MakePoint(0, 2) + ]), 0) + ) +); + +-- polygon +INSERT INTO raster_contains_geom VALUES ( + 31, ( + SELECT ST_MakePolygon(geom) FROM raster_contains_geom WHERE gid = 24 + ) +), ( + 32, ( + SELECT ST_MakePolygon(geom) FROM raster_contains_geom WHERE gid = 25 + ) +), ( + 33, ( + SELECT ST_MakePolygon(geom) FROM raster_contains_geom WHERE gid = 26 + ) +), ( + 34, ( + SELECT ST_MakePolygon(geom) FROM raster_contains_geom WHERE gid = 27 + ) +), ( + 35, ( + SELECT ST_MakePolygon(geom) FROM raster_contains_geom WHERE gid = 28 + ) +), ( + 36, ( + SELECT ST_MakePolygon(geom) FROM raster_contains_geom WHERE gid = 29 + ) +); + +-- multipolygon +INSERT INTO raster_contains_geom VALUES ( + 41, ( + SELECT ST_Multi(ST_Union(geom)) FROM raster_contains_geom WHERE gid BETWEEN 31 and 40 + ) +), ( + 42, ( + SELECT ST_Multi(ST_Union(geom)) FROM raster_contains_geom WHERE gid BETWEEN 32 and 40 + ) +), ( + 43, ( + SELECT ST_Multi(ST_Union(geom)) FROM raster_contains_geom WHERE gid BETWEEN 33 and 40 + ) +), ( + 44, ( + SELECT ST_Multi(ST_Union(geom)) FROM raster_contains_geom WHERE gid BETWEEN 34 and 40 + ) +), ( + 45, ( + SELECT ST_Multi(ST_Union(geom)) FROM raster_contains_geom WHERE gid BETWEEN 35 and 40 + ) +), ( + 46, ( + SELECT ST_Multi(ST_Union(geom)) FROM raster_contains_geom WHERE gid BETWEEN 36 and 40 + ) +); + +SELECT + '2.1', + r1.rid, + g1.gid, + ST_GeometryType(g1.geom), + ST_Contains(r1.rast, g1.geom) +FROM raster_contains_rast r1 +CROSS JOIN raster_contains_geom g1 +WHERE r1.rid = 0; + +SELECT + '2.2', + g1.gid, + r1.rid, + ST_GeometryType(g1.geom), + ST_Contains(g1.geom, r1.rast) +FROM raster_contains_rast r1 +CROSS JOIN raster_contains_geom g1 +WHERE r1.rid = 0; + +SELECT + '2.3', + r1.rid, + g1.gid, + ST_GeometryType(g1.geom), + ST_Contains(r1.rast, g1.geom) +FROM raster_contains_rast r1 +CROSS JOIN raster_contains_geom g1 +WHERE r1.rid = 2; + +SELECT + '2.4', + g1.gid, + r1.rid, + ST_GeometryType(g1.geom), + ST_Contains(g1.geom, r1.rast) +FROM raster_contains_rast r1 +CROSS JOIN raster_contains_geom g1 +WHERE r1.rid = 2; + +SELECT + '2.5', + r1.rid, + g1.gid, + ST_GeometryType(g1.geom), + ST_Contains(r1.rast, g1.geom, 1) +FROM raster_contains_rast r1 +CROSS JOIN raster_contains_geom g1 +WHERE r1.rid = 0; + +SELECT + '2.6', + r1.rid, + g1.gid, + ST_GeometryType(g1.geom), + ST_Contains(r1.rast, g1.geom, 1) +FROM raster_contains_rast r1 +CROSS JOIN raster_contains_geom g1 +WHERE r1.rid = 2; + +SELECT + '2.7', + g1.gid, + r1.rid, + ST_GeometryType(g1.geom), + ST_Contains(g1.geom, r1.rast, 1) +FROM raster_contains_rast r1 +CROSS JOIN raster_contains_geom g1 +WHERE r1.rid = 0; + +SELECT + '2.8', + g1.gid, + r1.rid, + ST_GeometryType(g1.geom), + ST_Contains(g1.geom, r1.rast, 1) +FROM raster_contains_rast r1 +CROSS JOIN raster_contains_geom g1 +WHERE r1.rid = 2; + +DROP TABLE IF EXISTS raster_contains_rast; +DROP TABLE IF EXISTS raster_contains_geom; diff --git a/raster/test/regress/rt_contains_expected b/raster/test/regress/rt_contains_expected new file mode 100644 index 000000000..222dedd1a --- /dev/null +++ b/raster/test/regress/rt_contains_expected @@ -0,0 +1,336 @@ +1.1|0|1|f +1.1|0|2|f +1.1|0|10|f +1.1|0|11|f +1.1|0|12|f +1.1|0|13|f +1.1|0|14|f +1.1|0|15|t +1.1|0|16|t +1.1|0|20|f +1.1|0|21|f +1.1|0|22|f +1.1|0|23|f +1.1|0|30|f +1.1|0|31|f +1.1|0|32|f +1.2|0|1|f +1.2|0|2|f +1.2|0|10|f +1.2|0|11|f +1.2|0|12|f +1.2|0|13|f +1.2|0|14|f +1.2|0|15|t +1.2|0|16|t +1.2|0|20|f +1.2|0|21|f +1.2|0|22|f +1.2|0|23|f +1.2|0|30|f +1.2|0|31|f +1.2|0|32|f +1.3|1|0|f +1.3|2|0|f +1.3|10|0|f +1.3|11|0|f +1.3|12|0|f +1.3|13|0|f +1.3|14|0|f +1.3|15|0|f +1.3|16|0|f +1.3|20|0|t +1.3|21|0|t +1.3|22|0|t +1.3|23|0|t +1.3|30|0|f +1.3|31|0|f +1.3|32|0|f +1.4|1|0|f +1.4|2|0|f +1.4|10|0|f +1.4|11|0|f +1.4|12|0|f +1.4|13|0|f +1.4|14|0|f +1.4|15|0|f +1.4|16|0|f +1.4|20|0|t +1.4|21|0|f +1.4|22|0|f +1.4|23|0|f +1.4|30|0|f +1.4|31|0|f +1.4|32|0|f +2.1|0|1|ST_Point|t +2.1|0|2|ST_Point|t +2.1|0|3|ST_Point|t +2.1|0|4|ST_Point|f +2.1|0|5|ST_Point|f +2.1|0|6|ST_Point|f +2.1|0|7|ST_Point|f +2.1|0|8|ST_Point|f +2.1|0|11|ST_MultiPoint|f +2.1|0|12|ST_MultiPoint|f +2.1|0|13|ST_MultiPoint|f +2.1|0|14|ST_MultiPoint|f +2.1|0|15|ST_MultiPoint|f +2.1|0|21|ST_LineString|f +2.1|0|22|ST_LineString|t +2.1|0|23|ST_LineString|f +2.1|0|24|ST_LineString|f +2.1|0|25|ST_LineString|f +2.1|0|26|ST_LineString|t +2.1|0|27|ST_LineString|t +2.1|0|28|ST_LineString|f +2.1|0|29|ST_LineString|f +2.1|0|31|ST_Polygon|f +2.1|0|32|ST_Polygon|f +2.1|0|33|ST_Polygon|t +2.1|0|34|ST_Polygon|t +2.1|0|35|ST_Polygon|f +2.1|0|36|ST_Polygon|f +2.1|0|41|ST_MultiPolygon|f +2.1|0|42|ST_MultiPolygon|f +2.1|0|43|ST_MultiPolygon|f +2.1|0|44|ST_MultiPolygon|f +2.1|0|45|ST_MultiPolygon|f +2.1|0|46|ST_MultiPolygon|f +2.2|1|0|ST_Point|f +2.2|2|0|ST_Point|f +2.2|3|0|ST_Point|f +2.2|4|0|ST_Point|f +2.2|5|0|ST_Point|f +2.2|6|0|ST_Point|f +2.2|7|0|ST_Point|f +2.2|8|0|ST_Point|f +2.2|11|0|ST_MultiPoint|f +2.2|12|0|ST_MultiPoint|f +2.2|13|0|ST_MultiPoint|f +2.2|14|0|ST_MultiPoint|f +2.2|15|0|ST_MultiPoint|f +2.2|21|0|ST_LineString|f +2.2|22|0|ST_LineString|f +2.2|23|0|ST_LineString|f +2.2|24|0|ST_LineString|f +2.2|25|0|ST_LineString|f +2.2|26|0|ST_LineString|f +2.2|27|0|ST_LineString|f +2.2|28|0|ST_LineString|f +2.2|29|0|ST_LineString|f +2.2|31|0|ST_Polygon|t +2.2|32|0|ST_Polygon|t +2.2|33|0|ST_Polygon|f +2.2|34|0|ST_Polygon|f +2.2|35|0|ST_Polygon|f +2.2|36|0|ST_Polygon|f +2.2|41|0|ST_MultiPolygon|t +2.2|42|0|ST_MultiPolygon|t +2.2|43|0|ST_MultiPolygon|f +2.2|44|0|ST_MultiPolygon|f +2.2|45|0|ST_MultiPolygon|f +2.2|46|0|ST_MultiPolygon|f +2.3|2|1|ST_Point|f +2.3|2|2|ST_Point|t +2.3|2|3|ST_Point|f +2.3|2|4|ST_Point|f +2.3|2|5|ST_Point|f +2.3|2|6|ST_Point|f +2.3|2|7|ST_Point|f +2.3|2|8|ST_Point|f +2.3|2|11|ST_MultiPoint|f +2.3|2|12|ST_MultiPoint|f +2.3|2|13|ST_MultiPoint|f +2.3|2|14|ST_MultiPoint|f +2.3|2|15|ST_MultiPoint|f +2.3|2|21|ST_LineString|t +2.3|2|22|ST_LineString|f +2.3|2|23|ST_LineString|f +2.3|2|24|ST_LineString|f +2.3|2|25|ST_LineString|f +2.3|2|26|ST_LineString|f +2.3|2|27|ST_LineString|t +2.3|2|28|ST_LineString|t +2.3|2|29|ST_LineString|f +2.3|2|31|ST_Polygon|f +2.3|2|32|ST_Polygon|f +2.3|2|33|ST_Polygon|f +2.3|2|34|ST_Polygon|t +2.3|2|35|ST_Polygon|t +2.3|2|36|ST_Polygon|f +2.3|2|41|ST_MultiPolygon|f +2.3|2|42|ST_MultiPolygon|f +2.3|2|43|ST_MultiPolygon|f +2.3|2|44|ST_MultiPolygon|f +2.3|2|45|ST_MultiPolygon|f +2.3|2|46|ST_MultiPolygon|f +2.4|1|2|ST_Point|f +2.4|2|2|ST_Point|f +2.4|3|2|ST_Point|f +2.4|4|2|ST_Point|f +2.4|5|2|ST_Point|f +2.4|6|2|ST_Point|f +2.4|7|2|ST_Point|f +2.4|8|2|ST_Point|f +2.4|11|2|ST_MultiPoint|f +2.4|12|2|ST_MultiPoint|f +2.4|13|2|ST_MultiPoint|f +2.4|14|2|ST_MultiPoint|f +2.4|15|2|ST_MultiPoint|f +2.4|21|2|ST_LineString|f +2.4|22|2|ST_LineString|f +2.4|23|2|ST_LineString|f +2.4|24|2|ST_LineString|f +2.4|25|2|ST_LineString|f +2.4|26|2|ST_LineString|f +2.4|27|2|ST_LineString|f +2.4|28|2|ST_LineString|f +2.4|29|2|ST_LineString|f +2.4|31|2|ST_Polygon|f +2.4|32|2|ST_Polygon|f +2.4|33|2|ST_Polygon|f +2.4|34|2|ST_Polygon|f +2.4|35|2|ST_Polygon|f +2.4|36|2|ST_Polygon|f +2.4|41|2|ST_MultiPolygon|f +2.4|42|2|ST_MultiPolygon|f +2.4|43|2|ST_MultiPolygon|f +2.4|44|2|ST_MultiPolygon|f +2.4|45|2|ST_MultiPolygon|f +2.4|46|2|ST_MultiPolygon|f +2.5|0|1|ST_Point|t +2.5|0|2|ST_Point|t +2.5|0|3|ST_Point|t +2.5|0|4|ST_Point|f +2.5|0|5|ST_Point|f +2.5|0|6|ST_Point|f +2.5|0|7|ST_Point|f +2.5|0|8|ST_Point|f +2.5|0|11|ST_MultiPoint|f +2.5|0|12|ST_MultiPoint|f +2.5|0|13|ST_MultiPoint|f +2.5|0|14|ST_MultiPoint|f +2.5|0|15|ST_MultiPoint|f +2.5|0|21|ST_LineString|f +2.5|0|22|ST_LineString|f +2.5|0|23|ST_LineString|f +2.5|0|24|ST_LineString|f +2.5|0|25|ST_LineString|f +2.5|0|26|ST_LineString|t +2.5|0|27|ST_LineString|f +2.5|0|28|ST_LineString|f +2.5|0|29|ST_LineString|f +2.5|0|31|ST_Polygon|f +2.5|0|32|ST_Polygon|f +2.5|0|33|ST_Polygon|t +2.5|0|34|ST_Polygon|t +2.5|0|35|ST_Polygon|f +2.5|0|36|ST_Polygon|f +2.5|0|41|ST_MultiPolygon|f +2.5|0|42|ST_MultiPolygon|f +2.5|0|43|ST_MultiPolygon|f +2.5|0|44|ST_MultiPolygon|f +2.5|0|45|ST_MultiPolygon|f +2.5|0|46|ST_MultiPolygon|f +2.6|2|1|ST_Point|f +2.6|2|2|ST_Point|t +2.6|2|3|ST_Point|f +2.6|2|4|ST_Point|f +2.6|2|5|ST_Point|f +2.6|2|6|ST_Point|f +2.6|2|7|ST_Point|f +2.6|2|8|ST_Point|f +2.6|2|11|ST_MultiPoint|f +2.6|2|12|ST_MultiPoint|f +2.6|2|13|ST_MultiPoint|f +2.6|2|14|ST_MultiPoint|f +2.6|2|15|ST_MultiPoint|f +2.6|2|21|ST_LineString|f +2.6|2|22|ST_LineString|f +2.6|2|23|ST_LineString|f +2.6|2|24|ST_LineString|f +2.6|2|25|ST_LineString|f +2.6|2|26|ST_LineString|f +2.6|2|27|ST_LineString|f +2.6|2|28|ST_LineString|f +2.6|2|29|ST_LineString|f +2.6|2|31|ST_Polygon|f +2.6|2|32|ST_Polygon|f +2.6|2|33|ST_Polygon|f +2.6|2|34|ST_Polygon|t +2.6|2|35|ST_Polygon|t +2.6|2|36|ST_Polygon|f +2.6|2|41|ST_MultiPolygon|f +2.6|2|42|ST_MultiPolygon|f +2.6|2|43|ST_MultiPolygon|f +2.6|2|44|ST_MultiPolygon|f +2.6|2|45|ST_MultiPolygon|f +2.6|2|46|ST_MultiPolygon|f +2.7|1|0|ST_Point|f +2.7|2|0|ST_Point|f +2.7|3|0|ST_Point|f +2.7|4|0|ST_Point|f +2.7|5|0|ST_Point|f +2.7|6|0|ST_Point|f +2.7|7|0|ST_Point|f +2.7|8|0|ST_Point|f +2.7|11|0|ST_MultiPoint|f +2.7|12|0|ST_MultiPoint|f +2.7|13|0|ST_MultiPoint|f +2.7|14|0|ST_MultiPoint|f +2.7|15|0|ST_MultiPoint|f +2.7|21|0|ST_LineString|f +2.7|22|0|ST_LineString|f +2.7|23|0|ST_LineString|f +2.7|24|0|ST_LineString|f +2.7|25|0|ST_LineString|f +2.7|26|0|ST_LineString|f +2.7|27|0|ST_LineString|f +2.7|28|0|ST_LineString|f +2.7|29|0|ST_LineString|f +2.7|31|0|ST_Polygon|t +2.7|32|0|ST_Polygon|t +2.7|33|0|ST_Polygon|f +2.7|34|0|ST_Polygon|f +2.7|35|0|ST_Polygon|f +2.7|36|0|ST_Polygon|f +2.7|41|0|ST_MultiPolygon|t +2.7|42|0|ST_MultiPolygon|t +2.7|43|0|ST_MultiPolygon|f +2.7|44|0|ST_MultiPolygon|f +2.7|45|0|ST_MultiPolygon|f +2.7|46|0|ST_MultiPolygon|f +2.8|1|2|ST_Point|f +2.8|2|2|ST_Point|f +2.8|3|2|ST_Point|f +2.8|4|2|ST_Point|f +2.8|5|2|ST_Point|f +2.8|6|2|ST_Point|f +2.8|7|2|ST_Point|f +2.8|8|2|ST_Point|f +2.8|11|2|ST_MultiPoint|f +2.8|12|2|ST_MultiPoint|f +2.8|13|2|ST_MultiPoint|f +2.8|14|2|ST_MultiPoint|f +2.8|15|2|ST_MultiPoint|f +2.8|21|2|ST_LineString|f +2.8|22|2|ST_LineString|f +2.8|23|2|ST_LineString|f +2.8|24|2|ST_LineString|f +2.8|25|2|ST_LineString|f +2.8|26|2|ST_LineString|f +2.8|27|2|ST_LineString|f +2.8|28|2|ST_LineString|f +2.8|29|2|ST_LineString|f +2.8|31|2|ST_Polygon|f +2.8|32|2|ST_Polygon|f +2.8|33|2|ST_Polygon|f +2.8|34|2|ST_Polygon|f +2.8|35|2|ST_Polygon|f +2.8|36|2|ST_Polygon|f +2.8|41|2|ST_MultiPolygon|f +2.8|42|2|ST_MultiPolygon|f +2.8|43|2|ST_MultiPolygon|f +2.8|44|2|ST_MultiPolygon|f +2.8|45|2|ST_MultiPolygon|f +2.8|46|2|ST_MultiPolygon|f