Skip to main content

Distance

Use the Distance gem to calculate the distance between two geographic points.

Parameters

Spatial Object Fields

Use these parameters to specify the columns containing the source and destination geographic points for distance calculation.

ParameterDescription
Source TypeFormat of the source column.
Source ColumnColumn that contains the source geo points.
Destination TypeFormat of the destination column.
Destination ColumnColumn that contains the destination geo points.

Select Output Options

Use the checkboxes defined below to choose which output columns the Distance gem should generate.

CheckboxDescription
Output DistanceReturn a column that includes the distance between points in a specified unit of distance
Output Cardinal DirectionReturn a column that includes the cardinal direction from the source point to the destination point
Output Direction in DegreesReturn a column that includes the direction in degrees from the source point to the destination point
note

You can select zero, one, or multiple checkboxes. All checkboxes are disabled by default.

Example

Assume you have the following airline route table, and you would like to calculate the distance between start and destination cities.

start_citydestination_citysource_pointdest_point
New YorkLos AngelesPOINT (-74.0060 40.7128)POINT (-118.2437 34.0522)
LondonParisPOINT (-0.1278 51.5074)POINT (2.3522 48.8566)
TokyoSydneyPOINT (139.6917 35.6895)POINT (151.2093 -33.8688)
TorontoChicagoPOINT (-79.3470 43.6511)POINT (-87.6298 41.8781)
DubaiMumbaiPOINT (55.2962 25.2760)POINT (72.8777 19.0760)

To find the distance and direction between cities, set the following gem configurations.

  1. Set source and destination:

    1. Set Source Type to Point.

    2. Set Source Column to start_city.

    3. Set Destination Type to Point.

    4. Set Destination Column to destination_city.

  2. Set output options:

    1. Select the Output Distance checkbox.

    2. From the Units dropdown, select Kilometers.

    3. Select the Output Cardinal Direction checkbox.

    4. Select the Output Direction in Degrees checkbox.

    5. Run the gem.

Result

The resulting table will have three new columns: distance_kilometers, cardinal_direction, and direction_degrees.

start_citydestination_citysource_pointdest_pointdistance_kilometerscardinal_directiondirection_degrees
New YorkLos AngelesPOINT (-74.0060 40.7128)POINT (-118.2437 34.0522)3944.42W273.7
LondonParisPOINT (-0.1278 51.5074)POINT (2.3522 48.8566)343.92SE148.1
TokyoSydneyPOINT (139.6917 35.6895)POINT (151.2093 -33.8688)7792.96S169.9
TorontoChicagoPOINT (-79.3470 43.6511)POINT (-87.6298 41.8781)705.64W256.6
DubaiMumbaiPOINT (55.2962 25.2760)POINT (72.8777 19.0760)1936.68E107.3