Class SpatialDWithin
- Namespace
- YndigoBlue.Velocity.Functions
- Assembly
- YndigoBlue.Velocity.dll
Represents the ST_DWITHIN spatial function that tests whether two geometries are within a given distance of each other, returning a boolean rather than the distance itself.
public class SpatialDWithin : Function, ICheckItem, IDefaultItem, IFilterItem, IElement
- Inheritance
-
SpatialDWithin
- Implements
Remarks
Warning
Spatial functions are not available in the Community Edition of Velocity. They require the Full Edition.
SpatialDWithin answers "are these two things within X of each other?" as a single boolean
predicate — the same question SpatialDistance answers indirectly by computing an exact
distance and comparing it yourself (e.g. new Criterion<double>(new Expression(new
SpatialDistance(a, b)), ConditionalType.LessThanOrEqualTo, threshold)). Prefer
SpatialDWithin whenever the threshold comparison is the point — a spatially-indexed backend
can answer it directly (first narrowing candidates by their bounding box, then confirming the exact
distance) instead of computing an exact distance for every row before any comparison can happen.
PostgreSQL only. Unlike every other function in this namespace, ST_DWITHIN
(or an equivalent that preserves its indexed-lookup behavior) has no equivalent on any of Velocity's
other supported databases today. Calling this function against a non-PostgreSQL connection throws
NotSupportedException at query-build time — deliberately, rather than emitting SQL
that would fail unpredictably at the database. If your data layer must stay portable across
datasources, use SpatialDistance with an explicit threshold comparison instead; it's
slower on PostgreSQL (no index pushdown) but works identically everywhere Velocity runs.
Units of Measure. As with SpatialDistance, the distance
(or distanceExpression) argument is interpreted against a planar NetTopologySuite.Geometries.Geometry pair
in that geometry's own coordinate units (degrees, for the common WGS84 case), and against a
Geography pair in meters unless a UnitOfMeasure overload is used, in
which case the distance is converted to meters before being evaluated. See UnitOfMeasure.
Examples
var schema = manager.LoadSchema("logistics");
var stores = schema["stores"];
var centers = schema["distribution_centers"];
// Stores within 5 kilometers of any distribution center
var query = new Query()
.Select(stores["name"])
.From(stores)
.Where(new Criterion<bool>(
new Expression(new SpatialDWithin(stores["location"], centers["location"], 5.0F, UnitOfMeasure.Kilometer)),
true));
var results = manager.Retrieve(query);
Constructors
- SpatialDWithin(Geometry, Column, float)
Tests whether a literal geometry is within
distanceof a geometry column.
- SpatialDWithin(Geometry, Function, float)
Tests whether a literal geometry is within
distanceof the result of a spatial function.
- SpatialDWithin(Column, Geometry, float)
Tests whether a geometry column is within
distanceof a literal geometry.
- SpatialDWithin(Column, Column, float)
Tests whether two columns (a spatial join predicate) are within
distanceof each other.
- SpatialDWithin(Column, Column, float, UnitOfMeasure)
Tests whether two geography columns (a spatial join predicate) are within
distance(expressed inunitOfMeasure) of each other.
- SpatialDWithin(Column, Function, float)
Tests whether a geometry column is within
distanceof the result of a spatial function.
- SpatialDWithin(Column, Function, float, UnitOfMeasure)
Tests whether a geography column is within
distance(expressed inunitOfMeasure) of the result of a spatial function.
- SpatialDWithin(Column, Geography, float)
Tests whether a geography column is within
distancemeters of a literal geography.
- SpatialDWithin(Column, Geography, float, UnitOfMeasure)
Tests whether a geography column is within
distance(expressed inunitOfMeasure) of a literal geography.
- SpatialDWithin(Function, Geometry, float)
Tests whether the result of a spatial function is within
distanceof a literal geometry.
- SpatialDWithin(Function, Column, float)
Tests whether the result of a spatial function is within
distanceof a geometry column.
- SpatialDWithin(Function, Column, float, UnitOfMeasure)
Tests whether the result of a spatial function is within
distance(expressed inunitOfMeasure) of a geography column.
- SpatialDWithin(Function, Function, float)
Tests whether the results of two spatial functions are within
distanceof each other.
- SpatialDWithin(Function, Function, float, UnitOfMeasure)
Tests whether the results of two spatial functions are within
distance(expressed inunitOfMeasure) of each other.
- SpatialDWithin(Function, Geography, float)
Tests whether the result of a spatial function is within
distancemeters of a literal geography.
- SpatialDWithin(Function, Geography, float, UnitOfMeasure)
Tests whether the result of a spatial function is within
distance(expressed inunitOfMeasure) of a literal geography.
- SpatialDWithin(Geography, Column, float)
Tests whether a literal geography is within
distancemeters of a geography column.
- SpatialDWithin(Geography, Column, float, UnitOfMeasure)
Tests whether a literal geography is within
distance(expressed inunitOfMeasure) of a geography column.
- SpatialDWithin(Geography, Function, float)
Tests whether a literal geography is within
distancemeters of the result of a spatial function.
- SpatialDWithin(Geography, Function, float, UnitOfMeasure)
Tests whether a literal geography is within
distance(expressed inunitOfMeasure) of the result of a spatial function.