ffi-geos 1.2.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +4851 -0
- data/.travis.yml +24 -9
- data/FUNDING.yml +2 -0
- data/Gemfile +12 -16
- data/Guardfile +6 -8
- data/MIT-LICENSE +1 -1
- data/README.rdoc +2 -20
- data/Rakefile +4 -2
- data/ffi-geos.gemspec +13 -14
- data/lib/ffi-geos.rb +342 -244
- data/lib/ffi-geos/buffer_params.rb +9 -20
- data/lib/ffi-geos/coordinate_sequence.rb +351 -65
- data/lib/ffi-geos/geometry.rb +267 -191
- data/lib/ffi-geos/geometry_collection.rb +74 -12
- data/lib/ffi-geos/interrupt.rb +11 -16
- data/lib/ffi-geos/line_string.rb +157 -33
- data/lib/ffi-geos/linear_ring.rb +2 -3
- data/lib/ffi-geos/multi_line_string.rb +1 -2
- data/lib/ffi-geos/multi_point.rb +0 -1
- data/lib/ffi-geos/multi_polygon.rb +0 -1
- data/lib/ffi-geos/point.rb +70 -15
- data/lib/ffi-geos/polygon.rb +124 -21
- data/lib/ffi-geos/prepared_geometry.rb +11 -12
- data/lib/ffi-geos/strtree.rb +64 -77
- data/lib/ffi-geos/tools.rb +16 -19
- data/lib/ffi-geos/utils.rb +36 -60
- data/lib/ffi-geos/version.rb +1 -3
- data/lib/ffi-geos/wkb_reader.rb +4 -9
- data/lib/ffi-geos/wkb_writer.rb +15 -20
- data/lib/ffi-geos/wkt_reader.rb +2 -5
- data/lib/ffi-geos/wkt_writer.rb +20 -31
- data/sonar-project.properties +16 -0
- data/test/.rubocop.yml +36 -0
- data/test/coordinate_sequence_tests.rb +322 -52
- data/test/geometry_collection_tests.rb +388 -4
- data/test/geometry_tests.rb +466 -121
- data/test/interrupt_tests.rb +9 -12
- data/test/line_string_tests.rb +213 -25
- data/test/linear_ring_tests.rb +1 -3
- data/test/misc_tests.rb +28 -30
- data/test/multi_line_string_tests.rb +0 -2
- data/test/point_tests.rb +158 -2
- data/test/polygon_tests.rb +283 -2
- data/test/prepared_geometry_tests.rb +8 -11
- data/test/strtree_tests.rb +14 -15
- data/test/test_helper.rb +75 -51
- data/test/tools_tests.rb +1 -4
- data/test/utils_tests.rb +85 -76
- data/test/wkb_reader_tests.rb +18 -18
- data/test/wkb_writer_tests.rb +15 -22
- data/test/wkt_reader_tests.rb +1 -4
- data/test/wkt_writer_tests.rb +8 -17
- metadata +11 -7
@@ -1,7 +1,5 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
|
-
$: << File.dirname(__FILE__)
|
5
3
|
require 'test_helper'
|
6
4
|
|
7
5
|
class PreparedGeometryTests < Minitest::Test
|
@@ -19,14 +17,14 @@ class PreparedGeometryTests < Minitest::Test
|
|
19
17
|
|
20
18
|
def relationship_tester(method, *expected)
|
21
19
|
[
|
22
|
-
[
|
23
|
-
[
|
24
|
-
[
|
25
|
-
[
|
26
|
-
[
|
27
|
-
[
|
28
|
-
[
|
29
|
-
[
|
20
|
+
[POINT_A, POINT_A],
|
21
|
+
[POINT_A, LINESTRING_A],
|
22
|
+
[POINT_B, LINESTRING_A],
|
23
|
+
[LINESTRING_B, LINESTRING_A],
|
24
|
+
[LINESTRING_C, LINESTRING_A],
|
25
|
+
[LINESTRING_D, LINESTRING_A],
|
26
|
+
[POLYGON_A, POLYGON_B],
|
27
|
+
[POLYGON_A, POINT_C]
|
30
28
|
].each_with_index do |(geom_a, geom_b), i|
|
31
29
|
geom_a = read(geom_a).to_prepared
|
32
30
|
geom_b = read(geom_b)
|
@@ -114,4 +112,3 @@ class PreparedGeometryTests < Minitest::Test
|
|
114
112
|
end
|
115
113
|
end
|
116
114
|
end
|
117
|
-
|
data/test/strtree_tests.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
|
-
$: << File.dirname(__FILE__)
|
5
3
|
require 'test_helper'
|
6
4
|
|
7
5
|
class STRtreeTests < Minitest::Test
|
@@ -9,8 +7,8 @@ class STRtreeTests < Minitest::Test
|
|
9
7
|
|
10
8
|
def setup_tree
|
11
9
|
@tree = Geos::STRtree.new(3)
|
12
|
-
@item_1 = { :
|
13
|
-
@item_2 = [
|
10
|
+
@item_1 = { item_1: :test }
|
11
|
+
@item_2 = [:test]
|
14
12
|
@item_3 = Object.new
|
15
13
|
|
16
14
|
@geom_1 = read('LINESTRING(0 0, 10 10)')
|
@@ -83,7 +81,7 @@ class STRtreeTests < Minitest::Test
|
|
83
81
|
|
84
82
|
assert_equal(
|
85
83
|
[
|
86
|
-
{ :
|
84
|
+
{ item: @item_1, geometry: @geom_1 }
|
87
85
|
],
|
88
86
|
@tree.query(read('LINESTRING(5 5, 6 6)'), :all)
|
89
87
|
)
|
@@ -93,17 +91,17 @@ class STRtreeTests < Minitest::Test
|
|
93
91
|
|
94
92
|
assert_equal(
|
95
93
|
[
|
96
|
-
{ :
|
97
|
-
{ :
|
94
|
+
{ item: @item_2, geometry: @geom_2 },
|
95
|
+
{ item: @item_3, geometry: @geom_3 }
|
98
96
|
],
|
99
97
|
@tree.query(read('LINESTRING(25 25, 26 26)'), :all)
|
100
98
|
)
|
101
99
|
|
102
100
|
assert_equal(
|
103
101
|
[
|
104
|
-
{ :
|
105
|
-
{ :
|
106
|
-
{ :
|
102
|
+
{ item: @item_1, geometry: @geom_1 },
|
103
|
+
{ item: @item_2, geometry: @geom_2 },
|
104
|
+
{ item: @item_3, geometry: @geom_3 }
|
107
105
|
],
|
108
106
|
@tree.query(read('LINESTRING(0 0, 100 100)'), :all)
|
109
107
|
)
|
@@ -185,9 +183,9 @@ class STRtreeTests < Minitest::Test
|
|
185
183
|
skip unless ENV['FORCE_TESTS'] || defined?(Geos::STRtree)
|
186
184
|
|
187
185
|
tree = Geos::STRtree.new(
|
188
|
-
[
|
189
|
-
[
|
190
|
-
[
|
186
|
+
[read('LINESTRING(0 0, 10 10)'), item_1 = { item_1: :test }],
|
187
|
+
[read('LINESTRING(20 20, 30 30)'), item_2 = [:test]],
|
188
|
+
[read('LINESTRING(20 20, 30 30)'), item_3 = Object.new]
|
191
189
|
)
|
192
190
|
|
193
191
|
assert_equal([item_1],
|
@@ -315,6 +313,7 @@ class STRtreeTests < Minitest::Test
|
|
315
313
|
|
316
314
|
def test_nearest_with_only_empty_geometries
|
317
315
|
skip unless ENV['FORCE_TESTS'] || defined?(Geos::STRtree) && Geos::STRtree.method_defined?(:nearest)
|
316
|
+
skip if Geos::GEOS_VERSION > '3.9.0'
|
318
317
|
|
319
318
|
geom_1 = read('LINESTRING EMPTY')
|
320
319
|
geom_2 = read('POINT (2 7)')
|
@@ -347,8 +346,8 @@ class STRtreeTests < Minitest::Test
|
|
347
346
|
geom_3 = read('POINT (5 4)')
|
348
347
|
geom_4 = read('POINT (3 8)')
|
349
348
|
|
350
|
-
item_1 = { :
|
351
|
-
item_2 = [
|
349
|
+
item_1 = { item_1: :test }
|
350
|
+
item_2 = [:test]
|
352
351
|
item_3 = Object.new
|
353
352
|
|
354
353
|
tree = Geos::STRtree.new(2)
|
data/test/test_helper.rb
CHANGED
@@ -1,20 +1,17 @@
|
|
1
|
-
# encoding: BINARY
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
5
|
-
require 'simplecov'
|
3
|
+
require 'simplecov'
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
5
|
+
SimpleCov.command_name('Unit Tests')
|
6
|
+
SimpleCov.merge_timeout(3600)
|
7
|
+
SimpleCov.start do
|
8
|
+
add_filter '/test/'
|
9
|
+
add_filter '/.bundle/'
|
13
10
|
end
|
14
11
|
|
15
12
|
require 'rubygems'
|
16
13
|
require 'minitest/autorun'
|
17
|
-
require 'minitest/reporters'
|
14
|
+
require 'minitest/reporters'
|
18
15
|
|
19
16
|
if ENV['USE_BINARY_GEOS']
|
20
17
|
require 'geos'
|
@@ -32,14 +29,21 @@ else
|
|
32
29
|
end
|
33
30
|
|
34
31
|
puts "ffi-geos version #{Geos::VERSION}" if defined?(Geos::VERSION)
|
35
|
-
|
36
|
-
if defined?(Geos::FFIGeos)
|
37
|
-
puts "Using #{Geos::FFIGeos.geos_library_path}"
|
38
|
-
end
|
32
|
+
puts "Using #{Geos::FFIGeos.geos_library_path}" if defined?(Geos::FFIGeos)
|
39
33
|
|
40
34
|
module TestHelper
|
41
35
|
TOLERANCE = 0.0000000000001
|
42
36
|
|
37
|
+
EMPTY_GEOMETRY = if Geos::GEOS_VERSION > '3.8'
|
38
|
+
'POINT EMPTY'
|
39
|
+
else
|
40
|
+
'GEOMETRYCOLLECTION EMPTY'
|
41
|
+
end
|
42
|
+
|
43
|
+
EMPTY_BLOCK = proc do
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
|
43
47
|
def self.included(base)
|
44
48
|
base.class_eval do
|
45
49
|
attr_reader :reader, :reader_hex, :writer
|
@@ -53,16 +57,16 @@ module TestHelper
|
|
53
57
|
@writer = Geos::WktWriter.new
|
54
58
|
end
|
55
59
|
|
56
|
-
def read(*args)
|
57
|
-
if args[0][0]
|
58
|
-
|
60
|
+
def read(*args, **options)
|
61
|
+
if args[0][0] == '0'
|
62
|
+
reader_hex.read_hex(*args, **options)
|
59
63
|
else
|
60
|
-
|
64
|
+
reader.read(*args, **options)
|
61
65
|
end
|
62
66
|
end
|
63
67
|
|
64
|
-
def write(*args)
|
65
|
-
writer.write(*args)
|
68
|
+
def write(*args, **options)
|
69
|
+
writer.write(*args, **options)
|
66
70
|
end
|
67
71
|
|
68
72
|
def geom_from_geom_or_wkt(geom_or_wkt)
|
@@ -73,11 +77,11 @@ module TestHelper
|
|
73
77
|
end
|
74
78
|
end
|
75
79
|
|
76
|
-
def srid_copy_tester(method, expected, expected_srid, srid_policy, wkt, *args)
|
80
|
+
def srid_copy_tester(method, expected, expected_srid, srid_policy, wkt, *args, **options)
|
77
81
|
geom = read(wkt)
|
78
82
|
geom.srid = 4326
|
79
83
|
Geos.srid_copy_policy = srid_policy
|
80
|
-
geom_b = geom.send(method, *args)
|
84
|
+
geom_b = geom.send(method, *args, **options)
|
81
85
|
assert_equal(4326, geom.srid)
|
82
86
|
assert_equal(expected_srid, geom_b.srid)
|
83
87
|
assert_equal(expected, write(geom_b))
|
@@ -86,14 +90,14 @@ module TestHelper
|
|
86
90
|
end
|
87
91
|
|
88
92
|
{
|
89
|
-
:
|
90
|
-
:
|
91
|
-
:
|
92
|
-
:
|
93
|
-
:
|
94
|
-
:
|
93
|
+
empty: 'to be empty',
|
94
|
+
valid: 'to be valid',
|
95
|
+
simple: 'to be simple',
|
96
|
+
ring: 'to be ring',
|
97
|
+
closed: 'to be closed',
|
98
|
+
has_z: 'to have z dimension'
|
95
99
|
}.each do |t, m|
|
96
|
-
|
100
|
+
class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
|
97
101
|
def assert_geom_#{t}(geom)
|
98
102
|
assert(geom.#{t}?, "Expected geom #{m}")
|
99
103
|
end
|
@@ -101,62 +105,82 @@ module TestHelper
|
|
101
105
|
def refute_geom_#{t}(geom)
|
102
106
|
assert(!geom.#{t}?, "Did not expect geom #{m}")
|
103
107
|
end
|
104
|
-
|
108
|
+
RUBY
|
105
109
|
end
|
106
110
|
|
107
111
|
def assert_geom_eql_exact(geom, result, tolerance = TOLERANCE)
|
108
112
|
assert(geom.eql_exact?(result, tolerance), "Expected geom.eql_exact? to be within #{tolerance}")
|
109
113
|
end
|
110
114
|
|
111
|
-
def
|
115
|
+
def snapped_tester(method, expected, geom, *args, **options)
|
112
116
|
geom = geom_from_geom_or_wkt(geom)
|
113
|
-
result = geom.send(method, *args)
|
114
117
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
+
result = geom.send(method, *args, **options)
|
119
|
+
assert_equal(expected, write(result.snap_to_grid(1)))
|
120
|
+
end
|
118
121
|
|
119
|
-
|
122
|
+
def simple_tester(method, expected, geom, *args, **options)
|
123
|
+
geom = geom_from_geom_or_wkt(geom)
|
124
|
+
result = geom.send(method, *args, **options)
|
125
|
+
result = write(result) if result.is_a?(Geos::Geometry)
|
126
|
+
|
127
|
+
if expected.nil?
|
128
|
+
assert_nil(result)
|
129
|
+
else
|
130
|
+
assert_equal(expected, result)
|
131
|
+
end
|
120
132
|
end
|
121
133
|
|
122
|
-
def simple_bang_tester(method, expected, wkt, *args)
|
134
|
+
def simple_bang_tester(method, expected, wkt, *args, **options)
|
123
135
|
geom = read(wkt)
|
124
|
-
result = geom.send(method, *args)
|
136
|
+
result = geom.send(method, *args, **options)
|
125
137
|
|
126
138
|
assert_equal(wkt, write(geom))
|
127
139
|
assert_equal(expected, write(result))
|
128
140
|
|
129
141
|
geom = read(wkt)
|
130
|
-
geom.send("#{method}!", *args)
|
142
|
+
geom.send("#{method}!", *args, **options)
|
131
143
|
|
132
144
|
assert_equal(expected, write(geom))
|
133
145
|
end
|
134
146
|
|
135
|
-
def comparison_tester(method, expected, geom_a, geom_b, *args)
|
136
|
-
geom_a = geom_from_geom_or_wkt(geom_a)
|
137
|
-
geom_b = geom_from_geom_or_wkt(geom_b)
|
147
|
+
def comparison_tester(method, expected, geom_a, geom_b, *args, **options)
|
148
|
+
geom_a = geom_from_geom_or_wkt(geom_a).normalize
|
149
|
+
geom_b = geom_from_geom_or_wkt(geom_b).normalize
|
138
150
|
|
139
|
-
simple_tester(method, expected, geom_a, geom_b, *args)
|
151
|
+
simple_tester(method, expected, geom_a, geom_b, *args, **options)
|
140
152
|
end
|
141
153
|
|
142
|
-
def array_tester(method, expected, geom, *args)
|
154
|
+
def array_tester(method, expected, geom, *args, **options)
|
143
155
|
geom = geom_from_geom_or_wkt(geom)
|
144
|
-
result = geom.send(method, *args)
|
156
|
+
result = geom.send(method, *args, **options)
|
145
157
|
|
146
158
|
case result
|
147
159
|
when Geos::Geometry
|
148
|
-
result = [
|
160
|
+
result = [write(result)]
|
149
161
|
when Array
|
150
|
-
result = result.collect
|
162
|
+
result = result.collect do |r|
|
151
163
|
write(r)
|
152
|
-
|
164
|
+
end
|
153
165
|
end
|
154
166
|
|
155
167
|
assert_equal(expected, result)
|
156
168
|
end
|
157
|
-
end
|
158
169
|
|
159
|
-
|
160
|
-
|
170
|
+
def affine_tester(method, expected, wkt, *args, **options)
|
171
|
+
writer.trim = true
|
172
|
+
|
173
|
+
geom = read(wkt)
|
174
|
+
geom.send("#{method}!", *args, **options).snap_to_grid!(0.1)
|
175
|
+
|
176
|
+
assert_equal(expected, write(geom))
|
177
|
+
|
178
|
+
geom = read(wkt)
|
179
|
+
geom_2 = geom.send(method, *args, **options).snap_to_grid(0.1)
|
180
|
+
|
181
|
+
assert_equal(wkt, write(geom))
|
182
|
+
assert_equal(expected, write(geom_2, trim: true))
|
183
|
+
end
|
161
184
|
end
|
162
185
|
|
186
|
+
Minitest::Reporters.use!(Minitest::Reporters::SpecReporter.new)
|
data/test/tools_tests.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
|
-
$: << File.dirname(__FILE__)
|
5
3
|
require 'test_helper'
|
6
4
|
|
7
5
|
class ToolsTests < Minitest::Test
|
@@ -25,7 +23,7 @@ class ToolsTests < Minitest::Test
|
|
25
23
|
def test_bool_to_int
|
26
24
|
assert_equal(1, Geos::Tools.bool_to_int(1))
|
27
25
|
assert_equal(1, Geos::Tools.bool_to_int(true))
|
28
|
-
assert_equal(1, Geos::Tools.bool_to_int(
|
26
|
+
assert_equal(1, Geos::Tools.bool_to_int(''))
|
29
27
|
assert_equal(1, Geos::Tools.bool_to_int(0))
|
30
28
|
assert_equal(0, Geos::Tools.bool_to_int(false))
|
31
29
|
assert_equal(0, Geos::Tools.bool_to_int(nil))
|
@@ -92,4 +90,3 @@ class ToolsTests < Minitest::Test
|
|
92
90
|
assert_equal(:round, Geos::Tools.symbol_for_enum(Geos::BufferCapStyles, 1))
|
93
91
|
end
|
94
92
|
end
|
95
|
-
|
data/test/utils_tests.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
|
-
$: << File.dirname(__FILE__)
|
5
3
|
require 'test_helper'
|
6
4
|
|
7
5
|
class UtilsTests < Minitest::Test
|
@@ -15,17 +13,17 @@ class UtilsTests < Minitest::Test
|
|
15
13
|
def test_orientation_index
|
16
14
|
skip unless ENV['FORCE_TESTS'] || (defined?(Geos::Utils) && Geos::Utils.respond_to?(:orientation_index))
|
17
15
|
|
18
|
-
assert_equal(0,
|
19
|
-
assert_equal(0,
|
20
|
-
assert_equal(0,
|
21
|
-
assert_equal(0,
|
22
|
-
assert_equal(0,
|
23
|
-
assert_equal(1,
|
24
|
-
assert_equal(1,
|
25
|
-
assert_equal(-1,
|
26
|
-
assert_equal(-1,
|
27
|
-
assert_equal(1,
|
28
|
-
assert_equal(-1,
|
16
|
+
assert_equal(0, Geos::Utils.orientation_index(0, 0, 10, 0, 5, 0))
|
17
|
+
assert_equal(0, Geos::Utils.orientation_index(0, 0, 10, 0, 10, 0))
|
18
|
+
assert_equal(0, Geos::Utils.orientation_index(0, 0, 10, 0, 0, 0))
|
19
|
+
assert_equal(0, Geos::Utils.orientation_index(0, 0, 10, 0, -5, 0))
|
20
|
+
assert_equal(0, Geos::Utils.orientation_index(0, 0, 10, 0, 20, 0))
|
21
|
+
assert_equal(1, Geos::Utils.orientation_index(0, 0, 10, 10, 5, 6))
|
22
|
+
assert_equal(1, Geos::Utils.orientation_index(0, 0, 10, 10, 5, 20))
|
23
|
+
assert_equal(-1, Geos::Utils.orientation_index(0, 0, 10, 10, 5, 3))
|
24
|
+
assert_equal(-1, Geos::Utils.orientation_index(0, 0, 10, 10, 5, -2))
|
25
|
+
assert_equal(1, Geos::Utils.orientation_index(0, 0, 10, 10, 1_000_000, 1_000_001))
|
26
|
+
assert_equal(-1, Geos::Utils.orientation_index(0, 0, 10, 10, 1_000_000, 999_999))
|
29
27
|
end
|
30
28
|
|
31
29
|
def test_relate_match
|
@@ -50,7 +48,7 @@ class UtilsTests < Minitest::Test
|
|
50
48
|
end
|
51
49
|
|
52
50
|
def test_create_point
|
53
|
-
cs = Geos::CoordinateSequence.new([[
|
51
|
+
cs = Geos::CoordinateSequence.new([[10, 20]])
|
54
52
|
create_method_tester('POINT (10 20)', :create_point, cs, Geos::GEOS_POINT, Geos::Point)
|
55
53
|
end
|
56
54
|
|
@@ -59,7 +57,7 @@ class UtilsTests < Minitest::Test
|
|
59
57
|
end
|
60
58
|
|
61
59
|
def test_create_point_with_x_y_and_z_arguments
|
62
|
-
assert_equal('POINT Z (10 20 30)', write(Geos.create_point(10, 20, 30), :
|
60
|
+
assert_equal('POINT Z (10 20 30)', write(Geos.create_point(10, 20, 30), output_dimensions: 3))
|
63
61
|
end
|
64
62
|
|
65
63
|
def test_create_point_with_too_many_arguments
|
@@ -77,8 +75,8 @@ class UtilsTests < Minitest::Test
|
|
77
75
|
|
78
76
|
def test_create_line_string
|
79
77
|
cs = Geos::CoordinateSequence.new([
|
80
|
-
|
81
|
-
|
78
|
+
[10, 20, 30],
|
79
|
+
[30, 20, 10]
|
82
80
|
])
|
83
81
|
|
84
82
|
writer.output_dimensions = 3
|
@@ -105,7 +103,7 @@ class UtilsTests < Minitest::Test
|
|
105
103
|
create_method_tester(
|
106
104
|
'LINESTRING Z (10 20 30, 30 20 10)',
|
107
105
|
:create_line_string,
|
108
|
-
[[
|
106
|
+
[[10, 20, 30], [30, 20, 10]],
|
109
107
|
Geos::GEOS_LINESTRING,
|
110
108
|
Geos::LineString
|
111
109
|
) do |geom|
|
@@ -121,16 +119,16 @@ class UtilsTests < Minitest::Test
|
|
121
119
|
def test_create_bad_line_string
|
122
120
|
cs = Geos::CoordinateSequence.new(1, 0)
|
123
121
|
assert_raises(ArgumentError) do
|
124
|
-
Geos
|
122
|
+
Geos.create_line_string(cs)
|
125
123
|
end
|
126
124
|
end
|
127
125
|
|
128
126
|
def test_create_linear_ring
|
129
127
|
cs = Geos::CoordinateSequence.new([
|
130
|
-
[
|
131
|
-
[
|
132
|
-
[
|
133
|
-
[
|
128
|
+
[7, 8, 9],
|
129
|
+
[3, 3, 3],
|
130
|
+
[11, 15.2, 2],
|
131
|
+
[7, 8, 9]
|
134
132
|
])
|
135
133
|
|
136
134
|
writer.output_dimensions = 3
|
@@ -157,7 +155,7 @@ class UtilsTests < Minitest::Test
|
|
157
155
|
create_method_tester(
|
158
156
|
'LINEARRING Z (7 8 9, 3 3 3, 11 15.2 2, 7 8 9)',
|
159
157
|
:create_linear_ring,
|
160
|
-
[[
|
158
|
+
[[7, 8, 9], [3, 3, 3], [11, 15.2, 2], [7, 8, 9]],
|
161
159
|
Geos::GEOS_LINEARRING,
|
162
160
|
Geos::LinearRing
|
163
161
|
) do |geom|
|
@@ -174,22 +172,22 @@ class UtilsTests < Minitest::Test
|
|
174
172
|
cs = Geos::CoordinateSequence.new(1, 0)
|
175
173
|
|
176
174
|
assert_raises(ArgumentError) do
|
177
|
-
Geos
|
175
|
+
Geos.create_linear_ring(cs)
|
178
176
|
end
|
179
177
|
end
|
180
178
|
|
181
179
|
def test_create_polygon
|
182
180
|
cs = Geos::CoordinateSequence.new([
|
183
|
-
[
|
184
|
-
[
|
185
|
-
[
|
186
|
-
[
|
187
|
-
[
|
181
|
+
[0, 0],
|
182
|
+
[0, 10],
|
183
|
+
[10, 10],
|
184
|
+
[10, 0],
|
185
|
+
[0, 0]
|
188
186
|
])
|
189
187
|
|
190
|
-
exterior_ring = Geos
|
188
|
+
exterior_ring = Geos.create_linear_ring(cs)
|
191
189
|
|
192
|
-
geom = Geos
|
190
|
+
geom = Geos.create_polygon(exterior_ring)
|
193
191
|
assert_instance_of(Geos::Polygon, geom)
|
194
192
|
assert_equal('Polygon', geom.geom_type)
|
195
193
|
assert_equal(Geos::GEOS_POLYGON, geom.type_id)
|
@@ -198,22 +196,22 @@ class UtilsTests < Minitest::Test
|
|
198
196
|
|
199
197
|
def test_create_polygon_with_coordinate_sequences
|
200
198
|
outer = Geos::CoordinateSequence.new(
|
201
|
-
[
|
202
|
-
[
|
203
|
-
[
|
204
|
-
[
|
205
|
-
[
|
199
|
+
[0, 0],
|
200
|
+
[0, 10],
|
201
|
+
[10, 10],
|
202
|
+
[10, 0],
|
203
|
+
[0, 0]
|
206
204
|
)
|
207
205
|
|
208
206
|
inner = Geos::CoordinateSequence.new(
|
209
|
-
[
|
210
|
-
[
|
211
|
-
[
|
212
|
-
[
|
213
|
-
[
|
207
|
+
[2, 2],
|
208
|
+
[2, 4],
|
209
|
+
[4, 4],
|
210
|
+
[4, 2],
|
211
|
+
[2, 2]
|
214
212
|
)
|
215
213
|
|
216
|
-
geom = Geos
|
214
|
+
geom = Geos.create_polygon(outer, inner)
|
217
215
|
assert_instance_of(Geos::Polygon, geom)
|
218
216
|
assert_equal('Polygon', geom.geom_type)
|
219
217
|
assert_equal(Geos::GEOS_POLYGON, geom.type_id)
|
@@ -222,30 +220,30 @@ class UtilsTests < Minitest::Test
|
|
222
220
|
|
223
221
|
def test_create_polygon_with_holes
|
224
222
|
exterior_ring = Geos::CoordinateSequence.new(
|
225
|
-
[
|
226
|
-
[
|
227
|
-
[
|
228
|
-
[
|
229
|
-
[
|
223
|
+
[0, 0],
|
224
|
+
[0, 10],
|
225
|
+
[10, 10],
|
226
|
+
[10, 0],
|
227
|
+
[0, 0]
|
230
228
|
)
|
231
229
|
|
232
230
|
hole_1 = Geos::CoordinateSequence.new(
|
233
|
-
[
|
234
|
-
[
|
235
|
-
[
|
236
|
-
[
|
237
|
-
[
|
231
|
+
[2, 2],
|
232
|
+
[2, 4],
|
233
|
+
[4, 4],
|
234
|
+
[4, 2],
|
235
|
+
[2, 2]
|
238
236
|
)
|
239
237
|
|
240
238
|
hole_2 = Geos::CoordinateSequence.new(
|
241
|
-
[
|
242
|
-
[
|
243
|
-
[
|
244
|
-
[
|
245
|
-
[
|
239
|
+
[6, 6],
|
240
|
+
[6, 8],
|
241
|
+
[8, 8],
|
242
|
+
[8, 6],
|
243
|
+
[6, 6]
|
246
244
|
)
|
247
245
|
|
248
|
-
geom = Geos
|
246
|
+
geom = Geos.create_polygon(exterior_ring, [hole_1, hole_2])
|
249
247
|
assert_instance_of(Geos::Polygon, geom)
|
250
248
|
assert_equal('Polygon', geom.geom_type)
|
251
249
|
assert_equal(Geos::GEOS_POLYGON, geom.type_id)
|
@@ -263,10 +261,13 @@ class UtilsTests < Minitest::Test
|
|
263
261
|
skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_multi_point)
|
264
262
|
|
265
263
|
assert_equal('MULTIPOINT EMPTY', write(Geos.create_multi_point))
|
266
|
-
assert_equal('MULTIPOINT (0 0, 10 10)',
|
267
|
-
|
268
|
-
|
269
|
-
|
264
|
+
assert_equal('MULTIPOINT (0 0, 10 10)',
|
265
|
+
write(
|
266
|
+
Geos.create_multi_point(
|
267
|
+
read('POINT(0 0)'),
|
268
|
+
read('POINT(10 10)')
|
269
|
+
)
|
270
|
+
))
|
270
271
|
end
|
271
272
|
|
272
273
|
def test_create_bad_multi_point
|
@@ -284,10 +285,13 @@ class UtilsTests < Minitest::Test
|
|
284
285
|
skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_multi_line_string)
|
285
286
|
|
286
287
|
assert_equal('MULTILINESTRING EMPTY', write(Geos.create_multi_line_string))
|
287
|
-
assert_equal('MULTILINESTRING ((0 0, 10 10), (10 10, 20 20))',
|
288
|
-
|
289
|
-
|
290
|
-
|
288
|
+
assert_equal('MULTILINESTRING ((0 0, 10 10), (10 10, 20 20))',
|
289
|
+
write(
|
290
|
+
Geos.create_multi_line_string(
|
291
|
+
read('LINESTRING(0 0, 10 10)'),
|
292
|
+
read('LINESTRING(10 10, 20 20)')
|
293
|
+
)
|
294
|
+
))
|
291
295
|
end
|
292
296
|
|
293
297
|
def test_create_bad_multi_line_string
|
@@ -305,10 +309,13 @@ class UtilsTests < Minitest::Test
|
|
305
309
|
skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_multi_polygon)
|
306
310
|
|
307
311
|
assert_equal('MULTIPOLYGON EMPTY', write(Geos.create_multi_polygon))
|
308
|
-
assert_equal('MULTIPOLYGON (((0 0, 0 5, 5 5, 5 0, 0 0)), ((10 10, 10 15, 15 15, 15 10, 10 10)))',
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
+
assert_equal('MULTIPOLYGON (((0 0, 0 5, 5 5, 5 0, 0 0)), ((10 10, 10 15, 15 15, 15 10, 10 10)))',
|
313
|
+
write(
|
314
|
+
Geos.create_multi_polygon(
|
315
|
+
read('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'),
|
316
|
+
read('POLYGON((10 10, 10 15, 15 15, 15 10, 10 10))')
|
317
|
+
)
|
318
|
+
))
|
312
319
|
end
|
313
320
|
|
314
321
|
def test_create_bad_multi_polygon
|
@@ -327,11 +334,12 @@ class UtilsTests < Minitest::Test
|
|
327
334
|
|
328
335
|
assert_equal('GEOMETRYCOLLECTION EMPTY', write(Geos.create_geometry_collection))
|
329
336
|
assert_equal('GEOMETRYCOLLECTION (POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0)), POLYGON ((10 10, 10 15, 15 15, 15 10, 10 10)))',
|
330
|
-
write(
|
331
|
-
|
332
|
-
|
337
|
+
write(
|
338
|
+
Geos.create_geometry_collection(
|
339
|
+
read('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'),
|
340
|
+
read('POLYGON((10 10, 10 15, 15 15, 15 10, 10 10))')
|
341
|
+
)
|
333
342
|
))
|
334
|
-
)
|
335
343
|
end
|
336
344
|
|
337
345
|
def test_create_geometry_collection_with_constants_and_symbols
|
@@ -356,7 +364,7 @@ class UtilsTests < Minitest::Test
|
|
356
364
|
def test_create_geometry_collection_with_options
|
357
365
|
skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_geometry_collection)
|
358
366
|
|
359
|
-
geom = Geos.create_collection(:multi_line_string, :
|
367
|
+
geom = Geos.create_collection(:multi_line_string, srid: 4326)
|
360
368
|
|
361
369
|
assert_kind_of(Geos::MultiLineString, geom)
|
362
370
|
assert_equal(4326, geom.srid)
|
@@ -441,6 +449,7 @@ class UtilsTests < Minitest::Test
|
|
441
449
|
[5, 5],
|
442
450
|
[0, 5]
|
443
451
|
])
|
452
|
+
|
444
453
|
Geos.create_linear_ring(cs)
|
445
454
|
GC.start
|
446
455
|
end
|