Make a Spatial Query


  • Documents that contain spatial data can be queried by spatial queries that employ geographical criteria.
    You have two options:

    • Dynamic spatial query
      Either make a dynamic spatial query on a collection ( described in this article ).
      An auto-index will be created by the server.

    • Spatial index query
      Or, index your documents' spatial data in a static-index (see indexing spatial data),
      and then make a spatial query on this index (see query a spatial index).

  • To perform a spatial search,
    use the Spatial method which provides a wide range of spatial functionalities.

  • When making a dynamic spatial query from the Studio,
    results are also displayed on the global map. See spatial queries map view.



Search by radius

Use the WithinRadius method to search for all documents containing spatial data that is located
within the specified distance from the given center point.

// This query will return all matching employee entities
// that are located within 20 kilometers radius
// from point (47.623473 latitude, -122.3060097 longitude).

// Define a dynamic query on Employees collection
List<Employee> employeesWithinRadius = session
    .Query<Employee>()
     // Call 'Spatial' method
    .Spatial(
        // Call 'Point'
        // Pass the path to the document fields containing the spatial data
        pointField => pointField.Point(
            x => x.Address.Location.Latitude, 
            x => x.Address.Location.Longitude),
        // Set the geographical area in which to search for matching documents
        // Call 'WithinRadius', pass the radius and the center points coordinates  
        criteria => criteria.WithinRadius(20, 47.623473, -122.3060097))
    .ToList();
// This query will return all matching employee entities
// that are located within 20 kilometers radius
// from point (47.623473 latitude, -122.3060097 longitude).

// Define a dynamic query on Employees collection
List<Employee> employeesWithinRadius = await asyncSession
    .Query<Employee>()
     // Call 'Spatial' method
    .Spatial(
        // Call 'Point'
        // Pass the path to the document fields containing the spatial data
        pointField => pointField.Point(
            x => x.Address.Location.Latitude, 
            x => x.Address.Location.Longitude),
        // Set the geographical area in which to search for matching documents
        // Call 'WithinRadius', pass the radius and the center points coordinates  
        criteria => criteria.WithinRadius(20, 47.623473, -122.3060097))
    .ToListAsync();
// This query will return all matching employee entities
// that are located within 20 kilometers radius
// from point (47.623473 latitude, -122.3060097 longitude).

// Define a dynamic query on Employees collection
List<Employee> employeesWithinRadius = session.Advanced
    .DocumentQuery<Employee>()
    // Call 'Spatial' method
    .Spatial(
        // Call 'Point'
        // Pass the path to the document fields containing the spatial data
        pointField => pointField.Point(
            x => x.Address.Location.Latitude, 
            x => x.Address.Location.Longitude),
        // Set the geographical area in which to search for matching documents
        // Call 'WithinRadius', pass the radius and the center points coordinates  
        criteria => criteria.WithinRadius(20, 47.623473, -122.3060097))
    .ToList();
// This query will return all matching employee entities
// that are located within 20 kilometers radius
// from point (47.623473 latitude, -122.3060097 longitude).

from Employees
where spatial.within(
    spatial.point(Address.Location.Latitude, Address.Location.Longitude),
    spatial.circle(20, 47.623473, -122.3060097)
)

Search by shape

  • Use the RelatesToShape method to search for all documents containing spatial data that is located
    in the specified relation to the given shape.

  • The shape is specified as either a circle or a polygon in a WKT format.

  • The relation to the shape can be one of: Within, Contains, Disjoint, Intersects.

Circle:

// This query will return all matching employee entities
// that are located within 20 kilometers radius
// from point (47.623473 latitude, -122.3060097 longitude).

// Define a dynamic query on Employees collection
List<Employee> employeesWithinShape = session
    .Query<Employee>()
     // Call 'Spatial' method
    .Spatial(
        // Call 'Point'
        // Pass the path to the document fields containing the spatial data
        factory => factory.Point(
            x => x.Address.Location.Latitude,
            x => x.Address.Location.Longitude),
        // Set the geographical search criteria, call 'RelatesToShape'
        criteria => criteria.RelatesToShape(
            // Specify the WKT string. Note: longitude is written FIRST
            shapeWkt: "CIRCLE(-122.3060097 47.623473 d=20)",
            // Specify the relation between the WKT shape and the documents spatial data
            relation: SpatialRelation.Within,
            // Optional: customize radius units (default is Kilometers)
            units: SpatialUnits.Miles))  
    .ToList();
// This query will return all matching employee entities
// that are located within 20 kilometers radius
// from point (47.623473 latitude, -122.3060097 longitude).

// Define a dynamic query on Employees collection
List<Employee> employeesWithinShape = await asyncSession
    .Query<Employee>()
     // Call 'Spatial' method
    .Spatial(
        // Call 'Point'
        // Pass the path to the document fields containing the spatial data
        factory => factory.Point(
            x => x.Address.Location.Latitude,
            x => x.Address.Location.Longitude),
        // Set the geographical search criteria, call 'RelatesToShape'
        criteria => criteria.RelatesToShape(
            // Specify the WKT string. Note: longitude is written FIRST
            shapeWkt: "CIRCLE(-122.3060097 47.623473 d=20)",
            // Specify the relation between the WKT shape and the documents spatial data
            relation: SpatialRelation.Within,
            // Optional: customize radius units (default is Kilometers)
            units: SpatialUnits.Miles))  
    .ToListAsync();
// This query will return all matching employee entities
// that are located within 20 kilometers radius
// from point (47.623473 latitude, -122.3060097 longitude).

// Define a dynamic query on Employees collection
List<Employee> employeesWithinShape = session.Advanced
    .DocumentQuery<Employee>()
     // Call 'Spatial' method
    .Spatial(
        // Call 'Point'
        // Pass the path to the document fields containing the spatial data
        factory => factory.Point(
            x => x.Address.Location.Latitude,
            x => x.Address.Location.Longitude),
        // Set the geographical search criteria, call 'RelatesToShape'
        criteria => criteria.RelatesToShape(
            // Specify the WKT string. Note: longitude is written FIRST
            shapeWkt: "CIRCLE(-122.3060097 47.623473 d=20)",
            // Specify the relation between the WKT shape and the documents spatial data
            relation: SpatialRelation.Within,
            // Optional: customize radius units (default is Kilometers)
            units: SpatialUnits.Miles))  
    .ToList();
// This query will return all matching employee entities
// that are located within 20 kilometers radius
// from point (47.623473 latitude, -122.3060097 longitude).

from Employees
where spatial.within(
    spatial.point(Address.Location.Latitude, Address.Location.Longitude),
    spatial.wkt("CIRCLE(-122.3060097 47.623473 d=20)", "miles")
)

Polygon:

// This query will return all matching company entities
// that are located within the specified polygon.

// Define a dynamic query on Companies collection
List<Company> companiesWithinShape = session
    .Query<Company>()
     // Call 'Spatial' method
    .Spatial(
        // Call 'Point'
        // Pass the path to the document fields containing the spatial data
        factory => factory.Point(
            x => x.Address.Location.Latitude,
            x => x.Address.Location.Longitude),
        // Set the geographical search criteria, call 'RelatesToShape'
        criteria => criteria.RelatesToShape(
            // Specify the WKT string
            shapeWkt: @"POLYGON ((
                           -118.6527948 32.7114894,
                           -95.8040242 37.5929338,
                           -102.8344151 53.3349629,
                           -127.5286633 48.3485664,
                           -129.4620208 38.0786067,
                           -118.7406746 32.7853769,
                           -118.6527948 32.7114894
                      ))",
            // Specify the relation between the WKT shape and the documents spatial data
            relation: SpatialRelation.Within))  
    .ToList();
// This query will return all matching company entities
// that are located within the specified polygon.

// Define a dynamic query on Companies collection
List<Company> companiesWithinShape = await asyncSession
    .Query<Company>()
     // Call 'Spatial' method
    .Spatial(
        // Call 'Point'
        // Pass the path to the document fields containing the spatial data
        factory => factory.Point(
            x => x.Address.Location.Latitude,
            x => x.Address.Location.Longitude),
        // Set the geographical search criteria, call 'RelatesToShape'
        criteria => criteria.RelatesToShape(
            // Specify the WKT string
            shapeWkt: @"POLYGON ((
                           -118.6527948 32.7114894,
                           -95.8040242 37.5929338,
                           -102.8344151 53.3349629,
                           -127.5286633 48.3485664,
                           -129.4620208 38.0786067,
                           -118.7406746 32.7853769,
                           -118.6527948 32.7114894
                      ))",
            // Specify the relation between the WKT shape and the documents spatial data
            relation: SpatialRelation.Within))  
    .ToListAsync();
// This query will return all matching company entities
// that are located within the specified polygon.

// Define a dynamic query on Companies collection
List<Company> companiesWithinShape = session.Advanced
    .DocumentQuery<Company>()
    // Call 'Spatial' method
    .Spatial(
        // Call 'Point'
        // Pass the path to the document fields containing the spatial data
        factory => factory.Point(
            x => x.Address.Location.Latitude,
            x => x.Address.Location.Longitude),
        // Set the geographical search criteria, call 'RelatesToShape'
        criteria => criteria.RelatesToShape(
            // Specify the WKT string
            shapeWkt: @"POLYGON ((
                           -118.6527948 32.7114894,
                           -95.8040242 37.5929338,
                           -102.8344151 53.3349629,
                           -127.5286633 48.3485664,
                           -129.4620208 38.0786067,
                           -118.7406746 32.7853769,
                           -118.6527948 32.7114894
                      ))",
            // Specify the relation between the WKT shape and the documents spatial data
            relation: SpatialRelation.Within))  
    .ToList();
// This query will return all matching company entities
// that are located within the specified polygon.

from companies
where spatial.within(
    spatial.point(Address.Location.Latitude, Address.Location.Longitude),
    spatial.wkt("POLYGON ((
        -118.6527948 32.7114894,
        -95.8040242 37.5929338,
        -102.8344151 53.3349629,
        -127.5286633 48.3485664,
        -129.4620208 38.0786067,
        -118.7406746 32.7853769,
        -118.6527948 32.7114894))")
)

Polygon rules:

  • The polygon's coordinates must be provided in counterclockwise order.

  • The first and last coordinates must mark the same location to form a closed region.

WKT polygon

WKT Polygon

Spatial sorting

  • Use OrderByDistance or OrderByDistanceDescending to sort the results by distance from a given point.

  • By default, distance in RavenDB measured in kilometers.
    The distance can be rounded to a specific range.

Order by distance:

// Return all matching employee entities located within 20 kilometers radius
// from point (47.623473 latitude, -122.3060097 longitude).

// Sort the results by their distance from a specified point,
// the closest results will be listed first.

List<Employee> employeesSortedByDistance = session
    .Query<Employee>()
     // Provide the query criteria:
    .Spatial(
        pointField => pointField.Point(
            x => x.Address.Location.Latitude,
            x => x.Address.Location.Longitude
        ),
        criteria => criteria.WithinRadius(20, 47.623473, -122.3060097))
     // Call 'OrderByDistance'
    .OrderByDistance(
        factory => factory.Point(
            // Pass the path to the document fields containing the spatial data
            x => x.Address.Location.Latitude,
            x => x.Address.Location.Longitude
        ),
        // Sort the results by their distance from this point: 
        47.623473, -122.3060097)
    .ToList();
// Return all matching employee entities located within 20 kilometers radius
// from point (47.623473 latitude, -122.3060097 longitude).

// Sort the results by their distance from a specified point,
// the closest results will be listed first.

List<Employee> employeesSortedByDistance = await asyncSession
    .Query<Employee>()
     // Provide the query criteria:
    .Spatial(
        pointField => pointField.Point(
            x => x.Address.Location.Latitude,
            x => x.Address.Location.Longitude
        ),
        criteria => criteria.WithinRadius(20, 47.623473, -122.3060097))
     // Call 'OrderByDistance'
    .OrderByDistance(
        factory => factory.Point(
            // Pass the path to the document fields containing the spatial data
            x => x.Address.Location.Latitude,
            x => x.Address.Location.Longitude
        ),
        // Sort the results by their distance from this point: 
        47.623473, -122.3060097)
    .ToListAsync();
// Return all matching employee entities located within 20 kilometers radius
// from point (47.623473 latitude, -122.3060097 longitude).

// Sort the results by their distance from a specified point,
// the closest results will be listed first.

List<Employee> employeesSortedByDistance = session.Advanced
    .DocumentQuery<Employee>()
     // Provide the query criteria:
    .Spatial(
        pointField => pointField.Point(
            x => x.Address.Location.Latitude,
            x => x.Address.Location.Longitude
        ),
        criteria => criteria.WithinRadius(20, 47.623473, -122.3060097))
     // Call 'OrderByDistance'
    .OrderByDistance(
        factory => factory.Point(
            // Pass the path to the document fields containing the spatial data
            x => x.Address.Location.Latitude,
            x => x.Address.Location.Longitude
        ),
        // Sort the results by their distance from this point: 
        47.623473, -122.3060097)
    .ToList();
// Return all matching employee entities located within 20 kilometers radius
// from point (47.623473 latitude, -122.3060097 longitude).

// Sort the results by their distance from a specified point,
// the closest results will be listed first.       

from Employees
where spatial.within(
    spatial.point(Address.Location.Latitude, Address.Location.Longitude),
    spatial.circle(20, 47.623473, -122.3060097)
)
order by spatial.distance(
    spatial.point(Address.Location.Latitude, Address.Location.Longitude),
    spatial.point(47.623473, -122.3060097)
)

Order by distance descending:

// Return all employee entities sorted by their distance from a specified point.
// The farthest results will be listed first.

List<Employee> employeesSortedByDistanceDesc = session
    .Query<Employee>()
     // Call 'OrderByDistanceDescending'
    .OrderByDistanceDescending(
        factory => factory.Point(
            // Pass the path to the document fields containing the spatial data
            x => x.Address.Location.Latitude,
            x => x.Address.Location.Longitude
        ),
        // Sort the results by their distance (descending) from this point: 
        47.623473, -122.3060097)
    .ToList();
// Return all employee entities sorted by their distance from a specified point.
// The farthest results will be listed first.

List<Employee> employeesSortedByDistanceDesc = await asyncSession
    .Query<Employee>()
     // Call 'OrderByDistanceDescending'
    .OrderByDistanceDescending(
        factory => factory.Point(
            // Pass the path to the document fields containing the spatial data
            x => x.Address.Location.Latitude,
            x => x.Address.Location.Longitude
        ),
        // Sort the results by their distance (descending) from this point: 
        47.623473, -122.3060097)
    .ToListAsync();
// Return all employee entities sorted by their distance from a specified point.
// The farthest results will be listed first.

List<Employee> employeesSortedByDistanceDesc = session.Advanced
    .DocumentQuery<Employee>()
     // Call 'OrderByDistanceDescending'
    .OrderByDistanceDescending(
        factory => factory.Point(
            // Pass the path to the document fields containing the spatial data
            x => x.Address.Location.Latitude,
            x => x.Address.Location.Longitude
        ),
        // Sort the results by their distance (descending) from this point: 
        47.623473, -122.3060097)
    .ToList();
// Return all employee entities sorted by their distance from a specified point.
// The farthest results will be listed first.

from Employees
order by spatial.distance(
    spatial.point(Address.Location.Latitude, Address.Location.Longitude),
    spatial.point(47.623473, -122.3060097)
) desc

Sort results by rounded distance:

// Return all employee entities.
// Results are sorted by their distance to a specified point rounded to the nearest 100 km interval.
// A secondary sort can be applied within the 100 km range, e.g. by field LastName.

List<Employee> employeesSortedByRoundedDistance = session
    .Query<Employee>()
     // Call 'OrderByDistance'
    .OrderByDistance(
        factory => factory.Point(
                // Pass the path to the document fields containing the spatial data
                x => x.Address.Location.Latitude,
                x => x.Address.Location.Longitude)
             // Round up distance to 100 km 
            .RoundTo(100),
        // Sort the results by their distance from this point: 
        47.623473, -122.3060097)
     // A secondary sort can be applied
    .ThenBy(x => x.LastName)
    .ToList();
// Return all employee entities.
// Results are sorted by their distance to a specified point rounded to the nearest 100 km interval.
// A secondary sort can be applied within the 100 km range, e.g. by field LastName.

List<Employee> employeesSortedByRoundedDistance = await asyncSession
    .Query<Employee>()
     // Call 'OrderByDistance'
    .OrderByDistance(
        factory => factory.Point(
                // Pass the path to the document fields containing the spatial data
                x => x.Address.Location.Latitude,
                x => x.Address.Location.Longitude)
             // Round up distance to 100 km 
            .RoundTo(100),
        // Sort the results by their distance from this point: 
        47.623473, -122.3060097)
     // A secondary sort can be applied
    .ThenBy(x => x.LastName)
    .ToListAsync();
// Return all employee entities.
// Results are sorted by their distance to a specified point rounded to the nearest 100 km interval.
// A secondary sort can be applied within the 100 km range, e.g. by field LastName.

List<Employee> employeesSortedByRoundedDistance = session.Advanced
    .DocumentQuery<Employee>()
     // Call 'OrderByDistance'
    .OrderByDistance(
        factory => factory.Point(
                // Pass the path to the document fields containing the spatial data
                x => x.Address.Location.Latitude,
                x => x.Address.Location.Longitude)
             // Round up distance to 100 km 
            .RoundTo(100),
        // Sort the results by their distance from this point: 
        47.623473, -122.3060097)
     // A secondary sort can be applied
    .OrderBy(x => x.LastName)
    .ToList();
// Return all employee entities.
// Results are sorted by their distance to a specified point rounded to the nearest 100 km interval.
// A secondary sort can be applied within the 100 km range, e.g. by field LastName.

from Employees
order by spatial.distance(
    spatial.point(Address.Location.Latitude, Address.Location.Longitude),
    spatial.point(47.623473, -122.3060097),
    100
), LastName

Get resulting distance:

  • The distance is available in the @spatial metadata property within each result.

// Get the distance of the results:
// ================================

// Call 'GetMetadataFor', pass an entity from the resulting employees list
var metadata = session.Advanced.GetMetadataFor(employeesSortedByDistance[0]);

// The distance is available in the '@spatial' metadata property
var spatialResults = (IDictionary<string, object>)metadata[Constants.Documents.Metadata.SpatialResult];

var distance = spatialResults["Distance"];   // The distance of the entity from the queried location
var latitude = spatialResults["Latitude"];   // The entity's longitude value
var longitude = spatialResults["Longitude"]; // The entity's longitude value

Spatial API


Spatial

IRavenQueryable<T> Spatial<T>(
    Expression<Func<T, object>> path,
    Func<SpatialCriteriaFactory, SpatialCriteria> clause);

IRavenQueryable<T> Spatial<T>(
    string fieldName,
    Func<SpatialCriteriaFactory, SpatialCriteria> clause);

IRavenQueryable<T> Spatial<T>(
    Func<DynamicSpatialFieldFactory<T>, DynamicSpatialField> field,
    Func<SpatialCriteriaFactory, SpatialCriteria> clause);

IRavenQueryable<T> Spatial<T>(
    DynamicSpatialField field,
    Func<SpatialCriteriaFactory, SpatialCriteria> clause);
Parameters Type Description
path Expression<Func<T, object>> Path to spatial field in an index
(when querying an index)
fieldName string Path to spatial field in an index
(when querying an index)
field Func<DynamicSpatialFieldFactory<T>, DynamicSpatialField>
or
DynamicSpatialField
Factory or field that points to a document field
(when making a dynamic query).
Either PointField or WktField.
clause Func<SpatialCriteriaFactory, SpatialCriteria> Spatial criteria that will be executed on a given spatial field

DynamicSpatialFieldFactory

PointField Point(
    Expression<Func<T, object>> latitudePath,
    Expression<Func<T, object>> longitudePath);

WktField Wkt(Expression<Func<T, object>> wktPath);
Parameters Type Description
latitudePath / longitudePath / wktPath Expression<Func<T, object>> Path to the field in a document containing either longitude, latitude or WKT

SpatialCriteriaFactory

SpatialCriteria RelatesToShape(
    string shapeWkt,
    SpatialRelation relation,
    double distErrorPercent = Constants.Documents.Indexing.Spatial.DefaultDistanceErrorPct);

SpatialCriteria RelatesToShape(
    string shapeWkt,
    SpatialRelation relation,
    SpatialUnits units,
    double distErrorPercent = Constants.Documents.Indexing.Spatial.DefaultDistanceErrorPct);

SpatialCriteria Intersects(
    string shapeWkt,
    double distErrorPercent = Constants.Documents.Indexing.Spatial.DefaultDistanceErrorPct);

SpatialCriteria Intersects(
    string shapeWkt,
    SpatialUnits units,
    double distErrorPercent = Constants.Documents.Indexing.Spatial.DefaultDistanceErrorPct);

SpatialCriteria Contains(
    string shapeWkt,
    double distErrorPercent = Constants.Documents.Indexing.Spatial.DefaultDistanceErrorPct);

SpatialCriteria Contains(
    string shapeWkt,
    SpatialUnits units,
    double distErrorPercent = Constants.Documents.Indexing.Spatial.DefaultDistanceErrorPct);

SpatialCriteria Disjoint(
    string shapeWkt,
    double distErrorPercent = Constants.Documents.Indexing.Spatial.DefaultDistanceErrorPct);

SpatialCriteria Disjoint(
    string shapeWkt,
    SpatialUnits units,
    double distErrorPercent = Constants.Documents.Indexing.Spatial.DefaultDistanceErrorPct);

SpatialCriteria Within(
    string shapeWkt,
    double distErrorPercent = Constants.Documents.Indexing.Spatial.DefaultDistanceErrorPct);

SpatialCriteria Within(
    string shapeWkt,
    SpatialUnits units,
    double distErrorPercent = Constants.Documents.Indexing.Spatial.DefaultDistanceErrorPct);

SpatialCriteria WithinRadius(
    double radius,
    double latitude,
    double longitude,
    SpatialUnits? radiusUnits = null,
    double distErrorPercent = Constants.Documents.Indexing.Spatial.DefaultDistanceErrorPct);
Parameter Type Description
shapeWkt string WKT-based shape used in query criteria
relation SpatialRelation Relation of the shape to the spatial data in the document/index.
Can be Within, Contains, Disjoint, Intersects.
distErrorPercent double Maximum distance error tolerance in percents. Default: 0.025
radius / latitude / longitude double Used to define a radius of a circle
radiusUnits / units SpatialUnits Determines if circle or shape should be calculated in Kilometers or Miles.
By default, distances are measured in kilometers.

OrderByDistance

// From point
IOrderedQueryable<T> OrderByDistance<T>(
    Func<DynamicSpatialFieldFactory<T>, DynamicSpatialField> field,
    double latitude,
    double longitude);

IOrderedQueryable<T> OrderByDistance<T>(
    DynamicSpatialField field,
    double latitude,
    double longitude);

IOrderedQueryable<T> OrderByDistance<T>(
    Expression<Func<T, object>> path,
    double latitude,
    double longitude);

IOrderedQueryable<T> OrderByDistance<T>(
    string fieldName,
    double latitude,
    double longitude);

// From center of WKT shape
IOrderedQueryable<T> OrderByDistance<T>(
    Func<DynamicSpatialFieldFactory<T>, DynamicSpatialField> field,
    string shapeWkt);

IOrderedQueryable<T> OrderByDistance<T>(
    DynamicSpatialField field,
    string shapeWkt);

IOrderedQueryable<T> OrderByDistance<T>(
    Expression<Func<T, object>> path,
    string shapeWkt);

IOrderedQueryable<T> OrderByDistance<T>(
    string fieldName,
    string shapeWkt);

// Rounding
IOrderedQueryable<T> OrderByDistance<T>(
    Expression<Func<T, object>> path,
    double latitude,
    double longitude,
    double roundFactor);

IOrderedQueryable<T> OrderByDistance<T>(
    string fieldName,
    double latitude,
    double longitude,
    double roundFactor);

IOrderedQueryable<T> OrderByDistance<T>(
    Expression<Func<T, object>> path,
    string shapeWkt,
    double roundFactor);

IOrderedQueryable<T> OrderByDistance<T>(
    string fieldName,
    string shapeWkt,
    double roundFactor);

OrderByDistanceDescending

// From point
IOrderedQueryable<T> OrderByDistanceDescending<T>(
    Func<DynamicSpatialFieldFactory<T>, DynamicSpatialField> field,
    double latitude,
    double longitude);

IOrderedQueryable<T> OrderByDistanceDescending<T>(
    DynamicSpatialField field,
    double latitude,
    double longitude);

IOrderedQueryable<T> OrderByDistanceDescending<T>(
    Expression<Func<T, object>> path,
    double latitude,
    double longitude);

IOrderedQueryable<T> OrderByDistanceDescending<T>(
    string fieldName,
    double latitude,
    double longitude);

// From center of WKT shape
IOrderedQueryable<T> OrderByDistanceDescending<T>(
    Func<DynamicSpatialFieldFactory<T>, DynamicSpatialField> field,
    string shapeWkt);

IOrderedQueryable<T> OrderByDistanceDescending<T>(
    DynamicSpatialField field,
    string shapeWkt);

IOrderedQueryable<T> OrderByDistanceDescending<T>(
    Expression<Func<T, object>> path,
    string shapeWkt);

IOrderedQueryable<T> OrderByDistanceDescending<T>(
    string fieldName,
    string shapeWkt);

// Rounding
IOrderedQueryable<T> OrderByDistanceDescending<T>(
    Expression<Func<T, object>> path,
    double latitude,
    double longitude,
    double roundFactor);

IOrderedQueryable<T> OrderByDistanceDescending<T>(
    string fieldName,
    double latitude,
    double longitude,
    double roundFactor);

IOrderedQueryable<T> OrderByDistanceDescending<T>(
    Expression<Func<T, object>> path,
    string shapeWkt,
    double roundFactor);

IOrderedQueryable<T> OrderByDistanceDescending<T>(
    string fieldName,
    string shapeWkt,
    double roundFactor);
Parameter Type Description
path Expression<Func<T, object>> Path to spatial field in index
(when querying an index)
fieldName string Path to spatial field in index
(when querying an index)
field Func<DynamicSpatialFieldFactory<T>, DynamicSpatialField>
or
DynamicSpatialField
Factory or field that points to a document field
(when making a dynamic query).
Either PointField or WktField.
shapeWkt string WKT-based shape to be used as a point from which distance will be measured. If the shape is not a single point, then the center of the shape will be used as a reference.
latitude / longitude double Used to define a point from which distance will be measured
roundFactor double A distance interval in kilometers.
The distance from the point is rounded up to the nearest interval.
The results within the same interval can be sorted by a secondary order.
If no other order was specified, then by ascending order of document Id.