Return true if the raster spatially touches a separate raster or geometry. This means that the raster/raster or raster/geometry combinations have at least one point in common but their interiors do not intersect. If the band number is not provided (or set to NULL), only the convex hull of the raster is considered in the test. If the band number is provided, only those pixels with value (not NODATA) are considered in the test.
</para>
- <note>
- <para>
- Depending on the order that the raster and geometry is passed to ST_Touches(), the test will operate in either raster-space or geometry-space. If ST_Touches(raster, ....), the test is in raster-space (the geometry is converted to a raster). If ST_Touches(geometry, ...), the test is in geometry-space (the raster is converted to a set of pixel polygons).
- </para>
- </note>
-
<note>
<para>
This operand will make use of any indexes that may be available on the geometries / rasters.
COST 1000;
-----------------------------------------------------------------------
--- ST_Touches(raster, geometry) in raster-space
+-- ST_Touches(raster, geometry)
-----------------------------------------------------------------------
CREATE OR REPLACE FUNCTION _st_touches(rast raster, geom geometry, nband integer DEFAULT NULL)
COST 1000;
-----------------------------------------------------------------------
--- ST_Touches(geometry, raster) in geometry-space
+-- ST_Touches(geometry, raster)
-----------------------------------------------------------------------
--- This function can not be STRICT
-CREATE OR REPLACE FUNCTION _st_touches(geom geometry, rast raster, nband integer DEFAULT NULL)
- RETURNS boolean AS $$
- DECLARE
- convexhull geometry;
- hasnodata boolean := TRUE;
- surface geometry;
- BEGIN
- convexhull := ST_ConvexHull(rast);
- IF nband IS NOT NULL THEN
- SELECT CASE WHEN bmd.nodatavalue IS NULL THEN FALSE ELSE NULL END INTO hasnodata FROM ST_BandMetaData(rast, nband) AS bmd;
- END IF;
-
- IF ST_Touches(geom, convexhull) IS NOT TRUE THEN
- RETURN FALSE;
- ELSEIF nband IS NULL OR hasnodata IS FALSE THEN
- RETURN TRUE;
- END IF;
-
- -- get band polygon
- surface := ST_Polygon(rast, nband);
-
- IF surface IS NOT NULL THEN
- RETURN ST_Touches(geom, surface);
- END IF;
-
- RETURN FALSE;
- END;
- $$ LANGUAGE 'plpgsql' IMMUTABLE
- COST 1000;
-
-- This function can not be STRICT
CREATE OR REPLACE FUNCTION st_touches(geom geometry, rast raster, nband integer DEFAULT NULL)
RETURNS boolean AS
- $$ SELECT $1 && $2::geometry AND _st_touches($1, $2, $3); $$
+ $$ SELECT $1 && $2::geometry AND _st_touches($2, $1, $3); $$
LANGUAGE 'sql' IMMUTABLE
COST 1000;