Class SpatialDistance
- Namespace
- YndigoBlue.Velocity.Functions
- Assembly
- YndigoBlue.Velocity.dll
Represents the ST_Distance spatial function that calculates the minimum distance between two geometries or geographies.
public class SpatialDistance : Function, ICheckItem, IDefaultItem, IFilterItem, IElement
- Inheritance
-
SpatialDistance
- Implements
Remarks
Warning
Spatial functions are not available in the Community Edition of Velocity. They require the Full Edition.
The ST_Distance function returns the shortest distance between two spatial objects. For Geometry types (planar), it calculates Euclidean distance in the coordinate system units. For Geography types (spherical), it calculates great-circle distance on the earth's surface, optionally in specified units. This is useful for proximity queries, finding nearest neighbors, or spatial indexing. OGC-compliant.
Return Type: Numeric (float/double). Units depend on coordinate system or specified UnitOfMeasure.
Distance Calculation Rules:
| Relationship | Distance Result |
|---|---|
| Geometries touch or overlap | 0 |
| Geometries are separate | Minimum distance between closest points |
| One inside the other | 0 (they overlap) |
Example Results: ST_Distance(PY0, X)
| Shape X | Distance (in degrees) |
|---|---|
| PY1 (inside PY0) | 0 - contained within |
| PY2 (outside PY0) | 2° - gap between edges |
| PY3 (touches PY0) | 0 - shares boundary |
| PT1 (inside PY0) | 0 - point within polygon |
| PT2 (outside PY0) | 3° - horizontal distance to edge |
| LN1 (inside PY0) | 0 - line within polygon |
Units of Measure: For Geography types, use UnitOfMeasure to get results in meters, kilometers, miles, or other supported units.
| UnitOfMeasure | Result (GA at -102°,38° to GB at -96°,43°, approx. 750 km) |
|---|---|
| Meter | 750,000 |
| Kilometer | 750 |
| Mile | 466 |
| Foot | 2,460,630 |
| Yard | 820,210 |
| Inch | 29,527,559 |
Examples
Calculate the distance from each store to a target point, ordering by proximity:
var schema = manager.LoadSchema("retail");
var stores = schema["stores"];
var target = new Point(new Coordinate(-73.9857, 40.7484));
var query = new Query()
.Select([ stores["id"], stores["name"], new Expression("dist", new SpatialDistance(stores["location"], target)) ])
.From(stores)
.OrderBy(new Expression("dist", new SpatialDistance(stores["location"], target)));
var results = manager.Retrieve(query);
Constructors
- SpatialDistance(Geometry, Column)
Initializes a new instance of ST_Distance with a Geometry literal and a column.
- SpatialDistance(Geometry, Function)
Initializes a new instance of ST_Distance with a Geometry literal and function result for function chaining.
- SpatialDistance(Column, Geometry)
Initializes a new instance of ST_Distance with a column and a Geometry literal.
- SpatialDistance(Column, Column)
Initializes a new instance of ST_Distance with two columns for spatial joins.
- SpatialDistance(Column, Column, UnitOfMeasure)
Initializes a new instance of ST_Distance with two columns and unit of measure for spatial joins.
- SpatialDistance(Column, Function)
Initializes a new instance of ST_Distance with a column and function result for function chaining.
- SpatialDistance(Column, Function, UnitOfMeasure)
Initializes a new instance of ST_Distance with a column, function result, and unit of measure for function chaining.
- SpatialDistance(Column, Geography)
Initializes a new instance of ST_Distance with a column and a Geography literal.
- SpatialDistance(Column, Geography, UnitOfMeasure)
Initializes a new instance of ST_Distance with a column, Geography, and unit of measure.
- SpatialDistance(Function, Geometry)
Initializes a new instance of ST_Distance with a function result and Geometry literal for function chaining.
- SpatialDistance(Function, Column)
Initializes a new instance of ST_Distance with a function result and column for function chaining.
- SpatialDistance(Function, Column, UnitOfMeasure)
Initializes a new instance of ST_Distance with a function result, column, and unit of measure for function chaining.
- SpatialDistance(Function, Function)
Initializes a new instance of ST_Distance with two function results for function chaining.
- SpatialDistance(Function, Function, UnitOfMeasure)
Initializes a new instance of ST_Distance with two function results and unit of measure for function chaining.
- SpatialDistance(Function, Geography)
Initializes a new instance of ST_Distance with a function result and Geography literal for function chaining.
- SpatialDistance(Function, Geography, UnitOfMeasure)
Initializes a new instance of ST_Distance with a function result, Geography literal, and unit of measure for function chaining.
- SpatialDistance(Geography, Column)
Initializes a new instance of ST_Distance with a Geography literal and a column.
- SpatialDistance(Geography, Column, UnitOfMeasure)
Initializes a new instance of ST_Distance with a Geography, column, and unit of measure.
- SpatialDistance(Geography, Function)
Initializes a new instance of ST_Distance with a Geography literal and function result for function chaining.
- SpatialDistance(Geography, Function, UnitOfMeasure)
Initializes a new instance of ST_Distance with a Geography literal, function result, and unit of measure for function chaining.