Calculating the nearest location

Find the nearest location to another location, and then calculate the distance between these two locations.

Use the following operators to detect the nearest geometry, or a maximum number of nearest geometries:
  • the nearest polygon among <polygons> to <a geometry>
  • the <a number> nearest polygons among <polygons> to <a geometry>

    Similar operators are available for points, line strings, and generic geometries.

Use the following operator to calculate the distance between two geometries:

In the following example, a parking area is defined as a polygon in the business model. The rule finds the nearest parking lot to the location of the car, and then calculates the distance in kilometers.

when a car issue event occurs
definitions
    set 'parking lots' to the parking lots of 'the organization';
    set 'nearest parking lot' to the nearest polygon among the parking areas of 'parking lots' to the location of this car issue event;
then
    print "the nearest parking lot is within " + the distance between 'nearest parking lot' and the location of this car issue event in kilometers + "kilometers";