turf-ruby 0.8.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +21 -0
- data/README.md +163 -140
- data/lib/turf/along.rb +10 -3
- data/lib/turf/angle.rb +8 -0
- data/lib/turf/area.rb +4 -1
- data/lib/turf/bbox.rb +36 -0
- data/lib/turf/bbox_clip.rb +74 -0
- data/lib/turf/bbox_polygon.rb +41 -0
- data/lib/turf/bearing.rb +5 -2
- data/lib/turf/bezier_spline.rb +8 -0
- data/lib/turf/boolean_clockwise.rb +26 -0
- data/lib/turf/boolean_concave.rb +40 -0
- data/lib/turf/boolean_contains.rb +52 -0
- data/lib/turf/boolean_crosses.rb +8 -0
- data/lib/turf/boolean_disjoint.rb +8 -0
- data/lib/turf/boolean_equal.rb +8 -0
- data/lib/turf/boolean_intersects.rb +8 -0
- data/lib/turf/boolean_overlap.rb +8 -0
- data/lib/turf/boolean_parallel.rb +8 -0
- data/lib/turf/boolean_point_in_polygon.rb +5 -3
- data/lib/turf/boolean_point_on_line.rb +128 -0
- data/lib/turf/boolean_touches.rb +8 -0
- data/lib/turf/boolean_valid.rb +8 -0
- data/lib/turf/boolean_within.rb +8 -0
- data/lib/turf/buffer.rb +8 -0
- data/lib/turf/center.rb +32 -0
- data/lib/turf/center_mean.rb +8 -0
- data/lib/turf/center_median.rb +8 -0
- data/lib/turf/center_of_mass.rb +8 -0
- data/lib/turf/centroid.rb +5 -2
- data/lib/turf/circle.rb +5 -2
- data/lib/turf/clean_coords.rb +8 -0
- data/lib/turf/clone.rb +8 -0
- data/lib/turf/clusters.rb +32 -0
- data/lib/turf/clusters_dbscan.rb +8 -0
- data/lib/turf/clusters_kmeans.rb +8 -0
- data/lib/turf/collect.rb +8 -0
- data/lib/turf/combine.rb +8 -0
- data/lib/turf/concave.rb +8 -0
- data/lib/turf/convex.rb +8 -0
- data/lib/turf/destination.rb +6 -3
- data/lib/turf/difference.rb +8 -0
- data/lib/turf/directional_mean.rb +8 -0
- data/lib/turf/dissolve.rb +8 -0
- data/lib/turf/distance.rb +5 -2
- data/lib/turf/distance_weight.rb +12 -0
- data/lib/turf/ellipse.rb +8 -0
- data/lib/turf/envelope.rb +8 -0
- data/lib/turf/explode.rb +29 -0
- data/lib/turf/flatten.rb +8 -0
- data/lib/turf/flip.rb +8 -0
- data/lib/turf/geojson_rbush.rb +8 -0
- data/lib/turf/great_circle.rb +8 -0
- data/lib/turf/helpers.rb +166 -26
- data/lib/turf/hex_grid.rb +8 -0
- data/lib/turf/interpolate.rb +8 -0
- data/lib/turf/intersect.rb +8 -0
- data/lib/turf/invariant.rb +127 -1
- data/lib/turf/isobands.rb +8 -0
- data/lib/turf/isolines.rb +8 -0
- data/lib/turf/kinks.rb +8 -0
- data/lib/turf/length.rb +6 -3
- data/lib/turf/lib/lineclip.rb +118 -0
- data/lib/turf/line_arc.rb +8 -0
- data/lib/turf/line_chunk.rb +8 -0
- data/lib/turf/line_intersect.rb +8 -0
- data/lib/turf/line_offset.rb +8 -0
- data/lib/turf/line_overlap.rb +8 -0
- data/lib/turf/line_segment.rb +8 -0
- data/lib/turf/line_slice.rb +8 -0
- data/lib/turf/line_slice_along.rb +8 -0
- data/lib/turf/line_split.rb +8 -0
- data/lib/turf/line_to_polygon.rb +8 -0
- data/lib/turf/mask.rb +8 -0
- data/lib/turf/meta.rb +445 -79
- data/lib/turf/midpoint.rb +8 -0
- data/lib/turf/moran_index.rb +8 -0
- data/lib/turf/nearest_neighbor_analysis.rb +8 -0
- data/lib/turf/nearest_point.rb +8 -0
- data/lib/turf/nearest_point_on_line.rb +8 -0
- data/lib/turf/nearest_point_to_line.rb +8 -0
- data/lib/turf/planepoint.rb +8 -0
- data/lib/turf/point_grid.rb +8 -0
- data/lib/turf/point_on_feature.rb +8 -0
- data/lib/turf/point_to_line_distance.rb +8 -0
- data/lib/turf/point_to_polygon_distance.rb +8 -0
- data/lib/turf/points_within_polygon.rb +8 -0
- data/lib/turf/polygon_smooth.rb +8 -0
- data/lib/turf/polygon_tangents.rb +8 -0
- data/lib/turf/polygon_to_line.rb +20 -0
- data/lib/turf/polygonize.rb +8 -0
- data/lib/turf/projection.rb +12 -0
- data/lib/turf/quadrat_analysis.rb +8 -0
- data/lib/turf/random.rb +20 -0
- data/lib/turf/rectangle_grid.rb +8 -0
- data/lib/turf/rewind.rb +8 -0
- data/lib/turf/rhumb_bearing.rb +8 -0
- data/lib/turf/rhumb_destination.rb +8 -0
- data/lib/turf/rhumb_distance.rb +8 -0
- data/lib/turf/sample.rb +8 -0
- data/lib/turf/sector.rb +8 -0
- data/lib/turf/shortest_path.rb +8 -0
- data/lib/turf/simplify.rb +8 -0
- data/lib/turf/square.rb +42 -0
- data/lib/turf/square_grid.rb +8 -0
- data/lib/turf/standard_deviational_ellipse.rb +8 -0
- data/lib/turf/tag.rb +8 -0
- data/lib/turf/tesselate.rb +8 -0
- data/lib/turf/tin.rb +8 -0
- data/lib/turf/transform_rotate.rb +8 -0
- data/lib/turf/transform_scale.rb +8 -0
- data/lib/turf/transform_translate.rb +8 -0
- data/lib/turf/triangle_grid.rb +8 -0
- data/lib/turf/truncate.rb +3 -0
- data/lib/turf/union.rb +8 -0
- data/lib/turf/unkink_polygon.rb +8 -0
- data/lib/turf/version.rb +2 -1
- data/lib/turf/voronoi.rb +8 -0
- data/lib/turf.rb +2 -0
- data/lib/turf_ruby.rb +107 -3
- metadata +106 -3
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# :nodoc:
|
4
|
+
module Turf
|
5
|
+
# frozen_string_literal: true
|
6
|
+
|
7
|
+
# Takes a polygon and returns true or false as to whether it is concave or not.
|
8
|
+
#
|
9
|
+
# @function
|
10
|
+
# @param [Feature<Polygon>, Polygon] polygon to be evaluated
|
11
|
+
# @return [Boolean] true/false
|
12
|
+
# @example
|
13
|
+
# convex_polygon = polygon([[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]])
|
14
|
+
#
|
15
|
+
# boolean_concave(convex_polygon)
|
16
|
+
# # => false
|
17
|
+
def boolean_concave(polygon)
|
18
|
+
coords = get_geom(polygon)[:coordinates]
|
19
|
+
return false if coords[0].length <= 4
|
20
|
+
|
21
|
+
sign = nil
|
22
|
+
n = coords[0].length - 1
|
23
|
+
|
24
|
+
(0...n).each do |i|
|
25
|
+
dx1 = coords[0][(i + 2) % n][0] - coords[0][(i + 1) % n][0]
|
26
|
+
dy1 = coords[0][(i + 2) % n][1] - coords[0][(i + 1) % n][1]
|
27
|
+
dx2 = coords[0][i][0] - coords[0][(i + 1) % n][0]
|
28
|
+
dy2 = coords[0][i][1] - coords[0][(i + 1) % n][1]
|
29
|
+
zcrossproduct = (dx1 * dy2) - (dy1 * dx2)
|
30
|
+
|
31
|
+
if i.zero?
|
32
|
+
sign = zcrossproduct.positive?
|
33
|
+
elsif sign != zcrossproduct.positive?
|
34
|
+
return true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
false
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# :nodoc:
|
4
|
+
module Turf
|
5
|
+
def boolean_contains(*args)
|
6
|
+
raise NotImplementedError
|
7
|
+
end
|
8
|
+
|
9
|
+
def is_polygon_in_multi_polygon(*args)
|
10
|
+
raise NotImplementedError
|
11
|
+
end
|
12
|
+
|
13
|
+
def is_point_in_multi_point(*args)
|
14
|
+
raise NotImplementedError
|
15
|
+
end
|
16
|
+
|
17
|
+
def is_multi_point_in_multi_point(*args)
|
18
|
+
raise NotImplementedError
|
19
|
+
end
|
20
|
+
|
21
|
+
def is_multi_point_on_line(*args)
|
22
|
+
raise NotImplementedError
|
23
|
+
end
|
24
|
+
|
25
|
+
def is_multi_point_in_poly(*args)
|
26
|
+
raise NotImplementedError
|
27
|
+
end
|
28
|
+
|
29
|
+
def is_line_on_line(*args)
|
30
|
+
raise NotImplementedError
|
31
|
+
end
|
32
|
+
|
33
|
+
def is_line_in_poly(*args)
|
34
|
+
raise NotImplementedError
|
35
|
+
end
|
36
|
+
|
37
|
+
def is_poly_in_poly(*args)
|
38
|
+
raise NotImplementedError
|
39
|
+
end
|
40
|
+
|
41
|
+
def do_b_box_overlap(*args)
|
42
|
+
raise NotImplementedError
|
43
|
+
end
|
44
|
+
|
45
|
+
def compare_coords(*args)
|
46
|
+
raise NotImplementedError
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_midpoint(*args)
|
50
|
+
raise NotImplementedError
|
51
|
+
end
|
52
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "invariant"
|
4
|
+
|
3
5
|
# :nodoc:
|
4
6
|
module Turf
|
5
7
|
# @!group Booleans
|
@@ -13,7 +15,7 @@ module Turf
|
|
13
15
|
# inside
|
14
16
|
# the polygon otherwise false.
|
15
17
|
# @return [boolean] true if the Point is inside the Polygon; false if the Point is not inside the Polygon
|
16
|
-
def boolean_point_in_polygon(point, polygon,
|
18
|
+
def boolean_point_in_polygon(point, polygon, options = {})
|
17
19
|
polygon = deep_symbolize_keys(polygon)
|
18
20
|
pt = get_coord(point)
|
19
21
|
geom = get_geom(polygon)
|
@@ -30,13 +32,13 @@ module Turf
|
|
30
32
|
inside_poly = false
|
31
33
|
polys.each do |poly|
|
32
34
|
# check if it is in the outer ring first
|
33
|
-
next unless in_ring(pt, poly[0], ignore_boundary)
|
35
|
+
next unless in_ring(pt, poly[0], options[:ignore_boundary])
|
34
36
|
|
35
37
|
in_hole = false
|
36
38
|
|
37
39
|
# check for the point in any of the holes
|
38
40
|
poly.slice(1, poly.size - 1).each do |hole|
|
39
|
-
if in_ring(pt, hole, !ignore_boundary)
|
41
|
+
if in_ring(pt, hole, !options[:ignore_boundary])
|
40
42
|
in_hole = true
|
41
43
|
end
|
42
44
|
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# :nodoc:
|
4
|
+
module Turf
|
5
|
+
# Returns true if a point is on a line. Accepts an optional parameter to ignore the
|
6
|
+
# start and end vertices of the linestring.
|
7
|
+
#
|
8
|
+
# @param [Hash] pt GeoJSON Point
|
9
|
+
# @param [Hash] line GeoJSON LineString
|
10
|
+
# @param [Hash] options Optional parameters
|
11
|
+
# @option options [Boolean] :ignore_end_vertices whether to ignore the start and end vertices.
|
12
|
+
# @option options [Float] :epsilon Fractional number to compare with the cross product result.
|
13
|
+
# Useful for dealing with floating points such as lng/lat points
|
14
|
+
# @return [Boolean] true/false
|
15
|
+
# @example
|
16
|
+
# pt = turf_point([0, 0])
|
17
|
+
# line = turf_line_string([[-1, -1], [1, 1], [1.5, 2.2]])
|
18
|
+
# is_point_on_line = boolean_point_on_line(pt, line)
|
19
|
+
# # => true
|
20
|
+
def boolean_point_on_line(point, line, options = nil)
|
21
|
+
options ||= {}
|
22
|
+
# Normalize inputs
|
23
|
+
pt_coords = get_coord(point)
|
24
|
+
line_coords = get_coords(line)
|
25
|
+
|
26
|
+
# Main
|
27
|
+
line_coords.each_cons(2) do |line_segment_start, line_segment_end|
|
28
|
+
ignore_boundary = false
|
29
|
+
if options[:ignore_end_vertices]
|
30
|
+
first_segment = (line_coords.first == line_segment_start)
|
31
|
+
last_segment = (line_coords.last == line_segment_end)
|
32
|
+
|
33
|
+
if first_segment && last_segment
|
34
|
+
ignore_boundary = :both
|
35
|
+
elsif first_segment
|
36
|
+
ignore_boundary = :start
|
37
|
+
elsif last_segment
|
38
|
+
ignore_boundary = :end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
return true if is_point_on_line_segment(
|
43
|
+
line_segment_start,
|
44
|
+
line_segment_end,
|
45
|
+
pt_coords,
|
46
|
+
ignore_boundary,
|
47
|
+
options[:epsilon],
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
false
|
52
|
+
end
|
53
|
+
|
54
|
+
# Determines if a point is on a line segment.
|
55
|
+
#
|
56
|
+
# @param [Array<Float>] line_segment_start Coordinate pair of the start of the line segment [x1, y1].
|
57
|
+
# @param [Array<Float>] line_segment_end Coordinate pair of the end of the line segment [x2, y2].
|
58
|
+
# @param [Array<Float>] pt Coordinate pair of the point to check [px, py].
|
59
|
+
# @param [Boolean, String] exclude_boundary Whether the point is allowed to fall on the line ends.
|
60
|
+
# Can be true, false, or one of "start", "end", or "both".
|
61
|
+
# @param [Float, NilClass] epsilon Fractional tolerance for cross-product
|
62
|
+
# comparison (useful for floating-point coordinates).
|
63
|
+
# @return [Boolean] true if the point is on the line segment, false otherwise.
|
64
|
+
def is_point_on_line_segment(line_segment_start, line_segment_end, point, exclude_boundary, epsilon = nil)
|
65
|
+
x, y = point
|
66
|
+
x1, y1 = line_segment_start
|
67
|
+
x2, y2 = line_segment_end
|
68
|
+
|
69
|
+
dxc = x - x1
|
70
|
+
dyc = y - y1
|
71
|
+
dxl = x2 - x1
|
72
|
+
dyl = y2 - y1
|
73
|
+
cross = (dxc * dyl) - (dyc * dxl)
|
74
|
+
|
75
|
+
if epsilon
|
76
|
+
return false if cross.abs > epsilon
|
77
|
+
elsif cross != 0
|
78
|
+
return false
|
79
|
+
end
|
80
|
+
|
81
|
+
# Special case: zero-length line segments
|
82
|
+
if dxl == 0 && dyl == 0
|
83
|
+
return false if exclude_boundary
|
84
|
+
|
85
|
+
return point == line_segment_start
|
86
|
+
end
|
87
|
+
|
88
|
+
case exclude_boundary
|
89
|
+
when false
|
90
|
+
if dxl.abs >= dyl.abs
|
91
|
+
if dxl > 0
|
92
|
+
x.between?(x1,
|
93
|
+
x2)
|
94
|
+
else
|
95
|
+
x.between?(x2,
|
96
|
+
x1)
|
97
|
+
end
|
98
|
+
else
|
99
|
+
(if dyl > 0
|
100
|
+
y.between?(y1,
|
101
|
+
y2)
|
102
|
+
else
|
103
|
+
y.between?(y2, y1)
|
104
|
+
end)
|
105
|
+
end
|
106
|
+
when :start
|
107
|
+
if dxl.abs >= dyl.abs
|
108
|
+
dxl > 0 ? x1 < x && x <= x2 : x2 <= x && x < x1
|
109
|
+
else
|
110
|
+
(dyl > 0 ? y1 < y && y <= y2 : y2 < y && y < y1)
|
111
|
+
end
|
112
|
+
when :end
|
113
|
+
if dxl.abs >= dyl.abs
|
114
|
+
dxl > 0 ? x1 <= x && x < x2 : x2 < x && x <= x1
|
115
|
+
else
|
116
|
+
(dyl > 0 ? y1 <= y && y < y2 : y2 < y && y <= y1)
|
117
|
+
end
|
118
|
+
when :both
|
119
|
+
if dxl.abs >= dyl.abs
|
120
|
+
dxl > 0 ? x1 < x && x < x2 : x2 < x && x < x1
|
121
|
+
else
|
122
|
+
(dyl > 0 ? y1 < y && y < y2 : y2 < y && y < y1)
|
123
|
+
end
|
124
|
+
else
|
125
|
+
false
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
data/lib/turf/buffer.rb
ADDED
data/lib/turf/center.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# :nodoc:
|
4
|
+
module Turf
|
5
|
+
# frozen_string_literal: true
|
6
|
+
|
7
|
+
# Takes a Feature or FeatureCollection and returns the absolute center point of all features.
|
8
|
+
#
|
9
|
+
# @param [GeoJSON] geojson GeoJSON to be centered
|
10
|
+
# @param [Hash] options Optional parameters
|
11
|
+
# @option options [Hash] :properties Translate GeoJSON Properties to Point
|
12
|
+
# @option options [Array] :bbox Translate GeoJSON BBox to Point
|
13
|
+
# @option options [String, Integer] :id Translate GeoJSON Id to Point
|
14
|
+
# @return [Feature<Point>] a Point feature at the absolute center point of all input features
|
15
|
+
# @example
|
16
|
+
# features = points([
|
17
|
+
# [-97.522259, 35.4691],
|
18
|
+
# [-97.502754, 35.463455],
|
19
|
+
# [-97.508269, 35.463245]
|
20
|
+
# ])
|
21
|
+
# center = center(features)
|
22
|
+
# # Add to map
|
23
|
+
# add_to_map = [features, center]
|
24
|
+
# center[:properties]['marker-size'] = 'large'
|
25
|
+
# center[:properties]['marker-color'] = '#000'
|
26
|
+
def center(geojson, options = {})
|
27
|
+
ext = bbox(geojson)
|
28
|
+
x = (ext[0] + ext[2]) / 2.0
|
29
|
+
y = (ext[1] + ext[3]) / 2.0
|
30
|
+
point([x, y], options[:properties] || {}, options)
|
31
|
+
end
|
32
|
+
end
|
data/lib/turf/centroid.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "helpers"
|
4
|
+
require_relative "meta"
|
5
|
+
|
3
6
|
# :nodoc:
|
4
7
|
module Turf
|
5
8
|
# @!group Measurement
|
@@ -10,7 +13,7 @@ module Turf
|
|
10
13
|
# @param geojson [GeoJSON] GeoJSON to be centered
|
11
14
|
# @param properties [Hash] a [Hash] that is used as the Feature's properties
|
12
15
|
# @return [Feature<Point>] the centroid of the input features
|
13
|
-
def centroid(geojson, properties
|
16
|
+
def centroid(geojson, properties = nil)
|
14
17
|
x_sum = 0.0
|
15
18
|
y_sum = 0.0
|
16
19
|
len = 0.0
|
@@ -23,7 +26,7 @@ module Turf
|
|
23
26
|
|
24
27
|
point(
|
25
28
|
[x_sum / len, y_sum / len],
|
26
|
-
properties
|
29
|
+
properties,
|
27
30
|
)
|
28
31
|
end
|
29
32
|
end
|
data/lib/turf/circle.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "destination"
|
4
|
+
require_relative "helpers"
|
5
|
+
|
3
6
|
# :nodoc:
|
4
7
|
module Turf
|
5
8
|
# Takes a Point and calculates the circle polygon given a radius in degrees, radians, miles, or kilometers;
|
@@ -22,10 +25,10 @@ module Turf
|
|
22
25
|
# main
|
23
26
|
coordinates = []
|
24
27
|
steps.times do |i|
|
25
|
-
coordinates.push(destination(center, radius, (i * -360.0) / steps,
|
28
|
+
coordinates.push(destination(center, radius, (i * -360.0) / steps, options).dig(:geometry, :coordinates))
|
26
29
|
end
|
27
30
|
coordinates.push(coordinates[0])
|
28
31
|
|
29
|
-
polygon([coordinates], properties
|
32
|
+
polygon([coordinates], properties)
|
30
33
|
end
|
31
34
|
end
|
data/lib/turf/clone.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# :nodoc:
|
4
|
+
module Turf
|
5
|
+
def get_cluster(*args)
|
6
|
+
raise NotImplementedError
|
7
|
+
end
|
8
|
+
|
9
|
+
def cluster_each(*args)
|
10
|
+
raise NotImplementedError
|
11
|
+
end
|
12
|
+
|
13
|
+
def cluster_reduce(*args)
|
14
|
+
raise NotImplementedError
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_bins(*args)
|
18
|
+
raise NotImplementedError
|
19
|
+
end
|
20
|
+
|
21
|
+
def apply_filter(*args)
|
22
|
+
raise NotImplementedError
|
23
|
+
end
|
24
|
+
|
25
|
+
def properties_contains_filter(*args)
|
26
|
+
raise NotImplementedError
|
27
|
+
end
|
28
|
+
|
29
|
+
def filter_properties(*args)
|
30
|
+
raise NotImplementedError
|
31
|
+
end
|
32
|
+
end
|
data/lib/turf/collect.rb
ADDED
data/lib/turf/combine.rb
ADDED
data/lib/turf/concave.rb
ADDED
data/lib/turf/convex.rb
ADDED
data/lib/turf/destination.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "helpers"
|
4
|
+
require_relative "invariant"
|
5
|
+
|
3
6
|
# :nodoc:
|
4
7
|
module Turf
|
5
8
|
# @!group Measurement
|
@@ -10,8 +13,8 @@ module Turf
|
|
10
13
|
# @param origin [Coord] starting point
|
11
14
|
# @param distance [number] distance from the origin point
|
12
15
|
# @param bearing [number] ranging from -180 to 180
|
13
|
-
# @param units [string] miles, kilometers, degrees, or radians
|
14
|
-
# @param properties [Hash] Translate properties to Point
|
16
|
+
# @param options[:units] [string] miles, kilometers, degrees, or radians
|
17
|
+
# @param options[:properties] [Hash] Translate properties to Point
|
15
18
|
# @return [Feature<Point>] destination point
|
16
19
|
def destination(origin, distance, bearing, options = {})
|
17
20
|
coordinates1 = get_coord origin
|
@@ -29,6 +32,6 @@ module Turf
|
|
29
32
|
lng = radians_to_degrees(longitude2)
|
30
33
|
lat = radians_to_degrees(latitude2)
|
31
34
|
|
32
|
-
point([lng, lat],
|
35
|
+
point([lng, lat], options[:properties])
|
33
36
|
end
|
34
37
|
end
|
data/lib/turf/distance.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "helpers"
|
4
|
+
require_relative "invariant"
|
5
|
+
|
3
6
|
# :nodoc:
|
4
7
|
module Turf
|
5
8
|
# @!group Measurement
|
@@ -11,7 +14,7 @@ module Turf
|
|
11
14
|
# @param to [Coord] destination point
|
12
15
|
# @param units [string] can be degrees, radians, miles, or kilometers
|
13
16
|
# @return [number] distance between the two points
|
14
|
-
def distance(from, to,
|
17
|
+
def distance(from, to, options = {})
|
15
18
|
coordinates1 = get_coord from
|
16
19
|
coordinates2 = get_coord to
|
17
20
|
|
@@ -31,7 +34,7 @@ module Turf
|
|
31
34
|
Math.sqrt(a),
|
32
35
|
Math.sqrt(1 - a),
|
33
36
|
),
|
34
|
-
units,
|
37
|
+
options[:units],
|
35
38
|
)
|
36
39
|
end
|
37
40
|
end
|