turf-ruby 0.8.1 → 1.0.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.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +21 -0
  3. data/README.md +159 -139
  4. data/lib/turf/along.rb +10 -3
  5. data/lib/turf/angle.rb +8 -0
  6. data/lib/turf/area.rb +4 -1
  7. data/lib/turf/bbox.rb +36 -0
  8. data/lib/turf/bbox_clip.rb +74 -0
  9. data/lib/turf/bbox_polygon.rb +41 -0
  10. data/lib/turf/bearing.rb +5 -2
  11. data/lib/turf/bezier_spline.rb +8 -0
  12. data/lib/turf/boolean_clockwise.rb +8 -0
  13. data/lib/turf/boolean_concave.rb +8 -0
  14. data/lib/turf/boolean_contains.rb +52 -0
  15. data/lib/turf/boolean_crosses.rb +8 -0
  16. data/lib/turf/boolean_disjoint.rb +8 -0
  17. data/lib/turf/boolean_equal.rb +8 -0
  18. data/lib/turf/boolean_intersects.rb +8 -0
  19. data/lib/turf/boolean_overlap.rb +8 -0
  20. data/lib/turf/boolean_parallel.rb +8 -0
  21. data/lib/turf/boolean_point_in_polygon.rb +5 -3
  22. data/lib/turf/boolean_point_on_line.rb +8 -0
  23. data/lib/turf/boolean_touches.rb +8 -0
  24. data/lib/turf/boolean_valid.rb +8 -0
  25. data/lib/turf/boolean_within.rb +8 -0
  26. data/lib/turf/buffer.rb +8 -0
  27. data/lib/turf/center.rb +32 -0
  28. data/lib/turf/center_mean.rb +8 -0
  29. data/lib/turf/center_median.rb +8 -0
  30. data/lib/turf/center_of_mass.rb +8 -0
  31. data/lib/turf/centroid.rb +5 -2
  32. data/lib/turf/circle.rb +5 -2
  33. data/lib/turf/clean_coords.rb +8 -0
  34. data/lib/turf/clone.rb +8 -0
  35. data/lib/turf/clusters.rb +32 -0
  36. data/lib/turf/clusters_dbscan.rb +8 -0
  37. data/lib/turf/clusters_kmeans.rb +8 -0
  38. data/lib/turf/collect.rb +8 -0
  39. data/lib/turf/combine.rb +8 -0
  40. data/lib/turf/concave.rb +8 -0
  41. data/lib/turf/convex.rb +8 -0
  42. data/lib/turf/destination.rb +6 -3
  43. data/lib/turf/difference.rb +8 -0
  44. data/lib/turf/directional_mean.rb +8 -0
  45. data/lib/turf/dissolve.rb +8 -0
  46. data/lib/turf/distance.rb +5 -2
  47. data/lib/turf/distance_weight.rb +12 -0
  48. data/lib/turf/ellipse.rb +8 -0
  49. data/lib/turf/envelope.rb +8 -0
  50. data/lib/turf/explode.rb +29 -0
  51. data/lib/turf/flatten.rb +8 -0
  52. data/lib/turf/flip.rb +8 -0
  53. data/lib/turf/geojson_rbush.rb +8 -0
  54. data/lib/turf/great_circle.rb +8 -0
  55. data/lib/turf/helpers.rb +166 -26
  56. data/lib/turf/hex_grid.rb +8 -0
  57. data/lib/turf/interpolate.rb +8 -0
  58. data/lib/turf/intersect.rb +8 -0
  59. data/lib/turf/invariant.rb +127 -1
  60. data/lib/turf/isobands.rb +8 -0
  61. data/lib/turf/isolines.rb +8 -0
  62. data/lib/turf/kinks.rb +8 -0
  63. data/lib/turf/length.rb +6 -3
  64. data/lib/turf/lib/lineclip.rb +118 -0
  65. data/lib/turf/line_arc.rb +8 -0
  66. data/lib/turf/line_chunk.rb +8 -0
  67. data/lib/turf/line_intersect.rb +8 -0
  68. data/lib/turf/line_offset.rb +8 -0
  69. data/lib/turf/line_overlap.rb +8 -0
  70. data/lib/turf/line_segment.rb +8 -0
  71. data/lib/turf/line_slice.rb +8 -0
  72. data/lib/turf/line_slice_along.rb +8 -0
  73. data/lib/turf/line_split.rb +8 -0
  74. data/lib/turf/line_to_polygon.rb +8 -0
  75. data/lib/turf/mask.rb +8 -0
  76. data/lib/turf/meta.rb +445 -79
  77. data/lib/turf/midpoint.rb +8 -0
  78. data/lib/turf/moran_index.rb +8 -0
  79. data/lib/turf/nearest_neighbor_analysis.rb +8 -0
  80. data/lib/turf/nearest_point.rb +8 -0
  81. data/lib/turf/nearest_point_on_line.rb +8 -0
  82. data/lib/turf/nearest_point_to_line.rb +8 -0
  83. data/lib/turf/planepoint.rb +8 -0
  84. data/lib/turf/point_grid.rb +8 -0
  85. data/lib/turf/point_on_feature.rb +8 -0
  86. data/lib/turf/point_to_line_distance.rb +8 -0
  87. data/lib/turf/point_to_polygon_distance.rb +8 -0
  88. data/lib/turf/points_within_polygon.rb +8 -0
  89. data/lib/turf/polygon_smooth.rb +8 -0
  90. data/lib/turf/polygon_tangents.rb +8 -0
  91. data/lib/turf/polygon_to_line.rb +20 -0
  92. data/lib/turf/polygonize.rb +8 -0
  93. data/lib/turf/projection.rb +12 -0
  94. data/lib/turf/quadrat_analysis.rb +8 -0
  95. data/lib/turf/random.rb +20 -0
  96. data/lib/turf/rectangle_grid.rb +8 -0
  97. data/lib/turf/rewind.rb +8 -0
  98. data/lib/turf/rhumb_bearing.rb +8 -0
  99. data/lib/turf/rhumb_destination.rb +8 -0
  100. data/lib/turf/rhumb_distance.rb +8 -0
  101. data/lib/turf/sample.rb +8 -0
  102. data/lib/turf/sector.rb +8 -0
  103. data/lib/turf/shortest_path.rb +8 -0
  104. data/lib/turf/simplify.rb +8 -0
  105. data/lib/turf/square.rb +42 -0
  106. data/lib/turf/square_grid.rb +8 -0
  107. data/lib/turf/standard_deviational_ellipse.rb +8 -0
  108. data/lib/turf/tag.rb +8 -0
  109. data/lib/turf/tesselate.rb +8 -0
  110. data/lib/turf/tin.rb +8 -0
  111. data/lib/turf/transform_rotate.rb +8 -0
  112. data/lib/turf/transform_scale.rb +8 -0
  113. data/lib/turf/transform_translate.rb +8 -0
  114. data/lib/turf/triangle_grid.rb +8 -0
  115. data/lib/turf/truncate.rb +3 -0
  116. data/lib/turf/union.rb +8 -0
  117. data/lib/turf/unkink_polygon.rb +8 -0
  118. data/lib/turf/version.rb +2 -1
  119. data/lib/turf/voronoi.rb +8 -0
  120. data/lib/turf.rb +2 -0
  121. data/lib/turf_ruby.rb +107 -3
  122. metadata +105 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1759c68a13dd02fb326e6bf140b6a04cfc7c41cdb8094d444382438c74c639b
4
- data.tar.gz: aead3f8b19b118f5a5be8a5e9d45800e6888a85b0833ddd60289a7bef723cfdb
3
+ metadata.gz: 934aa7ef548c273fb906a74bd0d16b5344002274a8148ea4ec05ea7cf1b82cb6
4
+ data.tar.gz: 429c123473d5db24ec4aaf3562a1104c9c815d9b2579b843267f1cd451f6d639
5
5
  SHA512:
6
- metadata.gz: 7729eb457352857ab86aa6a8e2f18c0801395ac7adb81623e07f2ea4164f378ee0eade368d0933eb6e66b5264667f3899f40eed8372e799f1084a96a8f65f46c
7
- data.tar.gz: f105cc22e100bc24a73e6150b530a42a0b1f33dcc0326598da3fe18baed5e5674b3dc19d8f6c4b5b57a4329f224eed4a65adffffd4bab57b2ecb071c658dbb73
6
+ metadata.gz: 2fcdbcbb0a61f0a6ccf80c9f848fb0a60025bcb70803617ca211594228f9ab0a1d44f4d0563a63d3ac3399da812bbbe61140552d029d1987b4af00abbedd37f3
7
+ data.tar.gz: 0debca6e4ee62bfad49f9d7c3124fe295dbf361f67c2c340aa03a8ff2e3fc5aa564cd435e5ee929d4965a49b9dacea8d6730ba7932f3b9e4e0e2dae73d2a1f8f
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Rafael Santos
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -39,196 +39,216 @@ Currently not all functions are available, feel free to fork the repo and port m
39
39
 
40
40
  This list should be updated from [https://github.com/Turfjs/turf/blob/master/documentation.yml](https://github.com/Turfjs/turf/blob/master/documentation.yml).
41
41
 
42
- Measurement
43
-
42
+ ### Measurement
44
43
  - [x] along
45
44
  - [x] area
46
- - [ ] bbox
47
- - [ ] bboxPolygon
45
+ - [x] bbox
46
+ - [x] bbox_polygon
48
47
  - [x] bearing
49
- - [ ] center
50
- - [ ] centerOfMass
48
+ - [x] center
49
+ - [ ] center_of_mass
51
50
  - [x] centroid
52
51
  - [x] destination
53
52
  - [x] distance
54
53
  - [ ] envelope
54
+ - [ ] great_circle
55
55
  - [x] length
56
56
  - [ ] midpoint
57
- - [ ] pointOnFeature
58
- - [ ] polygonTangents
59
- - [ ] pointToLineDistance
60
- - [ ] rhumbBearing
61
- - [ ] rhumbDestination
62
- - [ ] rhumbDistance
63
- - [ ] square
64
- - [ ] greatCircle
65
-
66
- Coordinate Mutation
67
-
68
- - [ ] cleanCoords
57
+ - [ ] point_on_feature
58
+ - [ ] point_to_line_distance
59
+ - [ ] point_to_polygon_distance
60
+ - [ ] polygon_tangents
61
+ - [ ] rhumb_bearing
62
+ - [ ] rhumb_destination
63
+ - [ ] rhumb_distance
64
+ - [x] square
65
+
66
+ ### Coordinate Mutation
67
+ - [ ] clean_coords
69
68
  - [ ] flip
70
69
  - [ ] rewind
71
- - [ ] round
72
- - [ ] truncate
73
-
74
- Transformation
70
+ - [x] round
71
+ - [x] truncate
75
72
 
76
- - [ ] bboxClip
77
- - [ ] bezierSpline
73
+ ### Transformation
74
+ - [x] bbox_clip
75
+ - [ ] bezier_spline
78
76
  - [ ] buffer
79
- - [ ] circle
77
+ - [x] circle
80
78
  - [ ] clone
81
79
  - [ ] concave
82
80
  - [ ] convex
83
81
  - [ ] difference
84
82
  - [ ] dissolve
85
83
  - [ ] intersect
86
- - [ ] lineOffset
87
- - [ ] polygonSmooth
84
+ - [ ] line_offset
85
+ - [ ] polygon_smooth
88
86
  - [ ] simplify
89
87
  - [ ] tesselate
90
- - [ ] transformRotate
91
- - [ ] transformTranslate
92
- - [ ] transformScale
88
+ - [ ] transform_rotate
89
+ - [ ] transform_scale
90
+ - [ ] transform_translate
93
91
  - [ ] union
94
92
  - [ ] voronoi
95
93
 
96
- Feature Conversion
97
-
94
+ ### Feature Conversion
98
95
  - [ ] combine
99
- - [ ] explode
96
+ - [x] explode
100
97
  - [ ] flatten
101
- - [ ] lineToPolygon
98
+ - [ ] line_to_polygon
99
+ - [ ] polygon_to_line
102
100
  - [ ] polygonize
103
- - [ ] polygonToLine
104
-
105
- Misc
106
101
 
102
+ ### Misc
107
103
  - [ ] kinks
108
- - [ ] lineArc
109
- - [ ] lineChunk
110
- - [ ] lineIntersect
111
- - [ ] lineOverlap
112
- - [ ] lineSegment
113
- - [ ] lineSlice
114
- - [ ] lineSliceAlong
115
- - [ ] lineSplit
104
+ - [ ] line_arc
105
+ - [ ] line_chunk
106
+ - [ ] line_intersect
107
+ - [ ] line_overlap
108
+ - [ ] line_segment
109
+ - [ ] line_slice
110
+ - [ ] line_slice_along
111
+ - [ ] line_split
116
112
  - [ ] mask
117
- - [ ] nearestPointOnLine
113
+ - [ ] nearest_point_on_line
118
114
  - [ ] sector
119
- - [ ] shortestPath
120
- - [ ] unkinkPolygon
121
-
122
- Helper
115
+ - [ ] shortest_path
116
+ - [ ] unkink_polygon
123
117
 
124
- - [x] featureCollection
118
+ ### Helper
125
119
  - [x] feature
126
- - [x] geometryCollection
127
- - [x] lineString
128
- - [x] multiLineString
129
- - [x] multiPoint
130
- - [x] multiPolygon
120
+ - [x] feature_collection
121
+ - [x] geometry_collection
122
+ - [x] line_string
123
+ - [x] multi_line_string
124
+ - [x] multi_point
125
+ - [x] multi_polygon
131
126
  - [x] point
132
127
  - [x] polygon
133
128
 
134
- Random
135
-
136
- - [ ] randomPosition
137
- - [ ] randomPoint
138
- - [ ] randomLineString
139
- - [ ] randomPolygon
140
-
141
- Data
129
+ ### Random
130
+ - [ ] random_line_string
131
+ - [ ] random_point
132
+ - [ ] random_polygon
133
+ - [ ] random_position
142
134
 
135
+ ### Data
143
136
  - [ ] sample
144
137
 
145
- Interpolation
146
-
138
+ ### Interpolation
147
139
  - [ ] interpolate
148
140
  - [ ] isobands
149
141
  - [ ] isolines
150
142
  - [ ] planepoint
151
143
  - [ ] tin
152
144
 
153
- Joins
154
-
155
- - [ ] pointsWithinPolygon
145
+ ### Joins
146
+ - [ ] points_within_polygon
156
147
  - [ ] tag
157
148
 
158
- Grids
149
+ ### Grids
150
+ - [ ] hex_grid
151
+ - [ ] point_grid
152
+ - [ ] square_grid
153
+ - [ ] triangle_grid
159
154
 
160
- - [ ] hexGrid
161
- - [ ] pointGrid
162
- - [ ] squareGrid
163
- - [ ] triangleGrid
155
+ ### Classification
156
+ - [ ] nearest_point
164
157
 
165
- Classification
166
-
167
- - [ ] nearestPoint
158
+ ### Aggregation
159
+ - [ ] clusters_dbscan
160
+ - [ ] clusters_kmeans
161
+ - [ ] collect
168
162
 
169
- Aggregation
163
+ ### Meta
164
+ - [ ] cluster_each
165
+ - [ ] cluster_reduce
166
+ - [x] coord_all
167
+ - [x] coord_each
168
+ - [x] coord_reduce
169
+ - [x] feature_each
170
+ - [x] feature_reduce
171
+ - [x] flatten_each
172
+ - [x] flatten_reduce
173
+ - [x] geom_each
174
+ - [x] geom_reduce
175
+ - [ ] get_cluster
176
+ - [x] get_coord
177
+ - [x] get_coords
178
+ - [x] get_geom
179
+ - [x] get_type
180
+ - [x] prop_each
181
+ - [x] prop_reduce
182
+ - [x] segment_each
183
+ - [x] segment_reduce
184
+
185
+ ### Assertions
186
+ - [x] collection_of
187
+ - [x] contains_number
188
+ - [x] feature_of
189
+ - [x] geojson_type
190
+
191
+ ### Booleans
192
+ - [ ] boolean_clockwise
193
+ - [ ] boolean_concave
194
+ - [ ] boolean_contains
195
+ - [ ] boolean_crosses
196
+ - [ ] boolean_disjoint
197
+ - [ ] boolean_equal
198
+ - [ ] boolean_intersects
199
+ - [ ] boolean_overlap
200
+ - [ ] boolean_parallel
201
+ - [x] boolean_point_in_polygon
202
+ - [ ] boolean_point_on_line
203
+ - [ ] boolean_touches
204
+ - [ ] boolean_within
205
+
206
+ ### Unit Conversion
207
+ - [x] azimuth_to_bearing
208
+ - [x] bearing_to_azimuth
209
+ - [x] convert_area
210
+ - [x] convert_length
211
+ - [x] degrees_to_radians
212
+ - [x] length_to_degrees
213
+ - [x] length_to_radians
214
+ - [x] radians_to_degrees
215
+ - [x] radians_to_length
216
+ - [ ] to_mercator
217
+ - [ ] to_wgs84
218
+
219
+ ### Other
220
+ - [ ] angle
221
+ - [ ] boolean_valid
222
+ - [ ] center_mean
223
+ - [ ] center_median
224
+ - [ ] directional_mean
225
+ - [ ] distance_weight
226
+ - [ ] ellipse
227
+ - [x] find_point
228
+ - [x] find_segment
229
+ - [x] geometry
230
+ - [x] is_number
231
+ - [x] is_object
232
+ - [x] line_each
233
+ - [x] line_reduce
234
+ - [x] line_strings
235
+ - [ ] moran_index
236
+ - [ ] nearest_neighbor_analysis
237
+ - [ ] nearest_point_to_line
238
+ - [ ] p_norm_distance
239
+ - [x] points
240
+ - [x] polygons
241
+ - [ ] quadrat_analysis
242
+ - [x] rbush
243
+ - [ ] rectangle_grid
244
+ - [ ] standard_deviational_ellipse
245
+
246
+ ### Constants
247
+ - [ ] K_TABLE
248
+ - [x] AREA_FACTORS
249
+ - [x] EARTH_RADIUS
250
+ - [x] FACTORS
170
251
 
171
- - [ ] collect
172
- - [ ] clustersDbscan
173
- - [ ] clustersKmeans
174
-
175
- Meta
176
-
177
- - [ ] coordAll
178
- - [x] coordEach
179
- - [x] coordReduce
180
- - [x] featureEach
181
- - [x] featureReduce
182
- - [x] flattenEach
183
- - [x] flattenReduce
184
- - [x] getCoord
185
- - [ ] getCoords
186
- - [x] getGeom
187
- - [ ] getType
188
- - [x] geomEach
189
- - [x] geomReduce
190
- - [ ] propEach
191
- - [ ] propReduce
192
- - [ ] segmentEach
193
- - [ ] segmentReduce
194
- - [ ] getCluster
195
- - [ ] clusterEach
196
- - [ ] clusterReduce
197
-
198
- Assertions
199
-
200
- - [ ] collectionOf
201
- - [ ] containsNumber
202
- - [ ] geojsonType
203
- - [ ] featureOf
204
-
205
- Booleans
206
-
207
- - [ ] booleanClockwise
208
- - [ ] booleanConcave
209
- - [ ] booleanContains
210
- - [ ] booleanCrosses
211
- - [ ] booleanDisjoint
212
- - [ ] booleanEqual
213
- - [ ] booleanIntersects
214
- - [ ] booleanOverlap
215
- - [ ] booleanParallel
216
- - [x] booleanPointInPolygon
217
- - [ ] booleanPointOnLine
218
- - [ ] booleanWithin
219
-
220
- Unit Conversion
221
-
222
- - [ ] bearingToAzimuth
223
- - [ ] convertArea
224
- - [ ] convertLength
225
- - [ ] degreesToRadians
226
- - [x] lengthToRadians
227
- - [x] lengthToDegrees
228
- - [x] radiansToLength
229
- - [x] radiansToDegrees
230
- - [ ] toMercator
231
- - [ ] toWgs84
232
252
 
233
253
  ## Development
234
254
 
data/lib/turf/along.rb CHANGED
@@ -1,5 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "bearing"
4
+ require_relative "destination"
5
+ require_relative "distance"
6
+ require_relative "helpers"
7
+ require_relative "invariant"
8
+
3
9
  # :nodoc:
4
10
  module Turf
5
11
  # @!group Measurement
@@ -10,7 +16,8 @@ module Turf
10
16
  # @param distance [number] distance along the line
11
17
  # @param units [string] can be degrees, radians, miles, or kilometers (optional, default "kilometers")
12
18
  # @return [Feature<Point>] Point distance units along the line
13
- def along(line, distance, units: "kilometers")
19
+ def along(line, distance, options = {})
20
+ units = options[:units] || "kilometers"
14
21
  line = deep_symbolize_keys line
15
22
  travelled = 0
16
23
 
@@ -25,10 +32,10 @@ module Turf
25
32
  return point(coord) if overshot.zero?
26
33
 
27
34
  direction = bearing(coord, coords[i - 1]) - 180
28
- interpolated = destination(coord, overshot, direction, units: units)
35
+ interpolated = destination(coord, overshot, direction, { units: units })
29
36
  return interpolated
30
37
  else
31
- travelled += distance(coords[i], coords[i + 1], units: units)
38
+ travelled += distance(coords[i], coords[i + 1], { units: units })
32
39
  end
33
40
  end
34
41
 
data/lib/turf/angle.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Turf
5
+ def angle(*args)
6
+ raise NotImplementedError
7
+ end
8
+ end
data/lib/turf/area.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
  # Takes one or more features and returns their area in square meters.
@@ -7,7 +10,7 @@ module Turf
7
10
  # @param geojson [GeoJSON] input GeoJSON feature(s)
8
11
  # @return [number] aria in square meters
9
12
  def area(geojson)
10
- geom_reduce(geojson, initial_value: 0) do |value, geom|
13
+ geom_reduce(geojson, 0) do |value, geom|
11
14
  value + area_calculate_area(geom)
12
15
  end
13
16
  end
data/lib/turf/bbox.rb ADDED
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Turf
5
+ # Calculates the bounding box for any GeoJSON object, including FeatureCollection.
6
+ # Uses geojson[:bbox] if available and options[:recompute] is not set.
7
+ #
8
+ # @param [Hash] geojson any GeoJSON object
9
+ # @param [Hash] options optional parameters
10
+ # @option options [Boolean] :recompute whether to ignore an existing bbox property on geojson
11
+ # @return [Array<Float>] bbox extent in [minX, minY, maxX, maxY] order
12
+ # @example
13
+ # line = {
14
+ # type: "LineString",
15
+ # coordinates: [[-74, 40], [-78, 42], [-82, 35]]
16
+ # }
17
+ # bbox = bbox(line)
18
+ # puts bbox.inspect # => [-82, 35, -74, 42]
19
+ def bbox(geojson, options = {})
20
+ # If geojson has a bbox property and options[:recompute] is not true, return the existing bbox
21
+ return geojson[:bbox] if geojson[:bbox] && options[:recompute] != true
22
+
23
+ # Initialize the result array with infinity values
24
+ result = [Float::INFINITY, Float::INFINITY, -Float::INFINITY, -Float::INFINITY]
25
+
26
+ # Iterate through each coordinate in the GeoJSON object using coord_each
27
+ coord_each(geojson) do |coord|
28
+ result[0] = coord[0] if result[0] > coord[0] # minX
29
+ result[1] = coord[1] if result[1] > coord[1] # minY
30
+ result[2] = coord[0] if result[2] < coord[0] # maxX
31
+ result[3] = coord[1] if result[3] < coord[1] # maxY
32
+ end
33
+
34
+ result
35
+ end
36
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Turf
5
+ # Takes a Feature and a bbox and clips the feature to the bbox using
6
+ # [lineclip](https://github.com/mapbox/lineclip).
7
+ # May result in degenerate edges when clipping Polygons.
8
+ #
9
+ # @param [Feature<LineString, MultiLineString, Polygon, MultiPolygon>] feature Feature to clip to the bbox
10
+ # @param [BBox] bbox Extent in [minX, minY, maxX, maxY] order
11
+ # @return [Feature<LineString, MultiLineString, Polygon, MultiPolygon>] Clipped Feature
12
+ # @example
13
+ # bbox = [0, 0, 10, 10]
14
+ # poly = polygon([[[2, 2], [8, 4], [12, 8], [3, 7], [2, 2]]])
15
+ #
16
+ # clipped = bbox_clip(poly, bbox)
17
+ #
18
+ # # add_to_map
19
+ # add_to_map = [bbox, poly, clipped]
20
+ def bbox_clip(feature, bbox)
21
+ geom = get_geom(feature)
22
+ type = geom[:type]
23
+ properties = feature[:type] == "Feature" ? feature[:properties] : {}
24
+ coords = geom[:coordinates]
25
+
26
+ case type
27
+ when "LineString", "MultiLineString"
28
+ lines = []
29
+ coords = [coords] if type == "LineString"
30
+
31
+ coords.each do |line|
32
+ Lineclip.lineclip(line, bbox, lines)
33
+ end
34
+
35
+ if lines.length == 1
36
+ return line_string(lines[0], properties)
37
+ end
38
+
39
+ multi_line_string(lines, properties)
40
+ when "Polygon"
41
+ polygon(clip_polygon(coords, bbox), properties)
42
+ when "MultiPolygon"
43
+ multi_polygon(
44
+ coords.map { |poly| clip_polygon(poly, bbox) },
45
+ properties,
46
+ )
47
+ else
48
+ raise Error, "geometry #{type} not supported"
49
+ end
50
+ end
51
+
52
+ # Clips the rings of a Polygon or MultiPolygon to the bbox.
53
+ #
54
+ # @param [Array<Array<Array<Number>>>] rings The coordinates of the polygon rings
55
+ # @param [BBox] bbox Extent in [minX, minY, maxX, maxY] order
56
+ # @return [Array<Array<Array<Number>>>] Clipped polygon rings
57
+ def clip_polygon(rings, bbox)
58
+ out_rings = []
59
+
60
+ rings.each do |ring|
61
+ clipped = Lineclip.polygonclip(ring, bbox)
62
+
63
+ next unless clipped.any?
64
+
65
+ if clipped[0][0] != clipped[-1][0] || clipped[0][1] != clipped[-1][1]
66
+ clipped.push(clipped[0])
67
+ end
68
+
69
+ out_rings.push(clipped) if clipped.length >= 4
70
+ end
71
+
72
+ out_rings
73
+ end
74
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Turf
5
+ # Takes a bbox and returns an equivalent polygon.
6
+ #
7
+ # @param bbox [Array<Numeric>] extent in [minX, minY, maxX, maxY] order
8
+ # @param options [Hash] Optional parameters
9
+ # @option options [Hash] :properties Translate properties to Polygon
10
+ # @option options [String, Numeric] :id Translate Id to Polygon
11
+ # @return [Feature<Polygon>] a Polygon representation of the bounding box
12
+ # @example
13
+ # bbox = [0, 0, 10, 10]
14
+ # poly = bbox_polygon(bbox)
15
+ # # addToMap
16
+ # add_to_map = [poly]
17
+ def bbox_polygon(bbox, options = {})
18
+ # Convert BBox positions to Numbers
19
+ # No performance loss for including to_f
20
+ # https://github.com/Turfjs/turf/issues/1119
21
+ west = Float(bbox[0], exception: false) || Float::NAN
22
+ south = Float(bbox[1], exception: false) || Float::NAN
23
+ east = Float(bbox[2], exception: false) || Float::NAN
24
+ north = Float(bbox[3], exception: false) || Float::NAN
25
+
26
+ if bbox.length == 6
27
+ raise Error, "@turf/bbox-polygon does not support BBox with 6 positions"
28
+ end
29
+
30
+ low_left = [west, south]
31
+ top_left = [west, north]
32
+ top_right = [east, north]
33
+ low_right = [east, south]
34
+
35
+ polygon(
36
+ [[low_left, low_right, top_right, top_left, low_left]],
37
+ options[:properties] || {},
38
+ { bbox: bbox, id: options[:id] },
39
+ )
40
+ end
41
+ end
data/lib/turf/bearing.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,8 +14,8 @@ module Turf
11
14
  # @param to [Coord] ending Point
12
15
  # @param final boolean calculates the final bearing if true
13
16
  # @return [number] bearing in decimal degrees, between -180 and 180 degrees (positive clockwise)
14
- def bearing(from, to, final: false)
15
- return calculate_final_bearing(from, to) if final
17
+ def bearing(from, to, options = {})
18
+ return calculate_final_bearing(from, to) if options[:final]
16
19
 
17
20
  coordinates1 = get_coord from
18
21
  coordinates2 = get_coord to
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Turf
5
+ def bezier_spline(*args)
6
+ raise NotImplementedError
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Turf
5
+ def boolean_clockwise(*args)
6
+ raise NotImplementedError
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Turf
5
+ def boolean_concave(*args)
6
+ raise NotImplementedError
7
+ end
8
+ end