STV_DWithin
Determines if the shortest distance from the boundary of one spatial object to the boundary of another object is within a specified distance.
Determines if the shortest distance from the boundary of one spatial object to the boundary of another object is within a specified distance.
Parameters g1
and g2
must be both GEOMETRY objects or both GEOGRAPHY objects.
Behavior type
ImmutableSyntax
STV_DWithin( g1, g2, d )
Arguments
g1
Spatial object of type GEOMETRY or GEOGRAPHY
g2
Spatial object of type GEOMETRY or GEOGRAPHY
d
- Value of type FLOAT indicating a distance. For GEOMETRY objects, the distance is measured in Cartesian coordinate units. For GEOGRAPHY objects, the distance is measured in meters.
Returns
BOOLEAN
Supported data types
Data Type | GEOMETRY | GEOGRAPHY (Perfect Sphere) |
---|---|---|
Point | Yes | Yes |
Multipoint | Yes | Yes |
Linestring | Yes | Yes |
Multilinestring | Yes | Yes |
Polygon | Yes | Yes |
Multipolygon | Yes | Yes |
GeometryCollection | Yes | No |
Compatible GEOGRAPHY pairs:
- Data Type
- GEOGRAPHY (Perfect Sphere)
- Point-Point
- Yes
- Point-Linestring
- Yes
- Point-Polygon
- Yes
- Point-Multilinestring
- Yes
- Point-Multipolygon
- Yes
Examples
The following examples show how to use STV_DWithin.
Two geometries are one Cartesian coordinate unit from each other at their closest points:
=> SELECT STV_DWithin(ST_GeomFromText('POLYGON((-1 -1,2 2,0 1,-1 -1))'),
ST_GeomFromText('POLYGON((4 3,2 3,4 5,4 3))'),1);
STV_DWithin
-------------
t
(1 row)
If you reduce the distance to 0.99 units:
=> SELECT STV_DWithin(ST_GeomFromText('POLYGON((-1 -1,2 2,0 1,-1 -1))'),
ST_GeomFromText('POLYGON((4 3,2 3,4 5,4 3))'),0.99);
STV_DWithin
-------------
f
(1 row)
The first polygon touches the second polygon:
=> SELECT STV_DWithin(ST_GeomFromText('POLYGON((-1 -1,2 2,0 1,-1 -1))'),
ST_GeomFromText('POLYGON((1 1,2 3,4 5,1 1))'),0.00001);
STV_DWithin
-------------
t
(1 row)
The first polygon is not within 1000 meters from the second polygon:
=> SELECT STV_DWithin(ST_GeomFromText('POLYGON((45.2 40,50.65 51.29,
55.67 47.6,50 47.6,45.2 40))'),ST_GeomFromText('POLYGON((25 25,25 30,
30 30,30 25,25 25))'), 1000);
STV_DWithin
--------------
t
(1 row)