An inexpensive of whether two geometries might be 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_WithinDistanceFilter( 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 |
16 | 1.41 |
The following example creates points representing Halifax, NS and Waterloo, ON, Canada, and uses ST_WithinDistanceFilter to demonstrate that the distance between the two points might be within 850 miles, but definitely is not within 750 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_WithinDistanceFilter( NEW ST_Point( -80.522372, 43.465187, 4326 ) , 850, 'Statute mile' ) within850, NEW ST_Point( -63.573566, 44.646244, 4326 ) .ST_WithinDistanceFilter( NEW ST_Point( -80.522372, 43.465187, 4326 ) , 750, 'Statute mile' ) within750
within850 | within750 |
---|---|
1 | 0 |
SQL/MM (ISO/IEC 13249-3: 2006) Vendor extension