<refnamediv>
<refname>ST_Intersects</refname>
- <refpurpose>Return true if the raster spatially intersects a separate raster or geometry. 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.</refpurpose>
+ <refpurpose>Return true if raster rastA spatially intersects raster rastB. 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.</refpurpose>
</refnamediv>
<refsynopsisdiv>
</paramdef>
</funcprototype>
- <funcprototype>
- <funcdef>boolean <function>ST_Intersects</function></funcdef>
- <paramdef>
- <type>raster </type>
- <parameter>rast</parameter>
- </paramdef>
- <paramdef>
- <type>integer </type>
- <parameter>nband</parameter>
- </paramdef>
- <paramdef>
- <type>geometry </type>
- <parameter>geommin</parameter>
- </paramdef>
- </funcprototype>
-
- <funcprototype>
- <funcdef>boolean <function>ST_Intersects</function></funcdef>
- <paramdef>
- <type>raster </type>
- <parameter>rast</parameter>
- </paramdef>
- <paramdef>
- <type>geometry </type>
- <parameter>geommin</parameter>
- </paramdef>
- <paramdef choice='opt'>
- <type>integer </type>
- <parameter>nband=NULL</parameter>
- </paramdef>
- </funcprototype>
-
- <funcprototype>
- <funcdef>boolean <function>ST_Intersects</function></funcdef>
- <paramdef>
- <type>geometry </type>
- <parameter>geommin</parameter>
- </paramdef>
- <paramdef>
- <type>raster </type>
- <parameter>rast</parameter>
- </paramdef>
- <paramdef choice='opt'>
- <type>integer </type>
- <parameter>nband=NULL</parameter>
- </paramdef>
- </funcprototype>
-
</funcsynopsis>
</refsynopsisdiv>
<title>Description</title>
<para>
- Return true if the raster spatially intersects a separate raster or geometry. 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.
+ Return true if raster rastA spatially intersects raster rastB. 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_Intersects(), the test will operate in either raster-space or geometry-space. If ST_Intersects(raster, ....), the test is in raster-space (the geometry is converted to a raster). If ST_Intersects(geometry, ...), the test is in geometry-space (the raster is converted to a set of pixel polygons).
+ This operand will make use of any indexes that may be available on the rasters.
</para>
</note>
- <note>
+
+ <para>
+ Enhanced: 2.0.0 support raster/raster intersects was introduced.
+ </para>
+
+ <warning>
<para>
- This operand will make use of any indexes that may be available on the geometries / rasters.
+ Changed: The ST_Intersects(raster, geometry) and ST_Intersects(geometry, raster) variants present before PostGIS 2.1.0 have been removed. Use ST_Intersects(ST_Polygon(raster), geometry) instead.
</para>
- </note>
-
- <para>Enhanced: 2.0.0 support raster/raster intersects was introduced.</para>
+ </warning>
+
</refsection>
<refsection>
<title>Examples</title>
- <programlisting>SELECT A.rid, g.gid , ST_Intersects(A.rast, g.geom) As inter
-FROM dummy_rast AS A CROSS JOIN
- (VALUES (1, ST_Point(3427928, 5793243.85) ) ,
- (2, ST_GeomFromText('LINESTRING(3427927.85 5793243.75,3427927.8 5793243.75,3427927.8 5793243.8)') ),
- (3, ST_GeomFromText('LINESTRING(1 2, 3 4)') )
- ) As g(gid,geom)
-WHERE A.rid =2 ;
-
- rid | gid | inter
------+-----+-------
- 2 | 1 | t
- 2 | 2 | t
- 2 | 3 | f
-</programlisting>
+ <programlisting>
+-- needs a new example
+ </programlisting>
</refsection>
<refsection>
<title>See Also</title>
<refnamediv>
<refname>ST_Overlaps</refname>
<refpurpose>
- Return true if the raster spatially overlaps a separate raster or geometry. 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.
+ Return true if raster rastA spatially overlaps raster rastB. 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.
</refpurpose>
</refnamediv>
</paramdef>
</funcprototype>
- <funcprototype>
- <funcdef>boolean <function>ST_Overlaps</function></funcdef>
- <paramdef>
- <type>raster </type>
- <parameter>rast</parameter>
- </paramdef>
- <paramdef>
- <type>integer </type>
- <parameter>nband</parameter>
- </paramdef>
- <paramdef>
- <type>geometry </type>
- <parameter>geommin</parameter>
- </paramdef>
- </funcprototype>
-
- <funcprototype>
- <funcdef>boolean <function>ST_Overlaps</function></funcdef>
- <paramdef>
- <type>raster </type>
- <parameter>rast</parameter>
- </paramdef>
- <paramdef>
- <type>geometry </type>
- <parameter>geommin</parameter>
- </paramdef>
- <paramdef choice='opt'>
- <type>integer </type>
- <parameter>nband=NULL</parameter>
- </paramdef>
- </funcprototype>
-
- <funcprototype>
- <funcdef>boolean <function>ST_Overlaps</function></funcdef>
- <paramdef>
- <type>geometry </type>
- <parameter>geommin</parameter>
- </paramdef>
- <paramdef>
- <type>raster </type>
- <parameter>rast</parameter>
- </paramdef>
- <paramdef choice='opt'>
- <type>integer </type>
- <parameter>nband=NULL</parameter>
- </paramdef>
- </funcprototype>
-
</funcsynopsis>
</refsynopsisdiv>
<title>Description</title>
<para>
- Return true if the raster spatially overlaps a separate raster or geometry. This means that the raster/raster or raster/geometry combinations intersect but one does not completely contain the other. 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.
+ Return true if raster rastA spatially overlaps raster rastB. This means that rastA and rastB intersect but one does not completely contain the other. 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>
- This operand will make use of any indexes that may be available on the geometries / rasters.
+ This operand will make use of any indexes that may be available on the rasters.
</para>
</note>
<refnamediv>
<refname>ST_Touches</refname>
<refpurpose>
- Return true if the raster spatially touch a separate raster or geometry. 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.
+ Return true if raster rastA spatially touch raster rastB. 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.
</refpurpose>
</refnamediv>
</paramdef>
</funcprototype>
- <funcprototype>
- <funcdef>boolean <function>ST_Touches</function></funcdef>
- <paramdef>
- <type>raster </type>
- <parameter>rast</parameter>
- </paramdef>
- <paramdef>
- <type>integer </type>
- <parameter>nband</parameter>
- </paramdef>
- <paramdef>
- <type>geometry </type>
- <parameter>geommin</parameter>
- </paramdef>
- </funcprototype>
-
- <funcprototype>
- <funcdef>boolean <function>ST_Touches</function></funcdef>
- <paramdef>
- <type>raster </type>
- <parameter>rast</parameter>
- </paramdef>
- <paramdef>
- <type>geometry </type>
- <parameter>geommin</parameter>
- </paramdef>
- <paramdef choice='opt'>
- <type>integer </type>
- <parameter>nband=NULL</parameter>
- </paramdef>
- </funcprototype>
-
- <funcprototype>
- <funcdef>boolean <function>ST_Touches</function></funcdef>
- <paramdef>
- <type>geometry </type>
- <parameter>geommin</parameter>
- </paramdef>
- <paramdef>
- <type>raster </type>
- <parameter>rast</parameter>
- </paramdef>
- <paramdef choice='opt'>
- <type>integer </type>
- <parameter>nband=NULL</parameter>
- </paramdef>
- </funcprototype>
-
</funcsynopsis>
</refsynopsisdiv>
<title>Description</title>
<para>
- 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.
+ Return true if raster rastA spatially touches raster rastB. This means that rastA and rastB 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>
- This operand will make use of any indexes that may be available on the geometries / rasters.
+ This operand will make use of any indexes that may be available on the rasters.
</para>
</note>
);
-----------------------------------------------------------------------
--- Raster/(Raster|Geometry) Spatial Relationship
+-- Raster/Raster Spatial Relationship
-----------------------------------------------------------------------
-----------------------------------------------------------------------
LANGUAGE 'sql' IMMUTABLE
COST 1000;
------------------------------------------------------------------------
--- ST_Intersects(raster, geometry) in raster-space
------------------------------------------------------------------------
-
-CREATE OR REPLACE FUNCTION _st_intersects(rast raster, geom geometry, nband integer DEFAULT NULL)
- RETURNS boolean
- AS $$
- DECLARE
- gr raster;
- scale double precision;
- BEGIN
- IF ST_Intersects(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_Intersects(rast, nband, gr, 1);
- END;
- $$ LANGUAGE 'plpgsql' IMMUTABLE
- COST 1000;
-
-CREATE OR REPLACE FUNCTION st_intersects(rast raster, geom geometry, nband integer DEFAULT NULL)
- RETURNS boolean
- AS $$ SELECT $1::geometry && $2 AND _st_intersects($1, $2, $3) $$
- LANGUAGE 'sql' IMMUTABLE
- COST 1000;
-
-CREATE OR REPLACE FUNCTION st_intersects(rast raster, nband integer, geom geometry)
- RETURNS boolean
- AS $$ SELECT $1::geometry && $3 AND _st_intersects($1, $3, $2) $$
- LANGUAGE 'sql' IMMUTABLE
- COST 1000;
-
------------------------------------------------------------------------
--- ST_Intersects(geometry, raster) in geometry-space
------------------------------------------------------------------------
-
--- This function can not be STRICT
-CREATE OR REPLACE FUNCTION _st_intersects(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_Intersects(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_Intersects(geom, surface);
- END IF;
-
- RETURN FALSE;
- END;
- $$ LANGUAGE 'plpgsql' IMMUTABLE
- COST 1000;
-
--- This function can not be STRICT
-CREATE OR REPLACE FUNCTION st_intersects(geom geometry, rast raster, nband integer DEFAULT NULL)
- RETURNS boolean AS
- $$ SELECT $1 && $2::geometry AND _st_intersects($1, $2, $3); $$
- LANGUAGE 'sql' IMMUTABLE
- COST 1000;
-
-----------------------------------------------------------------------
-- ST_Overlaps(raster, raster)
-----------------------------------------------------------------------
LANGUAGE 'sql' IMMUTABLE
COST 1000;
------------------------------------------------------------------------
--- ST_Overlaps(raster, geometry)
------------------------------------------------------------------------
-
-CREATE OR REPLACE FUNCTION _st_overlaps(rast raster, geom geometry, nband integer DEFAULT NULL)
- RETURNS boolean
- AS $$
- DECLARE
- gr raster;
- scale double precision;
- BEGIN
- IF ST_Overlaps(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_Overlaps(rast, nband, gr, 1);
- END;
- $$ LANGUAGE 'plpgsql' IMMUTABLE
- COST 1000;
-
-CREATE OR REPLACE FUNCTION st_overlaps(rast raster, geom geometry, nband integer DEFAULT NULL)
- RETURNS boolean
- AS $$ SELECT $1::geometry && $2 AND _st_overlaps($1, $2, $3) $$
- LANGUAGE 'sql' IMMUTABLE
- COST 1000;
-
-CREATE OR REPLACE FUNCTION st_overlaps(rast raster, nband integer, geom geometry)
- RETURNS boolean
- AS $$ SELECT $1::geometry && $3 AND _st_overlaps($1, $3, $2) $$
- LANGUAGE 'sql' IMMUTABLE
- COST 1000;
-
------------------------------------------------------------------------
--- ST_Overlaps(geometry, raster)
------------------------------------------------------------------------
-
--- This function can not be STRICT
-CREATE OR REPLACE FUNCTION st_overlaps(geom geometry, rast raster, nband integer DEFAULT NULL)
- RETURNS boolean AS
- $$ SELECT $1 && $2::geometry AND _st_overlaps($2, $1, $3); $$
- LANGUAGE 'sql' IMMUTABLE
- COST 1000;
-
-----------------------------------------------------------------------
-- ST_Touches(raster, raster)
-----------------------------------------------------------------------
LANGUAGE 'sql' IMMUTABLE
COST 1000;
------------------------------------------------------------------------
--- ST_Touches(raster, geometry)
------------------------------------------------------------------------
-
-CREATE OR REPLACE FUNCTION _st_touches(rast raster, geom geometry, nband integer DEFAULT NULL)
- RETURNS boolean
- AS $$
- DECLARE
- gr raster;
- scale double precision;
- BEGIN
- IF ST_Touches(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_Touches(rast, nband, gr, 1);
- END;
- $$ LANGUAGE 'plpgsql' IMMUTABLE
- COST 1000;
-
-CREATE OR REPLACE FUNCTION st_touches(rast raster, geom geometry, nband integer DEFAULT NULL)
- RETURNS boolean
- AS $$ SELECT $1::geometry && $2 AND _st_touches($1, $2, $3) $$
- LANGUAGE 'sql' IMMUTABLE
- COST 1000;
-
-CREATE OR REPLACE FUNCTION st_touches(rast raster, nband integer, geom geometry)
- RETURNS boolean
- AS $$ SELECT $1::geometry && $3 AND _st_touches($1, $3, $2) $$
- LANGUAGE 'sql' IMMUTABLE
- COST 1000;
-
------------------------------------------------------------------------
--- 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
- $$ SELECT $1 && $2::geometry AND _st_touches($2, $1, $3); $$
- LANGUAGE 'sql' IMMUTABLE
- COST 1000;
-
-----------------------------------------------------------------------
-- ST_Contains(raster, raster)
-----------------------------------------------------------------------
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
-----------------------------------------------------------------------
$$ LANGUAGE 'plpgsql' VOLATILE;
SELECT _drop_st_samealignment();
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);
-- function deprecated
DROP FUNCTION IF EXISTS st_bandsurface(raster, integer);
--- function deprecated
+-- function no longer exists
+DROP FUNCTION IF EXISTS st_intersects(raster, integer, geometry);
+DROP FUNCTION IF EXISTS st_intersects(raster, geometry, integer);
+DROP FUNCTION IF EXISTS st_intersects(geometry, raster, integer);
+DROP FUNCTION IF EXISTS _st_intersects(raster, geometry, integer);
+DROP FUNCTION IF EXISTS _st_intersects(geometry, raster, integer);
+
+-- function no longer exists
+DROP FUNCTION IF EXISTS st_overlaps(geometry, raster, integer);
+DROP FUNCTION IF EXISTS st_overlaps(raster, integer, geometry);
+DROP FUNCTION IF EXISTS st_overlaps(raster, geometry, integer);
+DROP FUNCTION IF EXISTS _st_overlaps(raster, geometry, integer);
DROP FUNCTION IF EXISTS _st_overlaps(geometry, raster, integer);
--- function deprecated
+-- function no longer exists
+DROP FUNCTION IF EXISTS st_touches(geometry, raster, integer);
+DROP FUNCTION IF EXISTS st_touches(raster, geometry, integer);
+DROP FUNCTION IF EXISTS st_touches(raster, integer, geometry);
DROP FUNCTION IF EXISTS _st_touches(geometry, raster, integer);
+DROP FUNCTION IF EXISTS _st_touches(raster, geometry, integer);
+
+-- function no longer exists
+DROP FUNCTION IF EXISTS st_contains(raster, geometry, integer);
+DROP FUNCTION IF EXISTS st_contains(raster, integer, geometry);
+DROP FUNCTION IF EXISTS st_contains(geometry, raster, integer);
+DROP FUNCTION IF EXISTS _st_contains(raster, geometry, integer);
+DROP FUNCTION IF EXISTS _st_contains(geometry, raster, integer);