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.
Parameter | Description |
---|---|
Source Type | Format of the source column. |
Source Column | Column that contains the source geo points. |
Destination Type | Format of the destination column. |
Destination Column | Column that contains the destination geo points. |
Select Output Options
Use the checkboxes defined below to choose which output columns the Distance gem should generate.
Checkbox | Description |
---|---|
Output Distance | Return a column that includes the distance between points in a specified unit of distance |
Output Cardinal Direction | Return a column that includes the cardinal direction from the source point to the destination point |
Output Direction in Degrees | Return a column that includes the direction in degrees from the source point to the destination point |
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_city | destination_city | source_point | dest_point |
---|---|---|---|
New York | Los Angeles | POINT (-74.0060 40.7128) | POINT (-118.2437 34.0522) |
London | Paris | POINT (-0.1278 51.5074) | POINT (2.3522 48.8566) |
Tokyo | Sydney | POINT (139.6917 35.6895) | POINT (151.2093 -33.8688) |
Toronto | Chicago | POINT (-79.3470 43.6511) | POINT (-87.6298 41.8781) |
Dubai | Mumbai | POINT (55.2962 25.2760) | POINT (72.8777 19.0760) |
To find the distance and direction between cities, set the following gem configurations.
-
Set source and destination:
-
Set Source Type to Point.
-
Set Source Column to
start_city
. -
Set Destination Type to Point.
-
Set Destination Column to
destination_city
.
-
-
Set output options:
-
Select the Output Distance checkbox.
-
From the Units dropdown, select Kilometers.
-
Select the Output Cardinal Direction checkbox.
-
Select the Output Direction in Degrees checkbox.
-
Run the gem.
-
Result
The resulting table will have three new columns: distance_kilometers
, cardinal_direction
, and direction_degrees
.
start_city | destination_city | source_point | dest_point | distance_kilometers | cardinal_direction | direction_degrees |
---|---|---|---|---|---|---|
New York | Los Angeles | POINT (-74.0060 40.7128) | POINT (-118.2437 34.0522) | 3944.42 | W | 273.7 |
London | Paris | POINT (-0.1278 51.5074) | POINT (2.3522 48.8566) | 343.92 | SE | 148.1 |
Tokyo | Sydney | POINT (139.6917 35.6895) | POINT (151.2093 -33.8688) | 7792.96 | S | 169.9 |
Toronto | Chicago | POINT (-79.3470 43.6511) | POINT (-87.6298 41.8781) | 705.64 | W | 256.6 |
Dubai | Mumbai | POINT (55.2962 25.2760) | POINT (72.8777 19.0760) | 1936.68 | E | 107.3 |