ffi-geos 2.3.1 → 2.5.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/.github/workflows/main.yml +2 -2
- data/.rbenv-vars +1 -0
- data/.rubocop-minitest.yml +40 -17
- data/.rubocop.yml +664 -120
- data/.rubocop_todo.yml +30 -19
- data/MIT-LICENSE +1 -1
- data/README.rdoc +2 -0
- data/ffi-geos.gemspec +2 -2
- data/lib/ffi-geos/coordinate_sequence.rb +2 -1
- data/lib/ffi-geos/geojson_reader.rb +35 -0
- data/lib/ffi-geos/geojson_writer.rb +49 -0
- data/lib/ffi-geos/geometry.rb +101 -1
- data/lib/ffi-geos/geometry_collection.rb +1 -1
- data/lib/ffi-geos/line_string.rb +1 -1
- data/lib/ffi-geos/point.rb +9 -0
- data/lib/ffi-geos/polygon.rb +1 -1
- data/lib/ffi-geos/prepared_geometry.rb +20 -0
- data/lib/ffi-geos/version.rb +1 -1
- data/lib/ffi-geos/wkb_writer.rb +12 -0
- data/lib/ffi-geos.rb +156 -3
- data/test/coordinate_sequence_tests.rb +22 -4
- data/test/geojson_reader_tests.rb +174 -0
- data/test/geojson_writer_tests.rb +103 -0
- data/test/geometry/area_tests.rb +18 -0
- data/test/geometry/boundary_tests.rb +36 -0
- data/test/geometry/buffer_tests.rb +116 -0
- data/test/geometry/build_area_tests.rb +20 -0
- data/test/geometry/centroid_tests.rb +37 -0
- data/test/geometry/clip_by_rect_tests.rb +56 -0
- data/test/geometry/clone_tests.rb +29 -0
- data/test/geometry/concave_hull_of_polygons_tests.rb +28 -0
- data/test/geometry/concave_hull_tests.rb +38 -0
- data/test/geometry/convex_hull_tests.rb +26 -0
- data/test/geometry/coord_seq_tests.rb +27 -0
- data/test/geometry/delaunay_triangulation_tests.rb +82 -0
- data/test/geometry/densify_tests.rb +95 -0
- data/test/geometry/difference_tests.rb +108 -0
- data/test/geometry/dimensions_tests.rb +46 -0
- data/test/geometry/distance_tests.rb +29 -0
- data/test/geometry/dump_points_tests.rb +60 -0
- data/test/geometry/dup_tests.rb +29 -0
- data/test/geometry/empty_tests.rb +23 -0
- data/test/geometry/envelope_tests.rb +26 -0
- data/test/geometry/equal_identical_tests.rb +78 -0
- data/test/geometry/equal_tests.rb +62 -0
- data/test/geometry/exterior_ring_tests.rb +27 -0
- data/test/geometry/extract_unique_points_tests.rb +41 -0
- data/test/geometry/frecet_distance_tests.rb +24 -0
- data/test/geometry/get_geometry_n_tests.rb +21 -0
- data/test/geometry/hausdorff_distance_tests.rb +46 -0
- data/test/geometry/hilbert_code_tests.rb +45 -0
- data/test/geometry/interior_ring_n_tests.rb +64 -0
- data/test/geometry/interior_rings_tests.rb +36 -0
- data/test/geometry/interpolate_tests.rb +49 -0
- data/test/geometry/intersection_tests.rb +49 -0
- data/test/geometry/largest_empty_circle_tests.rb +26 -0
- data/test/geometry/length_tests.rb +18 -0
- data/test/geometry/line_merge_directed_tests.rb +28 -0
- data/test/geometry/line_merge_tests.rb +25 -0
- data/test/geometry/line_string_enumerator_tests.rb +20 -0
- data/test/geometry/line_substring_tests.rb +76 -0
- data/test/geometry/make_valid_tests.rb +27 -0
- data/test/geometry/maximum_inscribed_circle_tests.rb +21 -0
- data/test/geometry/minimum_bounding_circle_tests.rb +23 -0
- data/test/geometry/minimum_clearance_tests.rb +58 -0
- data/test/geometry/minimum_rotated_rectangle_tests.rb +28 -0
- data/test/geometry/minimum_width_tests.rb +26 -0
- data/test/geometry/misc_tests.rb +24 -0
- data/test/geometry/nearest_points_tests.rb +46 -0
- data/test/geometry/node_tests.rb +22 -0
- data/test/geometry/normalize_tests.rb +34 -0
- data/test/geometry/num_coordinates_tests.rb +39 -0
- data/test/geometry/num_goemetries_tests.rb +35 -0
- data/test/geometry/num_interior_rings_tests.rb +28 -0
- data/test/geometry/orient_polygons_tests.rb +101 -0
- data/test/geometry/point_on_surface_tests.rb +37 -0
- data/test/geometry/polygon_hull_simplify_tests.rb +55 -0
- data/test/geometry/polygonize_tests.rb +173 -0
- data/test/geometry/precision_tests.rb +42 -0
- data/test/geometry/project_tests.rb +56 -0
- data/test/geometry/relate_tests.rb +73 -0
- data/test/geometry/relationships_tests.rb +138 -0
- data/test/geometry/reverse_tests.rb +44 -0
- data/test/geometry/ring_tests.rb +18 -0
- data/test/geometry/shared_path_tests.rb +31 -0
- data/test/geometry/simple_tests.rb +18 -0
- data/test/geometry/simplify_tests.rb +21 -0
- data/test/geometry/snap_tests.rb +20 -0
- data/test/geometry/srid_copy_policy_tests.rb +94 -0
- data/test/geometry/start_and_end_point_tests.rb +24 -0
- data/test/geometry/sym_difference_tests.rb +114 -0
- data/test/geometry/topology_preserve_simplify_tests.rb +21 -0
- data/test/geometry/union_tests.rb +216 -0
- data/test/geometry/valid_tests.rb +56 -0
- data/test/geometry/voronoi_diagram_tests.rb +62 -0
- data/test/geometry_collection_tests.rb +14 -2
- data/test/interrupt_tests.rb +1 -1
- data/test/line_string_tests.rb +24 -3
- data/test/misc_tests.rb +1 -1
- data/test/point/has_m_tests.rb +43 -0
- data/test/point/x_y_z_m_tests.rb +51 -0
- data/test/point_tests.rb +25 -3
- data/test/polygon_tests.rb +14 -1
- data/test/prepared_geometry_tests.rb +31 -0
- data/test/strtree_tests.rb +11 -18
- data/test/test_helper.rb +2 -0
- data/test/tools_tests.rb +7 -0
- data/test/utils_tests.rb +14 -3
- data/test/wkb_reader_tests.rb +1 -0
- data/test/wkb_writer_tests.rb +46 -5
- data/test/wkt_reader_tests.rb +2 -0
- data/test/wkt_writer_tests.rb +20 -2
- metadata +160 -7
- data/test/geometry_tests.rb +0 -2096
data/test/point_tests.rb
CHANGED
@@ -12,30 +12,36 @@ class PointTests < Minitest::Test
|
|
12
12
|
|
13
13
|
def test_default_srid
|
14
14
|
geom = read('POINT(0 0)')
|
15
|
+
|
15
16
|
assert_equal(0, geom.srid)
|
16
17
|
end
|
17
18
|
|
18
19
|
def test_setting_srid_manually
|
19
20
|
geom = read('POINT(0 0)')
|
20
21
|
geom.srid = 4326
|
22
|
+
|
21
23
|
assert_equal(4326, geom.srid)
|
22
24
|
end
|
23
25
|
|
24
26
|
def test_dimensions
|
25
27
|
geom = read('POINT(1 2)')
|
28
|
+
|
26
29
|
assert_equal(0, geom.dimensions)
|
27
30
|
|
28
31
|
geom = read('POINT(1 2 3)')
|
32
|
+
|
29
33
|
assert_equal(0, geom.dimensions)
|
30
34
|
end
|
31
35
|
|
32
36
|
def test_num_geometries
|
33
37
|
geom = read('POINT(1 2)')
|
38
|
+
|
34
39
|
assert_equal(1, geom.num_geometries)
|
35
40
|
end
|
36
41
|
|
37
42
|
def test_get_x
|
38
43
|
geom = read('POINT (1 2)')
|
44
|
+
|
39
45
|
assert_equal(1, geom.get_x)
|
40
46
|
assert_equal(1, geom.x)
|
41
47
|
|
@@ -46,6 +52,7 @@ class PointTests < Minitest::Test
|
|
46
52
|
|
47
53
|
def test_get_y
|
48
54
|
geom = read('POINT (1 2)')
|
55
|
+
|
49
56
|
assert_equal(2, geom.get_y)
|
50
57
|
assert_equal(2, geom.y)
|
51
58
|
|
@@ -56,6 +63,7 @@ class PointTests < Minitest::Test
|
|
56
63
|
|
57
64
|
def test_get_z
|
58
65
|
geom = read('POINT Z (1 2 3)')
|
66
|
+
|
59
67
|
assert_equal(3, geom.get_z)
|
60
68
|
assert_equal(3, geom.z)
|
61
69
|
assert_raises(NoMethodError) do
|
@@ -68,12 +76,15 @@ class PointTests < Minitest::Test
|
|
68
76
|
geom.srid = 4326
|
69
77
|
|
70
78
|
Geos.srid_copy_policy = :zero
|
79
|
+
|
71
80
|
assert_equal(0, geom.simplify(0.1).srid)
|
72
81
|
|
73
82
|
Geos.srid_copy_policy = :lenient
|
83
|
+
|
74
84
|
assert_equal(4326, geom.simplify(0.1).srid)
|
75
85
|
|
76
86
|
Geos.srid_copy_policy = :strict
|
87
|
+
|
77
88
|
assert_equal(4326, geom.simplify(0.1).srid)
|
78
89
|
ensure
|
79
90
|
Geos.srid_copy_policy = :default
|
@@ -84,12 +95,15 @@ class PointTests < Minitest::Test
|
|
84
95
|
geom.srid = 4326
|
85
96
|
|
86
97
|
Geos.srid_copy_policy = :zero
|
98
|
+
|
87
99
|
assert_equal(0, geom.extract_unique_points.srid)
|
88
100
|
|
89
101
|
Geos.srid_copy_policy = :lenient
|
102
|
+
|
90
103
|
assert_equal(4326, geom.extract_unique_points.srid)
|
91
104
|
|
92
105
|
Geos.srid_copy_policy = :strict
|
106
|
+
|
93
107
|
assert_equal(4326, geom.extract_unique_points.srid)
|
94
108
|
ensure
|
95
109
|
Geos.srid_copy_policy = :default
|
@@ -98,43 +112,51 @@ class PointTests < Minitest::Test
|
|
98
112
|
def test_normalize
|
99
113
|
geom = read('POINT(10 10)')
|
100
114
|
|
101
|
-
|
102
|
-
|
115
|
+
assert_same(geom, geom.normalize)
|
116
|
+
assert_same(geom, geom.normalize!)
|
103
117
|
end
|
104
118
|
|
105
119
|
def test_x_max
|
106
120
|
geom = read('POINT (-10 -15)')
|
121
|
+
|
107
122
|
assert_equal(-10, geom.x_max)
|
108
123
|
end
|
109
124
|
|
110
125
|
def test_x_min
|
111
126
|
geom = read('POINT (-10 -15)')
|
127
|
+
|
112
128
|
assert_equal(-10, geom.x_min)
|
113
129
|
end
|
114
130
|
|
115
131
|
def test_y_max
|
116
132
|
geom = read('POINT (-10 -15)')
|
133
|
+
|
117
134
|
assert_equal(-15, geom.y_max)
|
118
135
|
end
|
119
136
|
|
120
137
|
def test_y_min
|
121
138
|
geom = read('POINT (-10 -15)')
|
139
|
+
|
122
140
|
assert_equal(-15, geom.y_min)
|
123
141
|
end
|
124
142
|
|
125
143
|
def test_z_max
|
126
144
|
geom = read('POINT (-10 -15)')
|
145
|
+
|
127
146
|
assert_equal(0, geom.z_max)
|
128
147
|
|
129
148
|
geom = read('POINT Z (-10 -15 -20)')
|
149
|
+
|
130
150
|
assert_equal(-20, geom.z_max)
|
131
151
|
end
|
132
152
|
|
133
153
|
def test_z_min
|
134
154
|
geom = read('POINT (-10 -15)')
|
155
|
+
|
135
156
|
assert_equal(0, geom.z_min)
|
136
157
|
|
137
158
|
geom = read('POINT Z (-10 -15 -20)')
|
159
|
+
|
138
160
|
assert_equal(-20, geom.z_min)
|
139
161
|
end
|
140
162
|
|
@@ -146,7 +168,7 @@ class PointTests < Minitest::Test
|
|
146
168
|
end
|
147
169
|
|
148
170
|
def test_snap_to_grid_empty
|
149
|
-
|
171
|
+
assert_empty(read('POINT EMPTY').snap_to_grid!, 'Expected an empty Point')
|
150
172
|
end
|
151
173
|
|
152
174
|
def test_snap_to_grid_with_srid
|
data/test/polygon_tests.rb
CHANGED
@@ -12,61 +12,74 @@ class PolygonTests < Minitest::Test
|
|
12
12
|
|
13
13
|
def test_default_srid
|
14
14
|
geom = read('POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0))')
|
15
|
+
|
15
16
|
assert_equal(0, geom.srid)
|
16
17
|
end
|
17
18
|
|
18
19
|
def test_setting_srid_manually
|
19
20
|
geom = read('POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0))')
|
20
21
|
geom.srid = 4326
|
22
|
+
|
21
23
|
assert_equal(4326, geom.srid)
|
22
24
|
end
|
23
25
|
|
24
26
|
def test_dimensions
|
25
27
|
geom = read('POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0))')
|
28
|
+
|
26
29
|
assert_equal(2, geom.dimensions)
|
27
30
|
|
28
31
|
geom = read('POLYGON ((0 0 0, 5 0 0, 5 5 0, 0 5 0, 0 0 0))')
|
32
|
+
|
29
33
|
assert_equal(2, geom.dimensions)
|
30
34
|
end
|
31
35
|
|
32
36
|
def test_num_geometries
|
33
37
|
geom = read('POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0))')
|
38
|
+
|
34
39
|
assert_equal(1, geom.num_geometries)
|
35
40
|
end
|
36
41
|
|
37
42
|
def test_x_max
|
38
43
|
geom = read('POLYGON ((0 0, 5 0, 8 9, -10 5, 0 0))')
|
44
|
+
|
39
45
|
assert_equal(8, geom.x_max)
|
40
46
|
end
|
41
47
|
|
42
48
|
def test_x_min
|
43
49
|
geom = read('POLYGON ((0 0, 5 0, 8 9, -10 5, 0 0))')
|
50
|
+
|
44
51
|
assert_equal(-10, geom.x_min)
|
45
52
|
end
|
46
53
|
|
47
54
|
def test_y_max
|
48
55
|
geom = read('POLYGON ((0 0, 5 0, 8 9, -10 5, 0 0))')
|
56
|
+
|
49
57
|
assert_equal(9, geom.y_max)
|
50
58
|
end
|
51
59
|
|
52
60
|
def test_y_min
|
53
61
|
geom = read('POLYGON ((0 0, 5 0, 8 9, -10 5, 0 0))')
|
62
|
+
|
54
63
|
assert_equal(0, geom.y_min)
|
55
64
|
end
|
56
65
|
|
57
66
|
def test_z_max
|
58
67
|
geom = read('POLYGON ((0 0, 5 0, 8 9, -10 5, 0 0))')
|
68
|
+
|
59
69
|
assert_equal(0, geom.z_min)
|
60
70
|
|
61
71
|
geom = read('POLYGON Z ((0 0 0, 5 0 3, 8 9 4, -10 5 3, 0 0 0))')
|
72
|
+
|
62
73
|
assert_equal(4, geom.z_max)
|
63
74
|
end
|
64
75
|
|
65
76
|
def test_z_min
|
66
77
|
geom = read('POLYGON ((0 0, 5 0, 8 9, -10 5, 0 0))')
|
78
|
+
|
67
79
|
assert_equal(0, geom.z_min)
|
68
80
|
|
69
81
|
geom = read('POLYGON Z ((0 0 0, 5 0 3, 8 9 4, -10 5 3, 0 0 0))')
|
82
|
+
|
70
83
|
assert_equal(0, geom.z_min)
|
71
84
|
end
|
72
85
|
|
@@ -84,7 +97,7 @@ class PolygonTests < Minitest::Test
|
|
84
97
|
end
|
85
98
|
|
86
99
|
def test_snap_to_grid_empty
|
87
|
-
|
100
|
+
assert_empty(read('POLYGON EMPTY').snap_to_grid!, 'Expected an empty Polygon')
|
88
101
|
end
|
89
102
|
|
90
103
|
def test_snap_to_grid_collapse_holes
|
@@ -30,6 +30,7 @@ class PreparedGeometryTests < Minitest::Test
|
|
30
30
|
geom_b = read(geom_b)
|
31
31
|
|
32
32
|
value = geom_a.send(method, geom_b)
|
33
|
+
|
33
34
|
assert_equal(expected[i], value)
|
34
35
|
end
|
35
36
|
end
|
@@ -70,6 +71,12 @@ class PreparedGeometryTests < Minitest::Test
|
|
70
71
|
relationship_tester(:contains?, true, false, false, false, false, true, false, false)
|
71
72
|
end
|
72
73
|
|
74
|
+
def test_contains_properly
|
75
|
+
skip unless ENV['FORCE_TESTS'] || defined?(Geos::PreparedGeometry)
|
76
|
+
|
77
|
+
relationship_tester(:contains_properly?, true, false, false, false, false, false, false, false)
|
78
|
+
end
|
79
|
+
|
73
80
|
def test_overlaps
|
74
81
|
skip unless ENV['FORCE_TESTS'] || defined?(Geos::PreparedGeometry)
|
75
82
|
|
@@ -111,4 +118,28 @@ class PreparedGeometryTests < Minitest::Test
|
|
111
118
|
Geos::PreparedGeometry.new('hello world')
|
112
119
|
end
|
113
120
|
end
|
121
|
+
|
122
|
+
def test_distance
|
123
|
+
skip unless ENV['FORCE_TESTS'] || (defined?(Geos::PreparedGeometry) && Geos::FFIGeos.respond_to?(:GEOSPreparedDistance_r))
|
124
|
+
|
125
|
+
assert_in_delta(5.0, read(POINT_A).to_prepared.distance(read(POINT_B)))
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_distance_within
|
129
|
+
skip unless ENV['FORCE_TESTS'] || (defined?(Geos::PreparedGeometry) && Geos::FFIGeos.respond_to?(:GEOSPreparedDistanceWithin_r))
|
130
|
+
|
131
|
+
assert(read(POINT_A).to_prepared.distance_within?(read(POINT_B), 30.0))
|
132
|
+
refute(read(POINT_A).to_prepared.distance_within?(read(POINT_B), 3.0))
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_nearest_points
|
136
|
+
skip unless ENV['FORCE_TESTS'] || (defined?(Geos::PreparedGeometry) && Geos::FFIGeos.respond_to?(:GEOSPreparedNearestPoints_r))
|
137
|
+
|
138
|
+
coord_seq = read('POLYGON((1 1, 1 5, 5 5, 5 1, 1 1))').to_prepared.nearest_points(read('POLYGON((8 8, 9 9, 9 10, 8 8))'))
|
139
|
+
|
140
|
+
assert_in_delta(5.0, coord_seq.x[0])
|
141
|
+
assert_in_delta(5.0, coord_seq.y[0])
|
142
|
+
assert_in_delta(8.0, coord_seq.x[1])
|
143
|
+
assert_in_delta(8.0, coord_seq.y[1])
|
144
|
+
end
|
114
145
|
end
|
data/test/strtree_tests.rb
CHANGED
@@ -40,8 +40,7 @@ class STRtreeTests < Minitest::Test
|
|
40
40
|
assert_equal([@item_1],
|
41
41
|
@tree.query(read('LINESTRING(5 5, 6 6)')))
|
42
42
|
|
43
|
-
|
44
|
-
@tree.query(read('LINESTRING(20 0, 30 10)')))
|
43
|
+
assert_empty(@tree.query(read('LINESTRING(20 0, 30 10)')))
|
45
44
|
|
46
45
|
assert_equal([@item_2, @item_3],
|
47
46
|
@tree.query(read('LINESTRING(25 25, 26 26)')))
|
@@ -58,8 +57,7 @@ class STRtreeTests < Minitest::Test
|
|
58
57
|
assert_equal([@item_1],
|
59
58
|
@tree.query(read('LINESTRING(5 5, 6 6)'), :item))
|
60
59
|
|
61
|
-
|
62
|
-
@tree.query(read('LINESTRING(20 0, 30 10)'), :item))
|
60
|
+
assert_empty(@tree.query(read('LINESTRING(20 0, 30 10)'), :item))
|
63
61
|
|
64
62
|
assert_equal([@item_2, @item_3],
|
65
63
|
@tree.query(read('LINESTRING(25 25, 26 26)'), :item))
|
@@ -70,8 +68,7 @@ class STRtreeTests < Minitest::Test
|
|
70
68
|
assert_equal([@geom_1],
|
71
69
|
@tree.query(read('LINESTRING(5 5, 6 6)'), :geometry))
|
72
70
|
|
73
|
-
|
74
|
-
@tree.query(read('LINESTRING(20 0, 30 10)'), :geometry))
|
71
|
+
assert_empty(@tree.query(read('LINESTRING(20 0, 30 10)'), :geometry))
|
75
72
|
|
76
73
|
assert_equal([@geom_2, @geom_3],
|
77
74
|
@tree.query(read('LINESTRING(25 25, 26 26)'), :geometry))
|
@@ -86,8 +83,7 @@ class STRtreeTests < Minitest::Test
|
|
86
83
|
@tree.query(read('LINESTRING(5 5, 6 6)'), :all)
|
87
84
|
)
|
88
85
|
|
89
|
-
|
90
|
-
@tree.query(read('LINESTRING(20 0, 30 10)'), :all))
|
86
|
+
assert_empty(@tree.query(read('LINESTRING(20 0, 30 10)'), :all))
|
91
87
|
|
92
88
|
assert_equal(
|
93
89
|
[
|
@@ -115,8 +111,7 @@ class STRtreeTests < Minitest::Test
|
|
115
111
|
assert_equal([@item_1],
|
116
112
|
@tree.query_all(read('LINESTRING(5 5, 6 6)')).collect { |v| v[:item] })
|
117
113
|
|
118
|
-
|
119
|
-
@tree.query_all(read('LINESTRING(20 0, 30 10)')))
|
114
|
+
assert_empty(@tree.query_all(read('LINESTRING(20 0, 30 10)')))
|
120
115
|
|
121
116
|
assert_equal([@item_2, @item_3],
|
122
117
|
@tree.query_all(read('LINESTRING(25 25, 26 26)')).collect { |v| v[:item] })
|
@@ -133,8 +128,7 @@ class STRtreeTests < Minitest::Test
|
|
133
128
|
assert_equal([@geom_1],
|
134
129
|
@tree.query_geometries(read('LINESTRING(5 5, 6 6)')))
|
135
130
|
|
136
|
-
|
137
|
-
@tree.query_geometries(read('LINESTRING(20 0, 30 10)')))
|
131
|
+
assert_empty(@tree.query_geometries(read('LINESTRING(20 0, 30 10)')))
|
138
132
|
|
139
133
|
assert_equal([@geom_2, @geom_3],
|
140
134
|
@tree.query_geometries(read('LINESTRING(25 25, 26 26)')))
|
@@ -150,11 +144,9 @@ class STRtreeTests < Minitest::Test
|
|
150
144
|
|
151
145
|
@tree.remove(read('POINT(5 5)'), @item_1)
|
152
146
|
|
153
|
-
|
154
|
-
@tree.query(read('LINESTRING(5 5, 6 6)')))
|
147
|
+
assert_empty(@tree.query(read('LINESTRING(5 5, 6 6)')))
|
155
148
|
|
156
|
-
|
157
|
-
@tree.query(read('LINESTRING(20 0, 30 10)')))
|
149
|
+
assert_empty(@tree.query(read('LINESTRING(20 0, 30 10)')))
|
158
150
|
|
159
151
|
assert_equal([@item_2, @item_3],
|
160
152
|
@tree.query(read('LINESTRING(25 25, 26 26)')))
|
@@ -191,8 +183,7 @@ class STRtreeTests < Minitest::Test
|
|
191
183
|
assert_equal([item_1],
|
192
184
|
tree.query(read('LINESTRING(5 5, 6 6)')))
|
193
185
|
|
194
|
-
|
195
|
-
tree.query(read('LINESTRING(20 0, 30 10)')))
|
186
|
+
assert_empty(tree.query(read('LINESTRING(20 0, 30 10)')))
|
196
187
|
|
197
188
|
assert_equal([item_2, item_3],
|
198
189
|
tree.query(read('LINESTRING(25 25, 26 26)')))
|
@@ -246,6 +237,7 @@ class STRtreeTests < Minitest::Test
|
|
246
237
|
tree.insert(geom_3)
|
247
238
|
|
248
239
|
nearest_geom = tree.nearest(geom_4)
|
240
|
+
|
249
241
|
assert_equal(write(geom_2), write(nearest_geom))
|
250
242
|
end
|
251
243
|
|
@@ -356,6 +348,7 @@ class STRtreeTests < Minitest::Test
|
|
356
348
|
tree.insert(geom_3, item_3)
|
357
349
|
|
358
350
|
nearest_item = tree.nearest_item(geom_4)
|
351
|
+
|
359
352
|
assert_equal(item_2, nearest_item)
|
360
353
|
end
|
361
354
|
end
|
data/test/test_helper.rb
CHANGED
@@ -90,6 +90,7 @@ module TestHelper
|
|
90
90
|
Geos.srid_copy_policy = srid_policy
|
91
91
|
|
92
92
|
geom_b = geom.__safe_send__(method, *args, **options)
|
93
|
+
|
93
94
|
assert_equal(4326, geom.srid)
|
94
95
|
assert_equal(expected_srid, geom_b.srid)
|
95
96
|
assert_equal(expected, write(geom_b))
|
@@ -124,6 +125,7 @@ module TestHelper
|
|
124
125
|
geom = geom_from_geom_or_wkt(geom)
|
125
126
|
|
126
127
|
result = geom.__safe_send__(method, *args, **options)
|
128
|
+
|
127
129
|
assert_equal(expected, write(result.snap_to_grid(1)))
|
128
130
|
end
|
129
131
|
|
data/test/tools_tests.rb
CHANGED
@@ -31,12 +31,15 @@ class ToolsTests < Minitest::Test
|
|
31
31
|
|
32
32
|
def test_pick_srid_from_geoms
|
33
33
|
Geos.srid_copy_policy = :default
|
34
|
+
|
34
35
|
assert_equal(0, Geos::Tools.pick_srid_from_geoms(4326, 4269))
|
35
36
|
|
36
37
|
Geos.srid_copy_policy = :zero
|
38
|
+
|
37
39
|
assert_equal(0, Geos::Tools.pick_srid_from_geoms(4326, 4269))
|
38
40
|
|
39
41
|
Geos.srid_copy_policy = :lenient
|
42
|
+
|
40
43
|
assert_equal(4326, Geos::Tools.pick_srid_from_geoms(4326, 4269))
|
41
44
|
|
42
45
|
Geos.srid_copy_policy = :strict
|
@@ -63,15 +66,19 @@ class ToolsTests < Minitest::Test
|
|
63
66
|
|
64
67
|
def test_pick_srid_according_to_policy
|
65
68
|
Geos.srid_copy_policy = :default
|
69
|
+
|
66
70
|
assert_equal(0, Geos::Tools.pick_srid_according_to_policy(4326))
|
67
71
|
|
68
72
|
Geos.srid_copy_policy = :zero
|
73
|
+
|
69
74
|
assert_equal(0, Geos::Tools.pick_srid_according_to_policy(4326))
|
70
75
|
|
71
76
|
Geos.srid_copy_policy = :lenient
|
77
|
+
|
72
78
|
assert_equal(4326, Geos::Tools.pick_srid_according_to_policy(4326))
|
73
79
|
|
74
80
|
Geos.srid_copy_policy = :strict
|
81
|
+
|
75
82
|
assert_equal(4326, Geos::Tools.pick_srid_according_to_policy(4326))
|
76
83
|
ensure
|
77
84
|
Geos.srid_copy_policy = :default
|
data/test/utils_tests.rb
CHANGED
@@ -32,7 +32,7 @@ class UtilsTests < Minitest::Test
|
|
32
32
|
assert(Geos::Utils.relate_match('0FFFFFFF2', '0FFFFFFF2'), "'0FFFFFFF2' and '0FFFFFFF2' patterns match")
|
33
33
|
assert(Geos::Utils.relate_match('0FFFFFFF2', '0FFFFFFF*'), "'0FFFFFFF2' and '0FFFFFFF*' patterns match")
|
34
34
|
assert(Geos::Utils.relate_match('0FFFFFFF2', 'TFFFFFFF2'), "'0FFFFFFF2' and 'TFFFFFFF2' patterns match")
|
35
|
-
|
35
|
+
refute(Geos::Utils.relate_match('0FFFFFFF2', '0FFFFFFFF'), "'0FFFFFFF2' and '0FFFFFFFF' patterns match")
|
36
36
|
end
|
37
37
|
|
38
38
|
def create_method_tester(expected, method, cs, type_id, klass)
|
@@ -188,6 +188,7 @@ class UtilsTests < Minitest::Test
|
|
188
188
|
exterior_ring = Geos.create_linear_ring(cs)
|
189
189
|
|
190
190
|
geom = Geos.create_polygon(exterior_ring)
|
191
|
+
|
191
192
|
assert_instance_of(Geos::Polygon, geom)
|
192
193
|
assert_equal('Polygon', geom.geom_type)
|
193
194
|
assert_equal(Geos::GEOS_POLYGON, geom.type_id)
|
@@ -212,6 +213,7 @@ class UtilsTests < Minitest::Test
|
|
212
213
|
)
|
213
214
|
|
214
215
|
geom = Geos.create_polygon(outer, inner)
|
216
|
+
|
215
217
|
assert_instance_of(Geos::Polygon, geom)
|
216
218
|
assert_equal('Polygon', geom.geom_type)
|
217
219
|
assert_equal(Geos::GEOS_POLYGON, geom.type_id)
|
@@ -244,6 +246,7 @@ class UtilsTests < Minitest::Test
|
|
244
246
|
)
|
245
247
|
|
246
248
|
geom = Geos.create_polygon(exterior_ring, [hole_1, hole_2])
|
249
|
+
|
247
250
|
assert_instance_of(Geos::Polygon, geom)
|
248
251
|
assert_equal('Polygon', geom.geom_type)
|
249
252
|
assert_equal(Geos::GEOS_POLYGON, geom.type_id)
|
@@ -261,13 +264,20 @@ class UtilsTests < Minitest::Test
|
|
261
264
|
skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_multi_point)
|
262
265
|
|
263
266
|
assert_equal('MULTIPOINT EMPTY', write(Geos.create_multi_point))
|
264
|
-
|
267
|
+
|
268
|
+
assert_equal(
|
269
|
+
if Geos::GEOS_NICE_VERSION >= '031200'
|
270
|
+
'MULTIPOINT ((0 0), (10 10))'
|
271
|
+
else
|
272
|
+
'MULTIPOINT (0 0, 10 10)'
|
273
|
+
end,
|
265
274
|
write(
|
266
275
|
Geos.create_multi_point(
|
267
276
|
read('POINT(0 0)'),
|
268
277
|
read('POINT(10 10)')
|
269
278
|
)
|
270
|
-
)
|
279
|
+
)
|
280
|
+
)
|
271
281
|
end
|
272
282
|
|
273
283
|
def test_create_bad_multi_point
|
@@ -451,6 +461,7 @@ class UtilsTests < Minitest::Test
|
|
451
461
|
])
|
452
462
|
|
453
463
|
Geos.create_linear_ring(cs)
|
464
|
+
|
454
465
|
GC.start
|
455
466
|
end
|
456
467
|
end
|
data/test/wkb_reader_tests.rb
CHANGED
data/test/wkb_writer_tests.rb
CHANGED
@@ -433,12 +433,20 @@ class WkbWriterTests < Minitest::Test
|
|
433
433
|
}
|
434
434
|
|
435
435
|
tester[
|
436
|
-
|
436
|
+
if Geos::GEOS_NICE_VERSION >= '031200'
|
437
|
+
[1, 1, 0, 0, 160, 230, 16, 0, 0, 0, 0, 0, 0, 0, 0, 240, 63, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 8, 64].pack('C*')
|
438
|
+
else
|
439
|
+
[1, 1, 0, 0, 32, 230, 16, 0, 0, 0, 0, 0, 0, 0, 0, 240, 63, 0, 0, 0, 0, 0, 0, 0, 64].pack('C*')
|
440
|
+
end,
|
437
441
|
include_srid: true
|
438
442
|
]
|
439
443
|
|
440
444
|
tester[
|
441
|
-
|
445
|
+
if Geos::GEOS_NICE_VERSION >= '031200'
|
446
|
+
[1, 1, 0, 0, 128, 0, 0, 0, 0, 0, 0, 240, 63, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 8, 64].pack('C*')
|
447
|
+
else
|
448
|
+
[1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240, 63, 0, 0, 0, 0, 0, 0, 0, 64].pack('C*')
|
449
|
+
end
|
442
450
|
]
|
443
451
|
end
|
444
452
|
|
@@ -448,13 +456,26 @@ class WkbWriterTests < Minitest::Test
|
|
448
456
|
geom = read('POINT(1 2 3)')
|
449
457
|
geom.srid = 4326
|
450
458
|
|
451
|
-
assert_equal(
|
459
|
+
assert_equal(
|
460
|
+
if Geos::GEOS_NICE_VERSION >= '031200'
|
461
|
+
'01010000A0E6100000000000000000F03F00000000000000400000000000000840'
|
462
|
+
else
|
463
|
+
'0101000020E6100000000000000000F03F0000000000000040'
|
464
|
+
end,
|
452
465
|
@wkb_writer.write_hex(
|
453
466
|
geom,
|
454
467
|
include_srid: true
|
455
|
-
)
|
468
|
+
)
|
469
|
+
)
|
456
470
|
|
457
|
-
assert_equal(
|
471
|
+
assert_equal(
|
472
|
+
if Geos::GEOS_NICE_VERSION >= '031200'
|
473
|
+
'0101000080000000000000F03F00000000000000400000000000000840'
|
474
|
+
else
|
475
|
+
'0101000000000000000000F03F0000000000000040'
|
476
|
+
end,
|
477
|
+
@wkb_writer.write_hex(geom)
|
478
|
+
)
|
458
479
|
end
|
459
480
|
|
460
481
|
def test_illegal_output_dimensions
|
@@ -466,4 +487,24 @@ class WkbWriterTests < Minitest::Test
|
|
466
487
|
@wkb_writer.output_dimensions = 0
|
467
488
|
end
|
468
489
|
end
|
490
|
+
|
491
|
+
def test_wkb_flavor_extended
|
492
|
+
skip unless ENV['FORCE_TESTS'] || Geos::FFIGeos.respond_to?(:GEOSWKBWriter_setFlavor_r)
|
493
|
+
|
494
|
+
@wkb_writer.output_dimensions = 3
|
495
|
+
@wkb_writer.flavor = :extended
|
496
|
+
|
497
|
+
assert_equal('010200008003000000000000000000F03F000000000000004000000000000008400000000000001040000000000000144000000000000018400000000000001C4000000000000020400000000000002240',
|
498
|
+
@wkb_writer.write_hex(read('LINESTRING Z (1 2 3, 4 5 6, 7 8 9)')))
|
499
|
+
end
|
500
|
+
|
501
|
+
def test_wkb_flavor_iso
|
502
|
+
skip unless ENV['FORCE_TESTS'] || Geos::FFIGeos.respond_to?(:GEOSWKBWriter_setFlavor_r)
|
503
|
+
|
504
|
+
@wkb_writer.output_dimensions = 3
|
505
|
+
@wkb_writer.flavor = :iso
|
506
|
+
|
507
|
+
assert_equal('01EA03000003000000000000000000F03F000000000000004000000000000008400000000000001040000000000000144000000000000018400000000000001C4000000000000020400000000000002240',
|
508
|
+
@wkb_writer.write_hex(read('LINESTRING Z (1 2 3, 4 5 6, 7 8 9)')))
|
509
|
+
end
|
469
510
|
end
|
data/test/wkt_reader_tests.rb
CHANGED
@@ -8,6 +8,7 @@ class WktReaderTests < Minitest::Test
|
|
8
8
|
def wkt_tester(type_id, geom_type, klass, *geoms)
|
9
9
|
geoms.each do |g|
|
10
10
|
geom = read(g)
|
11
|
+
|
11
12
|
refute_nil(geom)
|
12
13
|
assert_equal(type_id, geom.type_id)
|
13
14
|
assert_equal(geom_type, geom.geom_type)
|
@@ -106,6 +107,7 @@ class WktReaderTests < Minitest::Test
|
|
106
107
|
|
107
108
|
def test_read_linearring
|
108
109
|
geom = read('LINEARRING(0 0, 1 1, 2 2, 3 3, 0 0)')
|
110
|
+
|
109
111
|
assert_equal(Geos::GEOS_LINEARRING, geom.type_id)
|
110
112
|
assert_equal('LinearRing', geom.geom_type)
|
111
113
|
assert_kind_of(Geos::LinearRing, geom)
|
data/test/wkt_writer_tests.rb
CHANGED
@@ -21,9 +21,11 @@ class WktWriterTests < Minitest::Test
|
|
21
21
|
geom = read('POINT(6 7)')
|
22
22
|
|
23
23
|
writer.trim = true
|
24
|
+
|
24
25
|
assert_equal('POINT (6 7)', write(geom))
|
25
26
|
|
26
27
|
writer.trim = false
|
28
|
+
|
27
29
|
assert_equal('POINT (6.0000000000000000 7.0000000000000000)', write(geom))
|
28
30
|
end
|
29
31
|
|
@@ -35,7 +37,11 @@ class WktWriterTests < Minitest::Test
|
|
35
37
|
[
|
36
38
|
'POINT (0 0)',
|
37
39
|
'POINT EMPTY',
|
38
|
-
|
40
|
+
if Geos::GEOS_NICE_VERSION >= '031200'
|
41
|
+
'MULTIPOINT ((0 1), (2 3))'
|
42
|
+
else
|
43
|
+
'MULTIPOINT (0 1, 2 3)'
|
44
|
+
end,
|
39
45
|
'MULTIPOINT EMPTY',
|
40
46
|
'LINESTRING (0 0, 2 3)',
|
41
47
|
'LINESTRING EMPTY',
|
@@ -45,7 +51,11 @@ class WktWriterTests < Minitest::Test
|
|
45
51
|
'POLYGON EMPTY',
|
46
52
|
'MULTIPOLYGON (((0 0, 1 0, 1 1, 0 1, 0 0)), ((10 10, 10 14, 14 14, 14 10, 10 10), (11 11, 11 12, 12 12, 12 11, 11 11)))',
|
47
53
|
'MULTIPOLYGON EMPTY',
|
48
|
-
|
54
|
+
if Geos::GEOS_NICE_VERSION >= '031200'
|
55
|
+
'GEOMETRYCOLLECTION (MULTIPOLYGON (((0 0, 1 0, 1 1, 0 1, 0 0)), ((10 10, 10 14, 14 14, 14 10, 10 10), (11 11, 11 12, 12 12, 12 11, 11 11))), POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)), MULTILINESTRING ((0 0, 2 3), (10 10, 3 4)), LINESTRING (0 0, 2 3), MULTIPOINT ((0 0), (2 3)), POINT (9 0))'
|
56
|
+
else
|
57
|
+
'GEOMETRYCOLLECTION (MULTIPOLYGON (((0 0, 1 0, 1 1, 0 1, 0 0)), ((10 10, 10 14, 14 14, 14 10, 10 10), (11 11, 11 12, 12 12, 12 11, 11 11))), POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)), MULTILINESTRING ((0 0, 2 3), (10 10, 3 4)), LINESTRING (0 0, 2 3), MULTIPOINT (0 0, 2 3), POINT (9 0))'
|
58
|
+
end,
|
49
59
|
'GEOMETRYCOLLECTION EMPTY'
|
50
60
|
].each do |g|
|
51
61
|
assert_equal(g, write(read(g)))
|
@@ -59,6 +69,7 @@ class WktWriterTests < Minitest::Test
|
|
59
69
|
|
60
70
|
tester = lambda { |expected, precision|
|
61
71
|
writer.rounding_precision = precision if precision
|
72
|
+
|
62
73
|
assert_equal(expected, write(geom))
|
63
74
|
}
|
64
75
|
|
@@ -94,6 +105,7 @@ class WktWriterTests < Minitest::Test
|
|
94
105
|
|
95
106
|
# 3d if requested _and_ available
|
96
107
|
writer.output_dimensions = 3
|
108
|
+
|
97
109
|
assert_equal('POINT Z (1 2 3)', write(geom_3d))
|
98
110
|
assert_equal('POINT (3 2)', write(geom_2d))
|
99
111
|
|
@@ -114,6 +126,7 @@ class WktWriterTests < Minitest::Test
|
|
114
126
|
@writer.rounding_precision = 2
|
115
127
|
|
116
128
|
geom = read('POINT(1 2 3)')
|
129
|
+
|
117
130
|
assert_equal('POINT (1 2)', write(geom, trim: true))
|
118
131
|
|
119
132
|
assert_equal('POINT (1.0000 2.0000)', write(geom, rounding_precision: 4))
|
@@ -133,20 +146,25 @@ class WktWriterTests < Minitest::Test
|
|
133
146
|
|
134
147
|
# New 3d WKT by default
|
135
148
|
writer.output_dimensions = 3
|
149
|
+
|
136
150
|
assert_equal('POINT Z (1 2 3)', write(geom_3d))
|
137
151
|
|
138
152
|
# Switch to old
|
139
153
|
writer.old_3d = true
|
154
|
+
|
140
155
|
assert_equal('POINT (1 2 3)', write(geom_3d))
|
141
156
|
|
142
157
|
# Old3d flag is not reset when changing dimensions
|
143
158
|
writer.output_dimensions = 2
|
159
|
+
|
144
160
|
assert_equal('POINT (1 2)', write(geom_3d))
|
145
161
|
writer.output_dimensions = 3
|
162
|
+
|
146
163
|
assert_equal('POINT (1 2 3)', write(geom_3d))
|
147
164
|
|
148
165
|
# Likewise, dimensions spec is not reset when changing old3d flag
|
149
166
|
writer.old_3d = false
|
167
|
+
|
150
168
|
assert_equal('POINT Z (1 2 3)', write(geom_3d))
|
151
169
|
end
|
152
170
|
end
|