Test if two geometries are within a specified distance of each other.
SELECT ShapeID, ROUND( Shape.ST_Distance( NEW ST_Point( 2, 3 ) ), 2 ) AS dist FROM SpatialShapes WHERE ShapeID < 17 AND Shape.ST_WithinDistance( NEW ST_Point( 2, 3 ), 1.4 ) = 1 ORDER BY dist
ShapeID | dist |
---|---|
2 | 0.0 |
3 | 0.0 |
5 | 1.0 |
6 | 1.21 |
The following example creates points representing Halifax, NS and Waterloo, ON, Canada and uses ST_WithinDistance to demonstrate that the distance between the two points is within 850 miles, but not within 840 miles. This example assumes that the 'st_geometry_predefined_uom' feature has been installed by the sa_install_feature system procedure. Seesa_install_feature system procedure.
SELECT NEW ST_Point( -63.573566, 44.646244, 4326 ) .ST_WithinDistance( NEW ST_Point( -80.522372, 43.465187, 4326 ) , 850, 'Statute mile' ) within850, NEW ST_Point( -63.573566, 44.646244, 4326 ) .ST_WithinDistance( NEW ST_Point( -80.522372, 43.465187, 4326 ) , 840, 'Statute mile' ) within840
within850 | within840 |
---|---|
1 | 0 |
SQL/MM (ISO/IEC 13249-3: 2006) Vendor extension