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.
- checksums.yaml +4 -4
- data/LICENSE.txt +21 -0
- data/README.md +159 -139
- 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 +8 -0
- data/lib/turf/boolean_concave.rb +8 -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 +8 -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 +105 -2
@@ -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
|
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
|
data/lib/turf/ellipse.rb
ADDED
data/lib/turf/explode.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "meta"
|
4
|
+
require_relative "helpers"
|
5
|
+
|
6
|
+
# :nodoc:
|
7
|
+
module Turf
|
8
|
+
def explode(geojson)
|
9
|
+
points = []
|
10
|
+
|
11
|
+
if geojson[:type] == "FeatureCollection"
|
12
|
+
feature_each(geojson) do |feature|
|
13
|
+
coord_each(feature) do |coord|
|
14
|
+
points << point(coord, feature[:properties])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
elsif geojson[:type] == "Feature"
|
18
|
+
coord_each(geojson) do |coord|
|
19
|
+
points << point(coord, geojson[:properties])
|
20
|
+
end
|
21
|
+
else
|
22
|
+
coord_each(geojson) do |coord|
|
23
|
+
points << point(coord)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
feature_collection(points)
|
28
|
+
end
|
29
|
+
end
|
data/lib/turf/flatten.rb
ADDED
data/lib/turf/flip.rb
ADDED