turf-ruby 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b858fdec044cd9bcb71a29727849dee8ff75f74cf4bf2f97163fafb08be006ab
4
- data.tar.gz: 718bd40cab7ece92b2f95d080d7596bfbac2de785b3ba129078c01a2085cc252
3
+ metadata.gz: 989a5a140f46d9b673a83f71d3df89e6e6b2f9eaa23266a49db3ebeace62ce15
4
+ data.tar.gz: 921c501f57d3446e76a505a0f6be9d9549a4f7cd09a57699b192ab2ae8ff7eff
5
5
  SHA512:
6
- metadata.gz: c115975844db3097b16c9ba05b601104a9f8de6ff4216797dab70bfd539b282493d9988835074ed2ba36f43ae806f8d101278e021d4615dcb7153c8cadec95fc
7
- data.tar.gz: f155f788ea240f39d93603f6cd33e6712ccd7acfb71ca63d6052ad3f1df9d14d2b52d32ec8395f24ee6f922920dca57961d874d9fc41ebc566d4d3fc340c43fe
6
+ metadata.gz: 41d5d74fffef50e570dd4171a5b3518a8b7a07b5ff697da60ef0fddd718919aee2affd646647f99176e5b13f1ee5264249845bf403930831cfe4849da4431127
7
+ data.tar.gz: e50d3fdba23ffcb7d73e345bfde22c7fdb3793a0a2b9c923afe52f6bfe8b0893da6a617bbd3d258f7b2229fdca59c1a33a622b9a67dd11e831ec34db0b29666c
data/lib/turf.rb CHANGED
@@ -2,11 +2,18 @@
2
2
 
3
3
  require "turf/version"
4
4
 
5
+ # Ruby port of Turf.js, an advance geospatial analysis library.
6
+ # @see https://turfjs.org/
5
7
  module Turf
8
+ # Error thrown by turf-ruby
6
9
  class Error < StandardError; end
7
10
 
11
+ extend self
12
+
13
+ private
14
+
8
15
  # A non-intrusive implemenation of Rails' Hash#deep_symbolize_keys
9
- def self.deep_symbolize_keys(hash)
16
+ def deep_symbolize_keys(hash)
10
17
  return hash unless hash.is_a? Hash
11
18
 
12
19
  hash.transform_keys(&:to_sym).transform_values do |value|
data/lib/turf/along.rb CHANGED
@@ -1,7 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Turf
4
- def self.along(line, distance, **options)
4
+ # @!group Measurement
5
+
6
+ # Takes a LineString and returns a Point at a specified distance along the line.
7
+ # @see http://turfjs.org/docs/#along
8
+ # @param line [Feature<LineString>] input line
9
+ # @param distance [number] distance along the line
10
+ # @param units [string] can be degrees, radians, miles, or kilometers (optional, default "kilometers")
11
+ # @return [Feature<Point>] Point distance units along the line
12
+ def along(line, distance, units: "kilometers")
13
+ line = deep_symbolize_keys line
5
14
  travelled = 0
6
15
 
7
16
  geom = get_geom line
@@ -15,10 +24,10 @@ module Turf
15
24
  return point(coord) if overshot.zero?
16
25
 
17
26
  direction = bearing(coord, coords[i - 1]) - 180
18
- interpolated = destination(coord, overshot, direction, options)
27
+ interpolated = destination(coord, overshot, direction, units: units)
19
28
  return interpolated
20
29
  else
21
- travelled += distance(coords[i], coords[i + 1], options)
30
+ travelled += distance(coords[i], coords[i + 1], units: units)
22
31
  end
23
32
  end
24
33
 
data/lib/turf/bearing.rb CHANGED
@@ -1,8 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Turf
4
- def self.bearing(from, to, **options)
5
- return calculate_final_bearing(from, to) if options[:final] == true
4
+ # @!group Measurement
5
+
6
+ # Takes two points and finds the geographic bearing between them, i.e. the angle measured in degrees from the north
7
+ # line (0 degrees)
8
+ # @see http://turfjs.org/docs/#bearing
9
+ # @param from [Coord] starting Point
10
+ # @param to [Coord] ending Point
11
+ # @param final boolean calculates the final bearing if true
12
+ # @return [number] bearing in decimal degrees, between -180 and 180 degrees (positive clockwise)
13
+ def bearing(from, to, final: false)
14
+ return calculate_final_bearing(from, to) if final
6
15
 
7
16
  coordinates1 = get_coord from
8
17
  coordinates2 = get_coord to
@@ -18,7 +27,9 @@ module Turf
18
27
  radians_to_degrees(Math.atan2(a, b))
19
28
  end
20
29
 
21
- def self.calculate_final_bearing(from, to)
30
+ private
31
+
32
+ def calculate_final_bearing(from, to)
22
33
  bear = bearing(to, from)
23
34
  (bear + 180) % 360
24
35
  end
@@ -1,48 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # https://github.com/Turfjs/turf/blob/master/packages/turf-boolean-point-in-polygon/index.ts
4
- def in_bbox(point, bbox)
5
- bbox[0] <= point[0] &&
6
- bbox[1] <= point[1] &&
7
- bbox[2] >= point[0] &&
8
- bbox[3] >= point[1]
9
- end
10
-
11
- def in_ring(point, ring, ignore_boundary)
12
- is_inside = false
13
- is_ring_valid = ring[0][0] == ring[ring.size - 1][0]
14
- is_ring_valid &&= ring[0][1] == ring[ring.size - 1][1]
15
- if is_ring_valid
16
- ring = ring.slice(0, ring.size - 1)
17
- end
18
- ring.each_with_index do |ring_pt, ring_pt_index|
19
- ring_pt2 = ring[(ring_pt_index + 1) % ring.size]
20
-
21
- xi = ring_pt[0]
22
- yi = ring_pt[1]
23
- xj = ring_pt2[0]
24
- yj = ring_pt2[1]
25
-
26
- on_boundary = (
27
- point[1] * (xi - xj) + yi * (xj - point[0]) + yj * (point[0] - xi)
28
- ).zero?
29
- on_boundary &&= ((xi - point[0]) * (xj - point[0]) <= 0)
30
- on_boundary &&= ((yi - point[1]) * (yj - point[1]) <= 0)
31
- if on_boundary
32
- return !ignore_boundary
33
- end
34
-
35
- intersect = ((yi > point[1]) != (yj > point[1])) &&
36
- (point[0] < (xj - xi) * (point[1] - yi) / (yj - yi) + xi)
37
- if intersect
38
- is_inside = !is_inside
39
- end
40
- end
41
- is_inside
42
- end
43
-
44
3
  module Turf
45
- def self.boolean_point_in_polygon(point, polygon, ignore_boundary: false)
4
+ # @!group Booleans
5
+
6
+ # Takes a Point and a Polygon or MultiPolygon and determines if the point resides inside the polygon. The polygon
7
+ # can be convex or concave. The function accounts for holes.
8
+ # @see http://turfjs.org/docs/#booleanPointInPolygon
9
+ # @param point [Coord] input point
10
+ # @param polygon [Feature<(Polygon | MultiPolygon)>] input polygon or multipolygon
11
+ # @param ignore_boundary [boolean] True if polygon boundary should be ignored when determining if the point is
12
+ # inside
13
+ # the polygon otherwise false.
14
+ # @return [boolean] true if the Point is inside the Polygon; false if the Point is not inside the Polygon
15
+ def boolean_point_in_polygon(point, polygon, ignore_boundary: false)
46
16
  polygon = deep_symbolize_keys(polygon)
47
17
  pt = get_coord(point)
48
18
  geom = get_geom(polygon)
@@ -75,4 +45,46 @@ module Turf
75
45
  end
76
46
  inside_poly
77
47
  end
48
+
49
+ private
50
+
51
+ def in_bbox(point, bbox)
52
+ bbox[0] <= point[0] &&
53
+ bbox[1] <= point[1] &&
54
+ bbox[2] >= point[0] &&
55
+ bbox[3] >= point[1]
56
+ end
57
+
58
+ def in_ring(point, ring, ignore_boundary)
59
+ is_inside = false
60
+ is_ring_valid = ring[0][0] == ring[ring.size - 1][0]
61
+ is_ring_valid &&= ring[0][1] == ring[ring.size - 1][1]
62
+ if is_ring_valid
63
+ ring = ring.slice(0, ring.size - 1)
64
+ end
65
+ ring.each_with_index do |ring_pt, ring_pt_index|
66
+ ring_pt2 = ring[(ring_pt_index + 1) % ring.size]
67
+
68
+ xi = ring_pt[0]
69
+ yi = ring_pt[1]
70
+ xj = ring_pt2[0]
71
+ yj = ring_pt2[1]
72
+
73
+ on_boundary = (
74
+ point[1] * (xi - xj) + yi * (xj - point[0]) + yj * (point[0] - xi)
75
+ ).zero?
76
+ on_boundary &&= ((xi - point[0]) * (xj - point[0]) <= 0)
77
+ on_boundary &&= ((yi - point[1]) * (yj - point[1]) <= 0)
78
+ if on_boundary
79
+ return !ignore_boundary
80
+ end
81
+
82
+ intersect = ((yi > point[1]) != (yj > point[1])) &&
83
+ (point[0] < (xj - xi) * (point[1] - yi) / (yj - yi) + xi)
84
+ if intersect
85
+ is_inside = !is_inside
86
+ end
87
+ end
88
+ is_inside
89
+ end
78
90
  end
@@ -1,12 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Turf
4
- def self.destination(origin, distance, bearing, **options)
4
+ # @!group Measurement
5
+
6
+ # Takes a Point and calculates the location of a destination point given a distance in degrees, radians, miles, or
7
+ # kilometers; and bearing in degrees. This uses the Haversine formula to account for global curvature.
8
+ # @see http://turfjs.org/docs/#destination
9
+ # @param origin [Coord] starting point
10
+ # @param distance [number] distance from the origin point
11
+ # @param bearing [number] ranging from -180 to 180
12
+ # @param units [string] miles, kilometers, degrees, or radians
13
+ # @param properties [Hash] Translate properties to Point
14
+ # @return [Feature<Point>] destination point
15
+ def destination(origin, distance, bearing, units: "kilometers", properties: {})
5
16
  coordinates1 = get_coord origin
6
17
  longitude1 = degrees_to_radians coordinates1[0]
7
18
  latitude1 = degrees_to_radians coordinates1[1]
8
19
  bearing_radians = degrees_to_radians bearing
9
- radians = length_to_radians distance, options[:units]
20
+ radians = length_to_radians distance, units
10
21
 
11
22
  latitude2 = Math.asin(Math.sin(latitude1) * Math.cos(radians) +
12
23
  Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearing_radians))
@@ -17,6 +28,7 @@ module Turf
17
28
  lng = radians_to_degrees(longitude2)
18
29
  lat = radians_to_degrees(latitude2)
19
30
 
20
- point([lng, lat], options[:properties])
31
+ # prevent ruby@2 converting `properties` as kwargs
32
+ point([lng, lat], properties, **{})
21
33
  end
22
34
  end
@@ -1,7 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Turf
4
- def self.distance(from, to, **options)
4
+ # @!group Measurement
5
+
6
+ # Calculates the distance between two points in degrees, radians, miles, or kilometers. This uses the Haversine
7
+ # formula to account for global curvature.
8
+ # @see http://turfjs.org/docs/#distance
9
+ # @param from [Coord] origin point
10
+ # @param to [Coord] destination point
11
+ # @param units [string] can be degrees, radians, miles, or kilometers
12
+ # @return [number] distance between the two points
13
+ def distance(from, to, units: "kilometers")
5
14
  coordinates1 = get_coord from
6
15
  coordinates2 = get_coord to
7
16
 
@@ -16,15 +25,12 @@ module Turf
16
25
  (Math.sin(d_lon / 2)**2) * Math.cos(lat1) * Math.cos(lat2)
17
26
  )
18
27
 
19
- call_args = [
28
+ radians_to_length(
20
29
  2 * Math.atan2(
21
30
  Math.sqrt(a),
22
31
  Math.sqrt(1 - a),
23
32
  ),
24
- ]
25
- if options[:units]
26
- call_args << options[:units]
27
- end
28
- public_send(:radians_to_length, *call_args)
33
+ units,
34
+ )
29
35
  end
30
36
  end
@@ -0,0 +1,169 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Turf
4
+ EARTH_RADIUS = 6_371_008.8
5
+ private_constant :EARTH_RADIUS
6
+ FACTORS = {
7
+ "centimeters" => EARTH_RADIUS * 100,
8
+ "centimetres" => EARTH_RADIUS * 100,
9
+ "degrees" => EARTH_RADIUS / 111_325,
10
+ "feet" => EARTH_RADIUS * 3.28084,
11
+ "inches" => EARTH_RADIUS * 39.370,
12
+ "kilometers" => EARTH_RADIUS / 1000,
13
+ "kilometres" => EARTH_RADIUS / 1000,
14
+ "meters" => EARTH_RADIUS,
15
+ "metres" => EARTH_RADIUS,
16
+ "miles" => EARTH_RADIUS / 1609.344,
17
+ "millimeters" => EARTH_RADIUS * 1000,
18
+ "millimetres" => EARTH_RADIUS * 1000,
19
+ "nauticalmiles" => EARTH_RADIUS / 1852,
20
+ "radians" => 1,
21
+ "yards" => EARTH_RADIUS / 1.0936
22
+ }.freeze
23
+ private_constant :FACTORS
24
+
25
+ # @!group Helper
26
+
27
+ # Wraps a GeoJSON Geometry in a GeoJSON Feature.
28
+ # @see https://turfjs.org/docs/#feature
29
+ # @param geom [Geometry] input geometry
30
+ # @param properties [Hash] an Object of key-value pairs to add as properties
31
+ # @param bbox [Array<number>] Bounding Box Array [west, south, east, north] associated with the Feature
32
+ # @param id [string | number] Identifier associated with the Feature
33
+ # @return [Feature] a GeoJSON Feature
34
+ def feature(geom, properties = {}, bbox: nil, id: nil)
35
+ feat = {
36
+ type: "Feature",
37
+ geometry: geom,
38
+ properties: properties
39
+ }
40
+ feat[:id] = options[:id] if id
41
+ feat[:bbox] = options[:bbox] if bbox
42
+
43
+ feat
44
+ end
45
+
46
+ # Takes one or more Features and creates a FeatureCollection.
47
+ # @see https://turfjs.org/docs/#featureCollection
48
+ # @param features [Array<Feature>] input features
49
+ # @param bbox [Array<number>] Bounding Box Array [west, south, east, north] associated with the Feature
50
+ # @param id [string | number] Identifier associated with the Feature
51
+ # @return [FeatureCollection] FeatureCollection of Features
52
+ def feature_collection(features, bbox: nil, id: nil)
53
+ fc = { type: "FeatureCollection" }
54
+ fc[:id] = options[:id] if id
55
+ fc[:bbox] = options[:bbox] if bbox
56
+ fc[:features] = features
57
+
58
+ fc
59
+ end
60
+
61
+ # Creates a LineString Feature from an Array of Positions.
62
+ # @see https://turfjs.org/docs/#lineString
63
+ # @param coordinates [Array<Array<number>>] an array of Positions
64
+ # @param properties [Hash] an Hash of key-value pairs to add as properties
65
+ # @param bbox [Array<number>] Bounding Box Array [west, south, east, north] associated with the Feature
66
+ # @param id [string | number] Identifier associated with the Feature
67
+ # @return [Feature<LineString>] LineString Feature
68
+ def line_string(coordinates, properties = {}, bbox: nil, id: nil)
69
+ if coordinates.size < 2
70
+ raise Error, "coordinates must be an array of two or more positions"
71
+ end
72
+
73
+ geom = {
74
+ type: "LineString",
75
+ coordinates: coordinates
76
+ }
77
+ feature(geom, properties, bbox: bbox, id: id)
78
+ end
79
+
80
+ # Creates a Point Feature from a Position.
81
+ # @see https://turfjs.org/docs/#point
82
+ # @param coordinates [Array<number>] longitude, latitude position (each in decimal degrees)
83
+ # @param properties [Hash] an Hash of key-value pairs to add as properties
84
+ # @param bbox [Array<number>] Bounding Box Array [west, south, east, north] associated with the Feature
85
+ # @param id [string | number] Identifier associated with the Feature
86
+ # @return [Feature<Point>] a Point feature
87
+ def point(coordinates, properties = {}, id: nil, bbox: nil)
88
+ geom = {
89
+ type: "Point",
90
+ coordinates: coordinates
91
+ }
92
+ feature(geom, properties, id: id, bbox: bbox)
93
+ end
94
+
95
+ # Creates a Polygon Feature from an Array of LinearRings.
96
+ # @see https://turfjs.org/docs/#polygon
97
+ # @param coordinates [Array<Array<Array<number>>>] an array of LinearRings
98
+ # @param properties [Hash] an Hash of key-value pairs to add as properties
99
+ # @param bbox [Array<number>] Bounding Box Array [west, south, east, north] associated with the Feature
100
+ # @param id [string | number] Identifier associated with the Feature
101
+ # @return [Feature<Polygon>] Polygon feature
102
+ def polygon(coordinates, properties = {}, bbox: nil, id: nil)
103
+ coordinates.each do |ring|
104
+ if ring.size < 4
105
+ raise(
106
+ Error,
107
+ "Each LinearRing of a Polygon must have 4 or more Positions.",
108
+ )
109
+ end
110
+
111
+ ring.last.each_with_index do |number, idx|
112
+ if ring.first[idx] != number
113
+ raise Error, "First and last Position are not equivalent."
114
+ end
115
+ end
116
+ end
117
+ geom = {
118
+ type: "Polygon",
119
+ coordinates: coordinates
120
+ }
121
+ feature(geom, properties, id: id, bbox: bbox)
122
+ end
123
+
124
+ # @!group Unit Conversion
125
+
126
+ # Converts an angle in radians to degrees
127
+ # @see https://turfjs.org/docs/#radiansToDegrees
128
+ # @param radians [number] angle in radians
129
+ # @return [number] degrees between 0 and 360 degrees
130
+ def radians_to_degrees(radians)
131
+ degrees = radians.remainder(2 * Math::PI)
132
+ degrees * 180 / Math::PI
133
+ end
134
+
135
+ # Converts an angle in degrees to radians
136
+ # @see https://turfjs.org/docs/#degreesToRadians
137
+ # @param degrees [number] angle between 0 and 360 degrees
138
+ # @return [number] angle in radians
139
+ def degrees_to_radians(degrees)
140
+ radians = degrees.remainder(360)
141
+ radians * Math::PI / 180
142
+ end
143
+
144
+ # Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit. Valid units:
145
+ # miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
146
+ # @see https://turfjs.org/docs/#radiansToLength
147
+ # @param radians [number] in radians across the sphere
148
+ # @param units [string] can be degrees, radians, miles, inches, yards, metres, meters, kilometres, kilometers.
149
+ # @return [number] distance
150
+ def radians_to_length(radians, units = "kilometers")
151
+ factor = FACTORS[units]
152
+ raise Error, "#{units} units is invalid" unless factor
153
+
154
+ radians * factor
155
+ end
156
+
157
+ # Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians Valid units: miles,
158
+ # nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
159
+ # @see https://turfjs.org/docs/#lengthToRadians
160
+ # @param distance [number] in real units
161
+ # @param units [string] can be degrees, radians, miles, inches, yards, metres, meters, kilometres, kilometers.
162
+ # @return [number] radians
163
+ def length_to_radians(distance, units = "kilometers")
164
+ factor = FACTORS[units]
165
+ raise Error, "#{units} units is invalid" unless factor
166
+
167
+ distance / factor
168
+ end
169
+ end
@@ -1,7 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Turf
4
- def self.get_coord(coord)
4
+ # @!group Meta
5
+
6
+ # Unwrap a coordinate from a Point Feature, Geometry or a single coordinate.
7
+ # @see https://turfjs.org/docs/#getCoord
8
+ # @param coord [Array|Geometry<Point>|Feature<Point>] GeoJSON Point or an Array of numbers
9
+ # @return [Array] coordinates
10
+ def get_coord(coord)
5
11
  if !coord
6
12
  raise Error, "coord is required"
7
13
  end
@@ -27,7 +33,12 @@ module Turf
27
33
  raise Error, "coord must be GeoJSON Point or an Array of numbers"
28
34
  end
29
35
 
30
- def self.get_geom(geojson)
36
+ # Get Geometry from Feature or Geometry Object
37
+ # @see https://turfjs.org/docs/#getGeom
38
+ # @param geojson [Feature|Geometry] GeoJSON Feature or Geometry Object
39
+ # @return [Geometry|null] GeoJSON Geometry Object
40
+ def get_geom(geojson)
41
+ geojson = deep_symbolize_keys geojson
31
42
  return geojson[:geometry] if geojson[:type] == "Feature"
32
43
 
33
44
  geojson
data/lib/turf/version.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Turf
4
- VERSION = "0.3.0"
4
+ # Version of turf-ruby
5
+ VERSION = "0.4.0"
5
6
  end
data/lib/turf_ruby.rb CHANGED
@@ -1,10 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "turf"
4
- require "turf/along"
3
+ # Functions should be put into module with same package name in Turf.js
4
+ #
5
+ # https://github.com/Turfjs/turf/tree/master/packages
6
+ #
7
+ require "turf/helpers"
5
8
  require "turf/bearing"
6
9
  require "turf/destination"
7
- require "turf/helper"
8
- require "turf/measurement"
10
+ require "turf/along"
11
+ require "turf/distance"
9
12
  require "turf/invariant"
10
13
  require "turf/boolean_point_in_polygon"
14
+
15
+ require "turf"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turf-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafael Santos
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-05 00:00:00.000000000 Z
11
+ date: 2021-06-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Turf Ruby is a Ruby library for spatial analysis. It includes traditional
14
14
  spatial operations, helper functions for creating GeoJSON data, and data classification
@@ -19,36 +19,24 @@ executables: []
19
19
  extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
- - ".gitignore"
23
- - ".hound.yml"
24
- - ".rubocop.yml"
25
- - ".travis.yml"
26
- - CODE_OF_CONDUCT.md
27
- - Gemfile
28
- - Gemfile.lock
29
- - LICENSE.txt
30
- - README.md
31
- - Rakefile
32
- - bin/console
33
- - bin/setup
34
22
  - lib/turf.rb
35
23
  - lib/turf/along.rb
36
24
  - lib/turf/bearing.rb
37
25
  - lib/turf/boolean_point_in_polygon.rb
38
26
  - lib/turf/destination.rb
39
- - lib/turf/helper.rb
27
+ - lib/turf/distance.rb
28
+ - lib/turf/helpers.rb
40
29
  - lib/turf/invariant.rb
41
- - lib/turf/measurement.rb
42
30
  - lib/turf/version.rb
43
31
  - lib/turf_ruby.rb
44
- - turf-ruby.gemspec
45
32
  homepage: http://github.com/formigarafa/turf-ruby
46
33
  licenses:
47
34
  - MIT
48
35
  metadata:
49
36
  homepage_uri: http://github.com/formigarafa/turf-ruby
50
37
  source_code_uri: http://github.com/formigarafa/turf-ruby
51
- post_install_message:
38
+ documentation_uri: https://formigarafa.github.io/turf-ruby/
39
+ post_install_message:
52
40
  rdoc_options: []
53
41
  require_paths:
54
42
  - lib
@@ -56,16 +44,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
56
44
  requirements:
57
45
  - - ">="
58
46
  - !ruby/object:Gem::Version
59
- version: 2.3.0
47
+ version: '0'
60
48
  required_rubygems_version: !ruby/object:Gem::Requirement
61
49
  requirements:
62
50
  - - ">="
63
51
  - !ruby/object:Gem::Version
64
52
  version: '0'
65
53
  requirements: []
66
- rubyforge_project:
67
- rubygems_version: 2.7.6.2
68
- signing_key:
54
+ rubyforge_project:
55
+ rubygems_version: 2.7.6.3
56
+ signing_key:
69
57
  specification_version: 4
70
58
  summary: A modular geospatial engine. Ruby port of TurfJS.
71
59
  test_files: []
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
- .ruby-version
data/.hound.yml DELETED
@@ -1,5 +0,0 @@
1
- fail_on_violations: true
2
-
3
- rubocop:
4
- config_file: .rubocop.yml
5
- version: 0.80.0
data/.rubocop.yml DELETED
@@ -1,32 +0,0 @@
1
- Layout/FirstArrayElementIndentation:
2
- EnforcedStyle: consistent
3
-
4
- Metrics:
5
- Enabled: false
6
-
7
- Style/Documentation:
8
- Enabled: false
9
-
10
- Style/HashEachMethods:
11
- Enabled: false
12
-
13
- Style/HashTransformKeys:
14
- Enabled: true
15
-
16
- Style/HashTransformValues:
17
- Enabled: true
18
-
19
- Style/IfUnlessModifier:
20
- Enabled: false
21
-
22
- Style/NegatedIf:
23
- Enabled: false
24
-
25
- Style/StringLiterals:
26
- EnforcedStyle: double_quotes
27
-
28
- Style/TrailingCommaInArguments:
29
- EnforcedStyleForMultiline: comma
30
-
31
- Style/TrailingCommaInArrayLiteral:
32
- EnforcedStyleForMultiline: consistent_comma
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.7.0
6
- before_install: gem install bundler -v 2.1.4
data/CODE_OF_CONDUCT.md DELETED
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at formigarafa@gmail.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [https://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: https://contributor-covenant.org
74
- [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile DELETED
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- # Specify your gem's dependencies in turf-ruby.gemspec
6
- gemspec
7
-
8
- gem "minitest", "~> 5.0"
9
- gem "minitest-focus"
10
- gem "rake", "~> 12.0"
data/Gemfile.lock DELETED
@@ -1,24 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- turf-ruby (0.3.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- minitest (5.14.0)
10
- minitest-focus (1.2.1)
11
- minitest (>= 4, < 6)
12
- rake (12.3.3)
13
-
14
- PLATFORMS
15
- ruby
16
-
17
- DEPENDENCIES
18
- minitest (~> 5.0)
19
- minitest-focus
20
- rake (~> 12.0)
21
- turf-ruby!
22
-
23
- BUNDLED WITH
24
- 2.1.4
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
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 DELETED
@@ -1,44 +0,0 @@
1
- # Turf Ruby [![Build Status](https://travis-ci.com/formigarafa/turf-ruby.svg?branch=master)](https://travis-ci.com/formigarafa/turf-ruby)
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/turf`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'turf-ruby'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle install
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install turf-ruby
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` 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.
30
-
31
- 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).
32
-
33
- ## Contributing
34
-
35
- 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](https://github.com/formigarafa/turf-ruby/blob/master/CODE_OF_CONDUCT.md).
36
-
37
-
38
- ## License
39
-
40
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
41
-
42
- ## Code of Conduct
43
-
44
- Everyone interacting in the Turf Ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/formigarafa/turf-ruby/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile DELETED
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rake/testtask"
5
-
6
- Rake::TestTask.new(:test) do |t|
7
- t.libs << "test"
8
- t.libs << "lib"
9
- t.test_files = FileList["test/**/*_test.rb"]
10
- end
11
-
12
- task default: :test
data/bin/console DELETED
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "bundler/setup"
5
- require "turf_ruby"
6
-
7
- # You can add fixtures and/or initialization code here to make experimenting
8
- # with your gem easier. You can also use a different console, if you like.
9
-
10
- # (If you use this, don't forget to add pry to your Gemfile!)
11
- # require "pry"
12
- # Pry.start
13
-
14
- require "irb"
15
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
data/lib/turf/helper.rb DELETED
@@ -1,110 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Turf
4
- EARTH_RADIUS = 6_371_008.8
5
- FACTORS = {
6
- "centimeters" => EARTH_RADIUS * 100,
7
- "centimetres" => EARTH_RADIUS * 100,
8
- "degrees" => EARTH_RADIUS / 111_325,
9
- "feet" => EARTH_RADIUS * 3.28084,
10
- "inches" => EARTH_RADIUS * 39.370,
11
- "kilometers" => EARTH_RADIUS / 1000,
12
- "kilometres" => EARTH_RADIUS / 1000,
13
- "meters" => EARTH_RADIUS,
14
- "metres" => EARTH_RADIUS,
15
- "miles" => EARTH_RADIUS / 1609.344,
16
- "millimeters" => EARTH_RADIUS * 1000,
17
- "millimetres" => EARTH_RADIUS * 1000,
18
- "nauticalmiles" => EARTH_RADIUS / 1852,
19
- "radians" => 1,
20
- "yards" => EARTH_RADIUS / 1.0936
21
- }.freeze
22
-
23
- def self.feature(geom, properties = nil, options = {})
24
- feat = {
25
- type: "Feature",
26
- geometry: geom,
27
- properties: properties || {}
28
- }
29
- feat[:id] = options[:id] if options[:id]
30
-
31
- feat[:bbox] = options[:bbox] if options[:bbox]
32
-
33
- feat
34
- end
35
-
36
- def self.feature_collection(features, options = {})
37
- fc = { type: "FeatureCollection" }
38
- fc[:id] = options[:id] if options[:id]
39
- fc[:bbox] = options[:bbox] if options[:bbox]
40
- fc[:features] = features
41
-
42
- fc
43
- end
44
-
45
- def self.line_string(coordinates, properties = nil, options = {})
46
- if coordinates.size < 2
47
- raise Error, "coordinates must be an array of two or more positions"
48
- end
49
-
50
- geom = {
51
- type: "LineString",
52
- coordinates: coordinates
53
- }
54
- feature(geom, properties, options)
55
- end
56
-
57
- def self.point(coordinates, properties = nil, options = {})
58
- geom = {
59
- type: "Point",
60
- coordinates: coordinates
61
- }
62
- feature(geom, properties, options)
63
- end
64
-
65
- def self.polygon(coordinates, properties = nil, options = {})
66
- coordinates.each do |ring|
67
- if ring.size < 4
68
- raise(
69
- Error,
70
- "Each LinearRing of a Polygon must have 4 or more Positions.",
71
- )
72
- end
73
-
74
- ring.last.each_with_index do |number, idx|
75
- if ring.first[idx] != number
76
- raise Error, "First and last Position are not equivalent."
77
- end
78
- end
79
- end
80
- geom = {
81
- type: "Polygon",
82
- coordinates: coordinates
83
- }
84
- feature(geom, properties, options)
85
- end
86
-
87
- def self.radians_to_degrees(radians)
88
- degrees = radians.remainder(2 * Math::PI)
89
- degrees * 180 / Math::PI
90
- end
91
-
92
- def self.degrees_to_radians(degrees)
93
- radians = degrees.remainder(360)
94
- radians * Math::PI / 180
95
- end
96
-
97
- def self.radians_to_length(radians, units = "kilometers")
98
- factor = FACTORS[units]
99
- raise Error, "#{units} units is invalid" unless factor
100
-
101
- radians * factor
102
- end
103
-
104
- def self.length_to_radians(distance, units = "kilometers")
105
- factor = FACTORS[units]
106
- raise Error, "#{units} units is invalid" unless factor
107
-
108
- distance / factor
109
- end
110
- end
data/turf-ruby.gemspec DELETED
@@ -1,35 +0,0 @@
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 = ["santos@rafael.nz"]
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.3.0")
20
-
21
- spec.metadata["homepage_uri"] = spec.homepage
22
- spec.metadata["source_code_uri"] = spec.homepage
23
-
24
- # Specify which files should be added to the gem when it is released.
25
- # The `git ls-files -z` loads the files in the RubyGem that have been added
26
- # into git.
27
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
28
- `git ls-files -z`.split("\x0").reject do |f|
29
- f.match(%r{^(test|spec|features)/})
30
- end
31
- end
32
- spec.bindir = "exe"
33
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
- spec.require_paths = ["lib"]
35
- end