turf-ruby 0.8.0 → 0.8.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15efb6b14189380f9e59456b544fc7cb95436eeceefbf4772f4f6ee1ea2d8a4e
4
- data.tar.gz: 16d8e44ef4eea15d03ed3059375d3df6c6c793f8c178878b6e1ebcbdb4f6d509
3
+ metadata.gz: a1759c68a13dd02fb326e6bf140b6a04cfc7c41cdb8094d444382438c74c639b
4
+ data.tar.gz: aead3f8b19b118f5a5be8a5e9d45800e6888a85b0833ddd60289a7bef723cfdb
5
5
  SHA512:
6
- metadata.gz: 4362da521aff1c2514668c011fd86348c2df8d6cb27510b17459303e046a3550552810bcc5ff42593ff758d4998d84de897bedf1ca851a71da0e44baec0e589f
7
- data.tar.gz: ad865f140fab4344bdb0e05bdc31e4e505a8479d2e86e1cdf4dc986130f4033d540dbe4db6bfb2cf6c07bdbfadbb53ef6aeef784d656f75c205263b5fee0e9ac
6
+ metadata.gz: 7729eb457352857ab86aa6a8e2f18c0801395ac7adb81623e07f2ea4164f378ee0eade368d0933eb6e66b5264667f3899f40eed8372e799f1084a96a8f65f46c
7
+ data.tar.gz: f105cc22e100bc24a73e6150b530a42a0b1f33dcc0326598da3fe18baed5e5674b3dc19d8f6c4b5b57a4329f224eed4a65adffffd4bab57b2ecb071c658dbb73
data/README.md ADDED
@@ -0,0 +1,257 @@
1
+ # turf-ruby [![Build Status](https://travis-ci.com/formigarafa/turf-ruby.svg?branch=master)](https://travis-ci.com/formigarafa/turf-ruby)
2
+
3
+ Ruby port of [Turf.js](https://turfjs.org/), an advance geospatial analysis library.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'turf-ruby'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install turf-ruby
20
+
21
+ ## Usage
22
+
23
+ Example:
24
+
25
+ ```
26
+ # Turf.js uses [GeoJSON](https://en.wikipedia.org/wiki/GeoJSON) is input and output, so does turf-ruby.
27
+ from = { type: "Feature", geometry: { type: "Point", coordinates: [-75.343, 39.984] } }
28
+ to = { type: "Feature", geometry: { type: "Point", coordinates: [-75.534, 39.123] } }
29
+
30
+ Turf::distance(from, to, units: 'miles')
31
+ # 60.35329997171344
32
+ ```
33
+
34
+ You can view all methods here: [https://formigarafa.github.io/turf-ruby/](https://formigarafa.github.io/turf-ruby/). Most methods have their documentation linked to Turf.js.
35
+
36
+ ## Progress
37
+
38
+ Currently not all functions are available, feel free to fork the repo and port missing functions you need by reading [source code of Turf.js](https://github.com/Turfjs/turf/tree/master/packages/). And don't forget to open a pull-request afterward.
39
+
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
+
42
+ Measurement
43
+
44
+ - [x] along
45
+ - [x] area
46
+ - [ ] bbox
47
+ - [ ] bboxPolygon
48
+ - [x] bearing
49
+ - [ ] center
50
+ - [ ] centerOfMass
51
+ - [x] centroid
52
+ - [x] destination
53
+ - [x] distance
54
+ - [ ] envelope
55
+ - [x] length
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
69
+ - [ ] flip
70
+ - [ ] rewind
71
+ - [ ] round
72
+ - [ ] truncate
73
+
74
+ Transformation
75
+
76
+ - [ ] bboxClip
77
+ - [ ] bezierSpline
78
+ - [ ] buffer
79
+ - [ ] circle
80
+ - [ ] clone
81
+ - [ ] concave
82
+ - [ ] convex
83
+ - [ ] difference
84
+ - [ ] dissolve
85
+ - [ ] intersect
86
+ - [ ] lineOffset
87
+ - [ ] polygonSmooth
88
+ - [ ] simplify
89
+ - [ ] tesselate
90
+ - [ ] transformRotate
91
+ - [ ] transformTranslate
92
+ - [ ] transformScale
93
+ - [ ] union
94
+ - [ ] voronoi
95
+
96
+ Feature Conversion
97
+
98
+ - [ ] combine
99
+ - [ ] explode
100
+ - [ ] flatten
101
+ - [ ] lineToPolygon
102
+ - [ ] polygonize
103
+ - [ ] polygonToLine
104
+
105
+ Misc
106
+
107
+ - [ ] kinks
108
+ - [ ] lineArc
109
+ - [ ] lineChunk
110
+ - [ ] lineIntersect
111
+ - [ ] lineOverlap
112
+ - [ ] lineSegment
113
+ - [ ] lineSlice
114
+ - [ ] lineSliceAlong
115
+ - [ ] lineSplit
116
+ - [ ] mask
117
+ - [ ] nearestPointOnLine
118
+ - [ ] sector
119
+ - [ ] shortestPath
120
+ - [ ] unkinkPolygon
121
+
122
+ Helper
123
+
124
+ - [x] featureCollection
125
+ - [x] feature
126
+ - [x] geometryCollection
127
+ - [x] lineString
128
+ - [x] multiLineString
129
+ - [x] multiPoint
130
+ - [x] multiPolygon
131
+ - [x] point
132
+ - [x] polygon
133
+
134
+ Random
135
+
136
+ - [ ] randomPosition
137
+ - [ ] randomPoint
138
+ - [ ] randomLineString
139
+ - [ ] randomPolygon
140
+
141
+ Data
142
+
143
+ - [ ] sample
144
+
145
+ Interpolation
146
+
147
+ - [ ] interpolate
148
+ - [ ] isobands
149
+ - [ ] isolines
150
+ - [ ] planepoint
151
+ - [ ] tin
152
+
153
+ Joins
154
+
155
+ - [ ] pointsWithinPolygon
156
+ - [ ] tag
157
+
158
+ Grids
159
+
160
+ - [ ] hexGrid
161
+ - [ ] pointGrid
162
+ - [ ] squareGrid
163
+ - [ ] triangleGrid
164
+
165
+ Classification
166
+
167
+ - [ ] nearestPoint
168
+
169
+ Aggregation
170
+
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
+
233
+ ## Development
234
+
235
+ After checking out the repo, run `bundle install` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
236
+
237
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
238
+
239
+ ## Contributing
240
+
241
+ Bug reports and pull requests are welcome on GitHub at https://github.com/formigarafa/turf-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](CODE_OF_CONDUCT.md).
242
+
243
+
244
+ ## License
245
+
246
+ The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
247
+
248
+ ## Code of Conduct
249
+
250
+ Everyone interacting in the Turf Ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
251
+
252
+ ## Great Thanks
253
+
254
+ Great thanks to people that care to share and helping with the evolution of the community:
255
+
256
+ - [@layerssss](https://github.com/layerssss) - Michael Yin
257
+ - [@Henridv](https://github.com/Henridv) - Henri De Veene
data/lib/turf/circle.rb CHANGED
@@ -11,19 +11,16 @@ module Turf
11
11
  # @param {string} [options.units='kilometers'] miles, kilometers, degrees, or radians
12
12
  # @param {hash} [options.properties={}] properties
13
13
  # @returns {Feature<Polygon>} circle polygon
14
- def circle(center, radius, options = {}, units: nil, steps: 64)
15
- # default params
14
+ def circle(center, radius, options = {})
16
15
  center = deep_symbolize_keys(center)
17
- properties = options[:properties] || (
18
- !center.is_a?(Array) && center[:type] == "Feature" && center[:properties] ? center[:properties] : {}
19
- )
16
+ # default params
17
+ steps = options[:steps] || 64
18
+ properties = options[:properties]
19
+ properties ||= !center.is_a?(Array) && center[:type] == "Feature" && center[:properties]
20
+ properties ||= {}
20
21
 
21
22
  # main
22
23
  coordinates = []
23
- destination_options = { properties: properties }
24
- if units
25
- destination_options[:units] = units
26
- end
27
24
  steps.times do |i|
28
25
  coordinates.push(destination(center, radius, (i * -360.0) / steps, **options).dig(:geometry, :coordinates))
29
26
  end
@@ -13,12 +13,12 @@ module Turf
13
13
  # @param units [string] miles, kilometers, degrees, or radians
14
14
  # @param properties [Hash] Translate properties to Point
15
15
  # @return [Feature<Point>] destination point
16
- def destination(origin, distance, bearing, units: "kilometers", properties: {})
16
+ def destination(origin, distance, bearing, options = {})
17
17
  coordinates1 = get_coord origin
18
18
  longitude1 = degrees_to_radians coordinates1[0]
19
19
  latitude1 = degrees_to_radians coordinates1[1]
20
20
  bearing_radians = degrees_to_radians bearing
21
- radians = length_to_radians distance, units
21
+ radians = length_to_radians distance, options[:units]
22
22
 
23
23
  latitude2 = Math.asin((Math.sin(latitude1) * Math.cos(radians)) +
24
24
  (Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearing_radians)))
@@ -29,6 +29,6 @@ module Turf
29
29
  lng = radians_to_degrees(longitude2)
30
30
  lat = radians_to_degrees(latitude2)
31
31
 
32
- point([lng, lat], properties: properties)
32
+ point([lng, lat], properties: options[:properties])
33
33
  end
34
34
  end
data/lib/turf/helpers.rb CHANGED
@@ -209,7 +209,8 @@ module Turf
209
209
  # @param radians [number] in radians across the sphere
210
210
  # @param units [string] can be degrees, radians, miles, inches, yards, metres, meters, kilometres, kilometers.
211
211
  # @return [number] distance
212
- def radians_to_length(radians, units = "kilometers")
212
+ def radians_to_length(radians, units = nil)
213
+ units ||= "kilometers"
213
214
  factor = FACTORS[units]
214
215
  raise Error, "#{units} units is invalid" unless factor
215
216
 
@@ -222,7 +223,8 @@ module Turf
222
223
  # @param distance [number] in real units
223
224
  # @param units [string] can be degrees, radians, miles, inches, yards, metres, meters, kilometres, kilometers.
224
225
  # @return [number] radians
225
- def length_to_radians(distance, units = "kilometers")
226
+ def length_to_radians(distance, units = nil)
227
+ units ||= "kilometers"
226
228
  factor = FACTORS[units]
227
229
  raise Error, "#{units} units is invalid" unless factor
228
230
 
data/lib/turf/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Turf
4
4
  # Version of turf-ruby
5
- VERSION = "0.8.0"
5
+ VERSION = "0.8.1"
6
6
  end
data/turf-ruby.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/turf/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "turf-ruby"
7
+ spec.version = Turf::VERSION
8
+ spec.authors = ["Rafael Santos"]
9
+ spec.email = ["formigarafa@gmail.com"]
10
+
11
+ spec.summary = "A modular geospatial engine. Ruby port of TurfJS."
12
+ spec.description = [
13
+ "Turf Ruby is a Ruby library for spatial analysis. ",
14
+ "It includes traditional spatial operations, helper functions for creating",
15
+ " GeoJSON data, and data classification and statistics tools.",
16
+ ].join
17
+ spec.homepage = "http://github.com/formigarafa/turf-ruby"
18
+ spec.license = "MIT"
19
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = spec.homepage
23
+ spec.metadata["documentation_uri"] = "https://formigarafa.github.io/turf-ruby/"
24
+
25
+ spec.files = Dir["*.gemspec", "lib/**/*", "LICENSE.txt", "README.md"]
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+ spec.metadata["rubygems_mfa_required"] = "true"
30
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turf-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafael Santos
@@ -13,11 +13,12 @@ description: Turf Ruby is a Ruby library for spatial analysis. It includes tradi
13
13
  spatial operations, helper functions for creating GeoJSON data, and data classification
14
14
  and statistics tools.
15
15
  email:
16
- - santos@rafael.nz
16
+ - formigarafa@gmail.com
17
17
  executables: []
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
+ - README.md
21
22
  - lib/turf.rb
22
23
  - lib/turf/along.rb
23
24
  - lib/turf/area.rb
@@ -34,6 +35,7 @@ files:
34
35
  - lib/turf/truncate.rb
35
36
  - lib/turf/version.rb
36
37
  - lib/turf_ruby.rb
38
+ - turf-ruby.gemspec
37
39
  homepage: http://github.com/formigarafa/turf-ruby
38
40
  licenses:
39
41
  - MIT