ST_DWithin function
The ST_DWithin function determines if two geometries are within a specified distance.
Syntax
Parameter
- geometry1
-
A value of type ST_Geometry that represents the geometry that is to be compared with geometry2.
- geometry2
-
A value of type ST_Geometry that represents the geometry that is to be compared with geometry1.
- distance
-
A value of type DOUBLE that indicates the distance within which the two geometries must be.
- unit
-
VARCHAR(128) value that identifies the unit in which the result is measured. The supported units of measure are listed in the DB2GSE.ST_UNITS_OF_MEASURE catalog view.
If the unit parameter is omitted, the following rules are used to determine the unit of measure used for the result:- If geometry1 is in a projected or geocentric coordinate system, the linear unit associated with this coordinate system is the default.
- If geometry1 is in a geographic coordinate system, the angular unit associated with this coordinate system is the default.
Restrictions on unit conversions: An error (SQLSTATE 38SU4) is returned if any of the following conditions occur:- The geometry is in an unspecified coordinate system and the unit parameter is specified.
- The geometry is in a projected coordinate system and an angular unit is specified.
Return type
Returns 1
(true) if the geometries are within the specified distance of one
another, and 0
(false) if they are not.
If the geometries are not in a compatible spatial reference system, an error is returned.
Example
create table points (pk integer not null primary key, geo db2gse.ST_Point) organize by row;
insert into points values(1, db2gse.st_point(10,10, 1));
insert into points values(2, db2gse.st_point(10,15, 1));
insert into points values(3, db2gse.st_point(12,20, 1));
create table polys (pk integer not null primary key, geo db2gse.st_polygon ) organize by row;
insert into polys values (1, db2gse.ST_Polygon (db2gse.ST_LineString ('linestring (10 20, 10 40, 20 30, 10 20)',1), 1));
insert into polys values (2, db2gse.ST_Polygon ('polygon ((110 120, 110 140, 120 130, 110 120))', 1)),
select t1.pk as ptsid, t2.pk as plyid, db2gse.st_dwithin(t1.geo, t2.geo, 100.0) as dw from points t1, polys t2 order by dw desc;
PTSID PLYID DW
----------- ----------- -----------
3 1 1
1 1 0
2 1 0
1 2 0
2 2 0
3 2 0
6 record(s) selected.