ST_DWithin takes two geometry columns and a numeric distance value and returns a boolean column. The function returns
True
if the two geometries are spatially within the given distance; otherwise, it returns False
. For multipoints,
lines, and polygons, the distance is calculated from the nearest point between the geometries. You can optionally
provide a boolean value that determines if geodesic distances will be used by the function. Planar distances will be
used by default.
When using planar calculations, the distance value is specified in the same units as the input geometry.
When geodesic
is set to True
, the distance value is specified in meters. In both cases, the value can be set
using a numeric column or a single value.
If the two geometry columns are in different spatial references, the function will automatically transform the second geometry into the spatial reference of the first.
When using geodesic distances, the first geometry column must have a spatial reference set. To learn more see Coordinate systems and transformations.
This function may result in an optimized spatial join.
Function | Syntax |
---|---|
Python | dwithin(geometry1, geometry2, distance, geodesic= |
SQL | ST |
Scala | dwithin(geometry1, geometry2, distance, geodesic) |
For more details, go to the GeoAnalytics for Microsoft Fabric API reference for dwithin.
Examples
from geoanalytics_fabric.sql import functions as ST, Point
data = [
(Point(-176, -15), Point(-176, -15)),
(Point(-176, -15), Point(-176, -20)),
(Point(-176, -15), Point(-175, -15))
]
df = spark.createDataFrame(data, ["point1", "point2"])
df.select(ST.dwithin("point1", "point2", 3.0).alias("dwithin")).show()
+-------+
|dwithin|
+-------+
| true|
| false|
| true|
+-------+
Version table
Release | Notes |
---|---|
1.0.0-beta | Python, SQL, and Scala functions introduced |