ffi-geos 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +2 -2
- data/.rbenv-vars +1 -0
- data/.rubocop.yml +538 -92
- data/.rubocop_todo.yml +28 -18
- data/ffi-geos.gemspec +2 -2
- data/lib/ffi-geos/coordinate_sequence.rb +2 -1
- data/lib/ffi-geos/geometry.rb +95 -1
- data/lib/ffi-geos/point.rb +9 -0
- data/lib/ffi-geos/version.rb +1 -1
- data/lib/ffi-geos.rb +78 -3
- data/test/coordinate_sequence_tests.rb +22 -4
- data/test/geojson_reader_tests.rb +6 -2
- 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 +6 -5
- 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 +26 -5
- data/test/wkt_reader_tests.rb +2 -0
- data/test/wkt_writer_tests.rb +20 -2
- metadata +154 -7
- data/test/geometry_tests.rb +0 -2114
@@ -0,0 +1,216 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryUnionTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_union
|
14
|
+
comparison_tester(
|
15
|
+
:union,
|
16
|
+
'POINT (0 0)',
|
17
|
+
'POINT(0 0)',
|
18
|
+
'POINT(0 0)'
|
19
|
+
)
|
20
|
+
|
21
|
+
comparison_tester(
|
22
|
+
:union,
|
23
|
+
if Geos::GEOS_NICE_VERSION >= '031200'
|
24
|
+
'MULTIPOINT ((0 0), (1 0))'
|
25
|
+
else
|
26
|
+
'MULTIPOINT (0 0, 1 0)'
|
27
|
+
end,
|
28
|
+
'POINT(0 0)',
|
29
|
+
'POINT(1 0)'
|
30
|
+
)
|
31
|
+
|
32
|
+
comparison_tester(
|
33
|
+
:union,
|
34
|
+
'LINESTRING (0 0, 10 0)',
|
35
|
+
'LINESTRING(0 0, 10 0)',
|
36
|
+
'POINT(5 0)'
|
37
|
+
)
|
38
|
+
|
39
|
+
comparison_tester(
|
40
|
+
:union,
|
41
|
+
'LINESTRING (0 0, 10 0)',
|
42
|
+
'POINT(5 0)',
|
43
|
+
'LINESTRING(0 0, 10 0)'
|
44
|
+
)
|
45
|
+
|
46
|
+
comparison_tester(
|
47
|
+
:union,
|
48
|
+
'GEOMETRYCOLLECTION (POINT (5 0), LINESTRING (0 1, 10 1))',
|
49
|
+
'POINT(5 0)',
|
50
|
+
'LINESTRING(0 1, 10 1)'
|
51
|
+
)
|
52
|
+
|
53
|
+
comparison_tester(
|
54
|
+
:union,
|
55
|
+
'MULTILINESTRING ((0 0, 5 0), (5 0, 10 0), (5 -10, 5 0), (5 0, 5 10))',
|
56
|
+
'LINESTRING(0 0, 10 0)',
|
57
|
+
'LINESTRING(5 -10, 5 10)'
|
58
|
+
)
|
59
|
+
|
60
|
+
comparison_tester(
|
61
|
+
:union,
|
62
|
+
'MULTILINESTRING ((0 0, 5 0), (5 0, 10 0), (10 0, 20 0))',
|
63
|
+
'LINESTRING(0 0, 10 0)',
|
64
|
+
'LINESTRING(5 0, 20 0)'
|
65
|
+
)
|
66
|
+
|
67
|
+
comparison_tester(
|
68
|
+
:union,
|
69
|
+
if Geos::GEOS_NICE_VERSION > '030900'
|
70
|
+
'GEOMETRYCOLLECTION (POLYGON ((0 10, 5 10, 10 10, 10 0, 5 0, 0 0, 0 10)), LINESTRING (5 -10, 5 0))'
|
71
|
+
else
|
72
|
+
'GEOMETRYCOLLECTION (LINESTRING (5 -10, 5 0), POLYGON ((0 0, 0 10, 5 10, 10 10, 10 0, 5 0, 0 0)))'
|
73
|
+
end,
|
74
|
+
'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
|
75
|
+
'LINESTRING(5 -10, 5 10)'
|
76
|
+
)
|
77
|
+
|
78
|
+
comparison_tester(
|
79
|
+
:union,
|
80
|
+
if Geos::GEOS_NICE_VERSION > '030900'
|
81
|
+
'GEOMETRYCOLLECTION (POLYGON ((0 10, 10 10, 10 0, 0 0, 0 10)), LINESTRING (10 0, 20 0))'
|
82
|
+
else
|
83
|
+
'GEOMETRYCOLLECTION (LINESTRING (10 0, 20 0), POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0)))'
|
84
|
+
end,
|
85
|
+
'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
|
86
|
+
'LINESTRING(10 0, 20 0)'
|
87
|
+
)
|
88
|
+
|
89
|
+
comparison_tester(
|
90
|
+
:union,
|
91
|
+
if Geos::GEOS_NICE_VERSION > '030900'
|
92
|
+
'POLYGON ((0 10, 10 10, 10 5, 15 5, 15 -5, 5 -5, 5 0, 0 0, 0 10))'
|
93
|
+
else
|
94
|
+
'POLYGON ((0 0, 0 10, 10 10, 10 5, 15 5, 15 -5, 5 -5, 5 0, 0 0))'
|
95
|
+
end,
|
96
|
+
'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
|
97
|
+
'POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))'
|
98
|
+
)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_union_with_precision
|
102
|
+
skip unless ENV['FORCE_TESTS'] || Geos::FFIGeos.respond_to?(:GEOSUnionPrec_r)
|
103
|
+
|
104
|
+
geom_a = read('POINT (1.9 8.2)')
|
105
|
+
geom_b = read('POINT (4.1 9.8)')
|
106
|
+
|
107
|
+
result = geom_a.union(geom_b, precision: 2)
|
108
|
+
|
109
|
+
assert_equal(
|
110
|
+
if Geos::GEOS_NICE_VERSION >= '031200'
|
111
|
+
'MULTIPOINT ((2 8), (4 10))'
|
112
|
+
else
|
113
|
+
'MULTIPOINT (2 8, 4 10)'
|
114
|
+
end,
|
115
|
+
write(result)
|
116
|
+
)
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_union_cascaded
|
120
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:union_cascaded)
|
121
|
+
|
122
|
+
simple_tester(
|
123
|
+
:union_cascaded,
|
124
|
+
if Geos::GEOS_NICE_VERSION > '030900'
|
125
|
+
'POLYGON ((0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0, 0 0), (12 12, 11 12, 11 11, 12 11, 12 12))'
|
126
|
+
else
|
127
|
+
'POLYGON ((1 0, 0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0), (11 11, 12 11, 12 12, 11 12, 11 11))'
|
128
|
+
end,
|
129
|
+
'MULTIPOLYGON(
|
130
|
+
((0 0, 1 0, 1 1, 0 1, 0 0)),
|
131
|
+
((10 10, 10 14, 14 14, 14 10, 10 10),
|
132
|
+
(11 11, 11 12, 12 12, 12 11, 11 11)),
|
133
|
+
((0 0, 11 0, 11 11, 0 11, 0 0))
|
134
|
+
)'
|
135
|
+
)
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_coverage_union
|
139
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:coverage_union)
|
140
|
+
|
141
|
+
simple_tester(
|
142
|
+
:union_cascaded,
|
143
|
+
if Geos::GEOS_NICE_VERSION > '030900'
|
144
|
+
'POLYGON ((0 1, 1 1, 2 1, 2 0, 1 0, 0 0, 0 1))'
|
145
|
+
else
|
146
|
+
'POLYGON ((0 0, 0 1, 1 1, 2 1, 2 0, 1 0, 0 0))'
|
147
|
+
end,
|
148
|
+
'MULTIPOLYGON(
|
149
|
+
((0 0, 0 1, 1 1, 1 0, 0 0)),
|
150
|
+
((1 0, 1 1, 2 1, 2 0, 1 0))
|
151
|
+
)'
|
152
|
+
)
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_unary_union
|
156
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:unary_union)
|
157
|
+
|
158
|
+
simple_tester(
|
159
|
+
:unary_union,
|
160
|
+
if Geos::GEOS_NICE_VERSION > '030900'
|
161
|
+
'POLYGON ((0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0, 0 0), (12 12, 11 12, 11 11, 12 11, 12 12))'
|
162
|
+
else
|
163
|
+
'POLYGON ((1 0, 0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0), (11 11, 12 11, 12 12, 11 12, 11 11))'
|
164
|
+
end,
|
165
|
+
'MULTIPOLYGON(
|
166
|
+
((0 0, 1 0, 1 1, 0 1, 0 0)),
|
167
|
+
((10 10, 10 14, 14 14, 14 10, 10 10),
|
168
|
+
(11 11, 11 12, 12 12, 12 11, 11 11)),
|
169
|
+
((0 0, 11 0, 11 11, 0 11, 0 0))
|
170
|
+
)'
|
171
|
+
)
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_unary_union_with_precision
|
175
|
+
skip unless ENV['FORCE_TESTS'] || Geos::FFIGeos.respond_to?(:GEOSUnaryUnionPrec_r)
|
176
|
+
|
177
|
+
simple_tester(
|
178
|
+
:unary_union,
|
179
|
+
'POLYGON ((0 0, 0 12, 9 12, 9 15, 15 15, 15 9, 12 9, 12 0, 0 0))',
|
180
|
+
'MULTIPOLYGON(
|
181
|
+
((0 0, 1 0, 1 1, 0 1, 0 0)),
|
182
|
+
((10 10, 10 14, 14 14, 14 10, 10 10),
|
183
|
+
(11 11, 11 12, 12 12, 12 11, 11 11)),
|
184
|
+
((0 0, 11 0, 11 11, 0 11, 0 0))
|
185
|
+
)',
|
186
|
+
3
|
187
|
+
)
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_disjoint_subset_union
|
191
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:disjoint_subset_union)
|
192
|
+
|
193
|
+
simple_tester(
|
194
|
+
:disjoint_subset_union,
|
195
|
+
'MULTIPOLYGON (((0 0, 0 1, 1 1, 2 1, 2 0, 1 0, 0 0)), ((3 3, 4 3, 4 4, 3 3)))',
|
196
|
+
'MULTIPOLYGON (((0 0, 1 0, 1 1, 0 1, 0 0)), ((1 0, 2 0, 2 1, 1 1, 1 0)), ((3 3, 4 3, 4 4, 3 3)))'
|
197
|
+
)
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_union_without_arguments
|
201
|
+
simple_tester(
|
202
|
+
:union,
|
203
|
+
if Geos::GEOS_NICE_VERSION > '030900'
|
204
|
+
'POLYGON ((0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0, 0 0), (12 12, 11 12, 11 11, 12 11, 12 12))'
|
205
|
+
else
|
206
|
+
'POLYGON ((1 0, 0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0), (11 11, 12 11, 12 12, 11 12, 11 11))'
|
207
|
+
end,
|
208
|
+
'MULTIPOLYGON(
|
209
|
+
((0 0, 1 0, 1 1, 0 1, 0 0)),
|
210
|
+
((10 10, 10 14, 14 14, 14 10, 10 10),
|
211
|
+
(11 11, 11 12, 12 12, 12 11, 11 11)),
|
212
|
+
((0 0, 11 0, 11 11, 0 11, 0 0))
|
213
|
+
)'
|
214
|
+
)
|
215
|
+
end
|
216
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryValidTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_valid
|
14
|
+
assert_geom_valid(read('POINT(0 0)'))
|
15
|
+
refute_geom_valid(read('POINT(0 NaN)'))
|
16
|
+
refute_geom_valid(read('POINT(0 nan)'))
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_valid_reason
|
20
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:valid_reason)
|
21
|
+
|
22
|
+
assert_equal('Valid Geometry', read('POINT(0 0)').valid_reason)
|
23
|
+
assert_equal('Invalid Coordinate[0 nan]', read('POINT(0 NaN)').valid_reason)
|
24
|
+
assert_equal('Invalid Coordinate[0 nan]', read('POINT(0 nan)').valid_reason)
|
25
|
+
assert_equal('Self-intersection[2.5 5]', read('POLYGON((0 0, 0 5, 5 5, 5 10, 0 0))').valid_reason)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_valid_detail
|
29
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:valid_detail)
|
30
|
+
|
31
|
+
tester = lambda { |detail, location, geom, flags|
|
32
|
+
ret = read(geom).valid_detail(flags)
|
33
|
+
|
34
|
+
assert_equal(detail, ret[:detail])
|
35
|
+
assert_equal(location, write(ret[:location]))
|
36
|
+
}
|
37
|
+
|
38
|
+
assert_nil(read('POINT(0 0)').valid_detail)
|
39
|
+
|
40
|
+
if Geos::GEOS_NICE_VERSION >= '031000'
|
41
|
+
tester['Invalid Coordinate', 'POINT (0 NaN)', 'POINT(0 NaN)', 0]
|
42
|
+
else
|
43
|
+
tester['Invalid Coordinate', 'POINT (0 nan)', 'POINT(0 NaN)', 0]
|
44
|
+
end
|
45
|
+
|
46
|
+
tester['Self-intersection', 'POINT (2.5 5)', 'POLYGON((0 0, 0 5, 5 5, 5 10, 0 0))', 0]
|
47
|
+
|
48
|
+
tester['Ring Self-intersection', 'POINT (0 0)', 'POLYGON((0 0, -10 10, 10 10, 0 0, 4 5, -4 5, 0 0))', 0]
|
49
|
+
|
50
|
+
assert_nil(
|
51
|
+
read('POLYGON((0 0, -10 10, 10 10, 0 0, 4 5, -4 5, 0 0))').valid_detail(
|
52
|
+
:allow_selftouching_ring_forming_hole
|
53
|
+
)
|
54
|
+
)
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class GeometryVoronoiDiagramTests < Minitest::Test
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_voronoi_diagram
|
14
|
+
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:voronoi_diagram)
|
15
|
+
|
16
|
+
tester = lambda { |expected, geom, *args|
|
17
|
+
geom = read(geom)
|
18
|
+
voronoi_diagram = geom.voronoi_diagram(*args)
|
19
|
+
|
20
|
+
assert_equal(expected, write(voronoi_diagram))
|
21
|
+
}
|
22
|
+
|
23
|
+
writer.trim = true
|
24
|
+
|
25
|
+
geom = 'MULTIPOINT(0 0, 100 0, 100 100, 0 100)'
|
26
|
+
|
27
|
+
tester[
|
28
|
+
if Geos::GEOS_NICE_VERSION > '030900'
|
29
|
+
'GEOMETRYCOLLECTION (POLYGON ((200 200, 200 50, 50 50, 50 200, 200 200)), POLYGON ((-100 200, 50 200, 50 50, -100 50, -100 200)), POLYGON ((-100 -100, -100 50, 50 50, 50 -100, -100 -100)), POLYGON ((200 -100, 50 -100, 50 50, 200 50, 200 -100)))'
|
30
|
+
else
|
31
|
+
'GEOMETRYCOLLECTION (POLYGON ((50 200, 200 200, 200 50, 50 50, 50 200)), POLYGON ((-100 50, -100 200, 50 200, 50 50, -100 50)), POLYGON ((50 -100, -100 -100, -100 50, 50 50, 50 -100)), POLYGON ((200 50, 200 -100, 50 -100, 50 50, 200 50)))'
|
32
|
+
end,
|
33
|
+
geom
|
34
|
+
]
|
35
|
+
|
36
|
+
tester['MULTILINESTRING ((50 50, 50 200), (200 50, 50 50), (50 50, -100 50), (50 50, 50 -100))', geom, tolerance: 0, only_edges: true]
|
37
|
+
|
38
|
+
tester['MULTILINESTRING ((50 50, 50 1100), (1100 50, 50 50), (50 50, -1000 50), (50 50, 50 -1000))', geom,
|
39
|
+
only_edges: true,
|
40
|
+
envelope: read(geom).buffer(1000)
|
41
|
+
]
|
42
|
+
|
43
|
+
# Allows a tolerance for the first argument
|
44
|
+
writer.rounding_precision = if Geos::GEOS_NICE_VERSION >= '031000'
|
45
|
+
0
|
46
|
+
else
|
47
|
+
3
|
48
|
+
end
|
49
|
+
|
50
|
+
writer.trim = true
|
51
|
+
|
52
|
+
tester[
|
53
|
+
if Geos::GEOS_NICE_VERSION > '030900'
|
54
|
+
'GEOMETRYCOLLECTION (POLYGON ((290 140, 185 140, 185 215, 188 235, 290 252, 290 140)), POLYGON ((80 340, 101 340, 188 235, 185 215, 80 215, 80 340)), POLYGON ((80 140, 80 215, 185 215, 185 140, 80 140)), POLYGON ((290 340, 290 252, 188 235, 101 340, 290 340)))'
|
55
|
+
else
|
56
|
+
'GEOMETRYCOLLECTION (POLYGON ((290 252, 290 140, 185 140, 185 215, 188 235, 290 252)), POLYGON ((80 215, 80 340, 101 340, 188 235, 185 215, 80 215)), POLYGON ((185 140, 80 140, 80 215, 185 215, 185 140)), POLYGON ((101 340, 290 340, 290 252, 188 235, 101 340)))'
|
57
|
+
end,
|
58
|
+
'MULTIPOINT ((150 210), (210 270), (150 220), (220 210), (215 269))',
|
59
|
+
10
|
60
|
+
]
|
61
|
+
end
|
62
|
+
end
|
@@ -14,6 +14,7 @@ class GeometryCollectionTests < Minitest::Test
|
|
14
14
|
skip unless ENV['FORCE_TESTS'] || Geos::GeometryCollection.method_defined?(:[])
|
15
15
|
|
16
16
|
geom = read('GEOMETRYCOLLECTION(POINT(0 0))')
|
17
|
+
|
17
18
|
assert_kind_of(Enumerable, geom.each)
|
18
19
|
assert_kind_of(Enumerable, geom.to_enum)
|
19
20
|
assert_equal(geom, geom.each(&EMPTY_BLOCK))
|
@@ -39,7 +40,7 @@ class GeometryCollectionTests < Minitest::Test
|
|
39
40
|
], geom[0, 2].collect { |g| write(g) })
|
40
41
|
|
41
42
|
assert_nil(geom[0, -1])
|
42
|
-
|
43
|
+
assert_empty(geom[-1, 0])
|
43
44
|
assert_equal([
|
44
45
|
'POINT (10 20)',
|
45
46
|
'POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0))'
|
@@ -62,25 +63,30 @@ class GeometryCollectionTests < Minitest::Test
|
|
62
63
|
|
63
64
|
def test_default_srid
|
64
65
|
geom = read('GEOMETRYCOLLECTION (POINT(0 0))')
|
66
|
+
|
65
67
|
assert_equal(0, geom.srid)
|
66
68
|
end
|
67
69
|
|
68
70
|
def test_setting_srid_manually
|
69
71
|
geom = read('GEOMETRYCOLLECTION (POINT(0 0))')
|
70
72
|
geom.srid = 4326
|
73
|
+
|
71
74
|
assert_equal(4326, geom.srid)
|
72
75
|
end
|
73
76
|
|
74
77
|
def test_dimensions
|
75
78
|
geom = read('GEOMETRYCOLLECTION (POINT(0 0))')
|
79
|
+
|
76
80
|
assert_equal(0, geom.dimensions)
|
77
81
|
|
78
82
|
geom = read('GEOMETRYCOLLECTION (LINESTRING(1 2, 3 4))')
|
83
|
+
|
79
84
|
assert_equal(1, geom.dimensions)
|
80
85
|
end
|
81
86
|
|
82
87
|
def test_num_geometries
|
83
88
|
geom = read('GEOMETRYCOLLECTION (POINT(1 2), LINESTRING(1 2, 3 4))')
|
89
|
+
|
84
90
|
assert_equal(2, geom.num_geometries)
|
85
91
|
end
|
86
92
|
|
@@ -130,6 +136,7 @@ class GeometryCollectionTests < Minitest::Test
|
|
130
136
|
LINESTRING (0 0, 5 0, 8 9, -10 5, 0 0),
|
131
137
|
POINT(3 12)
|
132
138
|
)')
|
139
|
+
|
133
140
|
assert_equal(0, geom.z_max)
|
134
141
|
|
135
142
|
geom = read('GEOMETRYCOLLECTION Z (
|
@@ -137,6 +144,7 @@ class GeometryCollectionTests < Minitest::Test
|
|
137
144
|
LINESTRING Z (0 0 0, 5 0 3, 8 9 4, -10 5 3, 0 0 0),
|
138
145
|
POINT Z (3 12 6)
|
139
146
|
)')
|
147
|
+
|
140
148
|
assert_equal(6, geom.z_max)
|
141
149
|
|
142
150
|
# GEOS lets you mix dimensionality, while PostGIS doesn't.
|
@@ -145,6 +153,7 @@ class GeometryCollectionTests < Minitest::Test
|
|
145
153
|
LINESTRING (0 0, 5 0, 8 9, -10 5, 0 0),
|
146
154
|
POINT(3 12 10)
|
147
155
|
)')
|
156
|
+
|
148
157
|
assert_equal(10, geom.z_max)
|
149
158
|
end
|
150
159
|
|
@@ -154,6 +163,7 @@ class GeometryCollectionTests < Minitest::Test
|
|
154
163
|
LINESTRING (0 0, 5 0, 8 9, -10 5, 0 0),
|
155
164
|
POINT(3 12)
|
156
165
|
)')
|
166
|
+
|
157
167
|
assert_equal(0, geom.z_min)
|
158
168
|
|
159
169
|
geom = read('GEOMETRYCOLLECTION Z (
|
@@ -161,6 +171,7 @@ class GeometryCollectionTests < Minitest::Test
|
|
161
171
|
LINESTRING Z (0 0 0, 5 0 3, 8 9 4, -10 5 3, 0 0 0),
|
162
172
|
POINT Z (3 12 6)
|
163
173
|
)')
|
174
|
+
|
164
175
|
assert_equal(0, geom.z_min)
|
165
176
|
|
166
177
|
# GEOS lets you mix dimensionality, while PostGIS doesn't.
|
@@ -169,6 +180,7 @@ class GeometryCollectionTests < Minitest::Test
|
|
169
180
|
LINESTRING (0 0, 5 0, 8 9, -10 5, 0 0),
|
170
181
|
POINT(3 12 -10)
|
171
182
|
)')
|
183
|
+
|
172
184
|
assert_equal(-10, geom.z_min)
|
173
185
|
end
|
174
186
|
|
@@ -182,7 +194,7 @@ class GeometryCollectionTests < Minitest::Test
|
|
182
194
|
end
|
183
195
|
|
184
196
|
def test_snap_to_grid_empty
|
185
|
-
|
197
|
+
assert_empty(read('GEOMETRYCOLLECTION EMPTY').snap_to_grid!, 'Expected an empty GeometryCollection')
|
186
198
|
end
|
187
199
|
|
188
200
|
def test_snap_to_grid_with_srid
|
data/test/interrupt_tests.rb
CHANGED
@@ -26,7 +26,7 @@ class InterruptTests < Minitest::Test
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def assert_interrupt_called(times = 0)
|
29
|
-
|
29
|
+
assert_operator(@interrupt_calls, :>, times, "Expected @interrupt_calls to be > #{times}")
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_interrupt_with_method
|
data/test/line_string_tests.rb
CHANGED
@@ -12,25 +12,30 @@ class LineStringTests < Minitest::Test
|
|
12
12
|
|
13
13
|
def test_default_srid
|
14
14
|
geom = read('LINESTRING (0 0, 10 10)')
|
15
|
+
|
15
16
|
assert_equal(0, geom.srid)
|
16
17
|
end
|
17
18
|
|
18
19
|
def test_setting_srid_manually
|
19
20
|
geom = read('LINESTRING (0 0, 10 10)')
|
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('LINESTRING (0 0, 10 10)')
|
28
|
+
|
26
29
|
assert_equal(1, geom.dimensions)
|
27
30
|
|
28
31
|
geom = read('LINESTRING (0 0 0, 10 10 10)')
|
32
|
+
|
29
33
|
assert_equal(1, geom.dimensions)
|
30
34
|
end
|
31
35
|
|
32
36
|
def test_num_geometries
|
33
37
|
geom = read('LINESTRING (0 0, 10 10)')
|
38
|
+
|
34
39
|
assert_equal(1, geom.num_geometries)
|
35
40
|
end
|
36
41
|
|
@@ -48,7 +53,7 @@ class LineStringTests < Minitest::Test
|
|
48
53
|
], geom[0, 2].collect { |g| write(g) })
|
49
54
|
|
50
55
|
assert_nil(geom[0, -1])
|
51
|
-
|
56
|
+
assert_empty(geom[-1, 0])
|
52
57
|
assert_equal([
|
53
58
|
'POINT (1 1)',
|
54
59
|
'POINT (2 2)'
|
@@ -95,7 +100,15 @@ class LineStringTests < Minitest::Test
|
|
95
100
|
# outside curve
|
96
101
|
simple_tester(
|
97
102
|
:offset_curve,
|
98
|
-
if Geos::GEOS_NICE_VERSION >= '
|
103
|
+
if Geos::GEOS_NICE_VERSION >= '031201'
|
104
|
+
'LINESTRING (0 -2, 10 -2, 10.390180644032256 -1.9615705608064609, 10.76536686473018 -1.8477590650225735, ' \
|
105
|
+
'11.111140466039204 -1.6629392246050905, 11.414213562373096 -1.414213562373095, 11.66293922460509 -1.1111404660392044, ' \
|
106
|
+
'11.847759065022574 -0.7653668647301796, 11.96157056080646 -0.3901806440322565, 12 0, 12 10)'
|
107
|
+
elsif Geos::GEOS_NICE_VERSION >= '031200'
|
108
|
+
'LINESTRING (0 -2, 10 -2, 10.390180644032256 -1.9615705608064609, 10.76536686473018 -1.8477590650225735, ' \
|
109
|
+
'11.111140466039204 -1.6629392246050902, 11.414213562373096 -1.414213562373095, 11.66293922460509 -1.1111404660392044, ' \
|
110
|
+
'11.847759065022574 -0.7653668647301796, 11.96157056080646 -0.3901806440322565, 12 0, 12 10)'
|
111
|
+
elsif Geos::GEOS_NICE_VERSION >= '031100'
|
99
112
|
'LINESTRING (0 -2, 10 -2, 12 0, 12 10)'
|
100
113
|
else
|
101
114
|
'LINESTRING (12 10, 12 0, 10 -2, 0 -2)'
|
@@ -199,37 +212,45 @@ class LineStringTests < Minitest::Test
|
|
199
212
|
|
200
213
|
def test_x_max
|
201
214
|
geom = read('LINESTRING (0 0, 5 0, 8 9, -10 5, 0 0)')
|
215
|
+
|
202
216
|
assert_equal(8, geom.x_max)
|
203
217
|
end
|
204
218
|
|
205
219
|
def test_x_min
|
206
220
|
geom = read('LINESTRING (0 0, 5 0, 8 9, -10 5, 0 0)')
|
221
|
+
|
207
222
|
assert_equal(-10, geom.x_min)
|
208
223
|
end
|
209
224
|
|
210
225
|
def test_y_max
|
211
226
|
geom = read('LINESTRING (0 0, 5 0, 8 9, -10 5, 0 0)')
|
227
|
+
|
212
228
|
assert_equal(9, geom.y_max)
|
213
229
|
end
|
214
230
|
|
215
231
|
def test_y_min
|
216
232
|
geom = read('LINESTRING (0 0, 5 0, 8 9, -10 5, 0 0)')
|
233
|
+
|
217
234
|
assert_equal(0, geom.y_min)
|
218
235
|
end
|
219
236
|
|
220
237
|
def test_z_max
|
221
238
|
geom = read('LINESTRING (0 0, 5 0, 8 9, -10 5, 0 0)')
|
239
|
+
|
222
240
|
assert_equal(0, geom.z_max)
|
223
241
|
|
224
242
|
geom = read('LINESTRING Z (0 0 0, 5 0 3, 8 9 4, -10 5 3, 0 0 0)')
|
243
|
+
|
225
244
|
assert_equal(4, geom.z_max)
|
226
245
|
end
|
227
246
|
|
228
247
|
def test_z_min
|
229
248
|
geom = read('LINESTRING (0 0, 5 0, 8 9, -10 5, 0 0)')
|
249
|
+
|
230
250
|
assert_equal(0, geom.z_min)
|
231
251
|
|
232
252
|
geom = read('LINESTRING Z (0 0 0, 5 0 3, 8 9 4, -10 5 3, 0 0 0)')
|
253
|
+
|
233
254
|
assert_equal(0, geom.z_min)
|
234
255
|
end
|
235
256
|
|
@@ -241,7 +262,7 @@ class LineStringTests < Minitest::Test
|
|
241
262
|
end
|
242
263
|
|
243
264
|
def test_snap_to_grid_empty
|
244
|
-
|
265
|
+
assert_empty(read('LINESTRING EMPTY').snap_to_grid!, 'Expected an empty LineString')
|
245
266
|
end
|
246
267
|
|
247
268
|
def test_snap_to_grid_with_srid
|
data/test/misc_tests.rb
CHANGED
@@ -111,7 +111,7 @@ class MiscTests < Minitest::Test
|
|
111
111
|
|
112
112
|
yield results
|
113
113
|
|
114
|
-
|
114
|
+
refute_predicate(geom, :valid?, 'Expected geom to be invalid')
|
115
115
|
assert_match(/^NOTICE: .+$/, results)
|
116
116
|
ensure
|
117
117
|
Geos.current_handle.reset_notice_handler
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
describe 'Geometry#has_z? and #has_m?' do
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def tester(geom, z: false, m: false)
|
14
|
+
geom = read(geom)
|
15
|
+
|
16
|
+
assert_equal(z, geom.has_z?) if Geos::Geometry.method_defined?(:has_z?)
|
17
|
+
assert_equal(m, geom.has_m?) if Geos::Geometry.method_defined?(:has_m?)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'handles 2D POLYGON' do
|
21
|
+
tester('POLYGON ((1 -2, 9 -2, 9 5, 1 5, 1 -2))', z: false, m: false)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'handles M POINT' do
|
25
|
+
tester('POINT M (1 2 3)', z: false, m: true)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'handles an empty POINT' do
|
29
|
+
tester('POINT EMPTY', z: false, m: false)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'handles an empty Z POINT' do
|
33
|
+
tester('POINT Z EMPTY', z: true, m: false)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'handles an M POINT' do
|
37
|
+
tester('POINT M EMPTY', z: false, m: true)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'handles an ZM POINT' do
|
41
|
+
tester('POINT ZM EMPTY', z: true, m: true)
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
describe 'X, Y, Z, M' do
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.trim = true
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'can get X, Y, Z, M from a 2D POINT' do
|
14
|
+
geom = read('POINT (1 2)')
|
15
|
+
|
16
|
+
assert_equal(1, geom.x)
|
17
|
+
assert_equal(2, geom.y)
|
18
|
+
assert_predicate(geom.z, :nan?)
|
19
|
+
assert_predicate(geom.m, :nan?) if geom.respond_to?(:m)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'can get Z, M from a 3D POINT' do
|
23
|
+
geom = read('POINT Z (1 2 3)')
|
24
|
+
|
25
|
+
assert_equal(3, geom.z)
|
26
|
+
assert_predicate(geom.m, :nan?) if geom.respond_to?(:m)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'can get Z, M from an M POINT' do
|
30
|
+
geom = read('POINT M (1 2 4)')
|
31
|
+
|
32
|
+
assert_predicate(geom.z, :nan?)
|
33
|
+
assert_equal(4, geom.m) if geom.respond_to?(:m)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'can get Z, M from a ZM POINT' do
|
37
|
+
geom = read('POINT ZM (1 2 3 4)')
|
38
|
+
|
39
|
+
assert_equal(3, geom.z)
|
40
|
+
assert_equal(4, geom.m) if geom.respond_to?(:m)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'handles an empty POINT' do
|
44
|
+
geom = read('POINT EMPTY')
|
45
|
+
|
46
|
+
assert_raises(Geos::GEOSException, 'UnsupportedOperationException') { geom.x }
|
47
|
+
assert_raises(Geos::GEOSException, 'UnsupportedOperationException') { geom.y }
|
48
|
+
assert_raises(Geos::GEOSException, 'UnsupportedOperationException') { geom.z }
|
49
|
+
assert_raises(Geos::GEOSException, 'UnsupportedOperationException') { geom.m } if geom.respond_to?(:m)
|
50
|
+
end
|
51
|
+
end
|