ffi-geos 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +21 -3
- data/ffi-geos.gemspec +2 -0
- data/lib/ffi-geos.rb +90 -13
- data/lib/ffi-geos/coordinate_sequence.rb +29 -14
- data/lib/ffi-geos/geometry.rb +77 -42
- data/lib/ffi-geos/geometry_collection.rb +6 -2
- data/lib/ffi-geos/line_string.rb +13 -3
- data/lib/ffi-geos/linear_ring.rb +3 -0
- data/lib/ffi-geos/point.rb +60 -2
- data/lib/ffi-geos/polygon.rb +13 -2
- data/lib/ffi-geos/tools.rb +35 -2
- data/lib/ffi-geos/utils.rb +120 -62
- data/lib/ffi-geos/version.rb +1 -1
- data/lib/ffi-geos/wkb_reader.rb +8 -4
- data/lib/ffi-geos/wkt_reader.rb +4 -2
- data/test/coordinate_sequence_tests.rb +81 -27
- data/test/geometry_collection_tests.rb +79 -0
- data/test/geometry_tests.rb +235 -249
- data/test/line_string_tests.rb +167 -0
- data/test/linear_ring_tests.rb +24 -0
- data/test/misc_tests.rb +3 -3
- data/test/point_tests.rb +62 -1
- data/test/polygon_tests.rb +36 -0
- data/test/prepared_geometry_tests.rb +4 -4
- data/test/strtree_tests.rb +6 -6
- data/test/test_helper.rb +48 -1
- data/test/utils_tests.rb +116 -34
- data/test/wkb_reader_tests.rb +24 -4
- data/test/wkb_writer_tests.rb +5 -5
- data/test/wkt_reader_tests.rb +10 -5
- data/test/wkt_writer_tests.rb +3 -3
- metadata +43 -3
@@ -0,0 +1,167 @@
|
|
1
|
+
|
2
|
+
$: << File.dirname(__FILE__)
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class LineStringTests < MiniTest::Unit::TestCase
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def test_default_srid
|
9
|
+
geom = read('LINESTRING (0 0, 10 10)')
|
10
|
+
assert_equal(0, geom.srid)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_setting_srid_manually
|
14
|
+
geom = read('LINESTRING (0 0, 10 10)')
|
15
|
+
geom.srid = 4326
|
16
|
+
assert_equal(4326, geom.srid)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_dimensions
|
20
|
+
geom = read('LINESTRING (0 0, 10 10)')
|
21
|
+
assert_equal(1, geom.dimensions)
|
22
|
+
|
23
|
+
geom = read('LINESTRING (0 0 0, 10 10 10)')
|
24
|
+
assert_equal(1, geom.dimensions)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_num_geometries
|
28
|
+
geom = read('LINESTRING (0 0, 10 10)')
|
29
|
+
assert_equal(1, geom.num_geometries)
|
30
|
+
end
|
31
|
+
|
32
|
+
if ENV['FORCE_TESTS'] || Geos::LineString.method_defined?(:[])
|
33
|
+
def test_line_string_array
|
34
|
+
writer.trim = true
|
35
|
+
geom = read('LINESTRING(0 0, 1 1, 2 2, 3 3, 4 4)')
|
36
|
+
|
37
|
+
assert_equal('POINT (0 0)', write(geom[0]))
|
38
|
+
assert_equal('POINT (4 4)', write(geom[-1]))
|
39
|
+
|
40
|
+
assert_equal([
|
41
|
+
'POINT (0 0)',
|
42
|
+
'POINT (1 1)'
|
43
|
+
], geom[0, 2].collect { |g| write(g) })
|
44
|
+
|
45
|
+
assert_equal(nil, geom[0, -1])
|
46
|
+
assert_equal([], geom[-1, 0])
|
47
|
+
assert_equal([
|
48
|
+
'POINT (1 1)',
|
49
|
+
'POINT (2 2)'
|
50
|
+
], geom[1..2].collect { |g| write(g) })
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
if ENV['FORCE_TESTS'] || Geos::LineString.method_defined?(:select)
|
55
|
+
def test_line_string_enumerable
|
56
|
+
writer.trim = true
|
57
|
+
geom = read('LINESTRING(0 0, 1 1, 2 2, 3 3, 10 0, 2 2)')
|
58
|
+
|
59
|
+
assert_equal(2, geom.select { |point| point == read('POINT(2 2)') }.length)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
if ENV['FORCE_TESTS'] || Geos::LineString.method_defined?(:offset_curve)
|
64
|
+
def test_offset_curve
|
65
|
+
tester = lambda { |expected, g, width, style|
|
66
|
+
geom = read(g)
|
67
|
+
buffered = geom.offset_curve(width, style)
|
68
|
+
|
69
|
+
assert_equal(expected, write(buffered))
|
70
|
+
}
|
71
|
+
|
72
|
+
writer.rounding_precision = 0
|
73
|
+
|
74
|
+
# straight left
|
75
|
+
tester[
|
76
|
+
'LINESTRING (0 2, 10 2)',
|
77
|
+
'LINESTRING (0 0, 10 0)',
|
78
|
+
2, {
|
79
|
+
:quad_segs => 0,
|
80
|
+
:join => :round,
|
81
|
+
:mitre_limit => 2
|
82
|
+
}
|
83
|
+
]
|
84
|
+
|
85
|
+
# straight right
|
86
|
+
tester[
|
87
|
+
'LINESTRING (10 -2, 0 -2)',
|
88
|
+
'LINESTRING (0 0, 10 0)',
|
89
|
+
-2, {
|
90
|
+
:quad_segs => 0,
|
91
|
+
:join => :round,
|
92
|
+
:mitre_limit => 2
|
93
|
+
}
|
94
|
+
]
|
95
|
+
|
96
|
+
# outside curve
|
97
|
+
tester[
|
98
|
+
'LINESTRING (12 10, 12 0, 10 -2, 0 -2)',
|
99
|
+
'LINESTRING (0 0, 10 0, 10 10)',
|
100
|
+
-2, {
|
101
|
+
:quad_segs => 1,
|
102
|
+
:join => :round,
|
103
|
+
:mitre_limit => 2
|
104
|
+
}
|
105
|
+
]
|
106
|
+
|
107
|
+
# inside curve
|
108
|
+
tester[
|
109
|
+
'LINESTRING (0 2, 8 2, 8 10)',
|
110
|
+
'LINESTRING (0 0, 10 0, 10 10)',
|
111
|
+
2, {
|
112
|
+
:quad_segs => 1,
|
113
|
+
:join => :round,
|
114
|
+
:mitre_limit => 2
|
115
|
+
}
|
116
|
+
]
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
if ENV['FORCE_TESTS'] || Geos::LineString.method_defined?(:closed?)
|
121
|
+
def test_closed
|
122
|
+
assert_geom_closed(read('LINESTRING(0 0, 1 1, 2 2, 0 0)'))
|
123
|
+
refute_geom_closed(read('LINESTRING(0 0, 1 1, 2 2)'))
|
124
|
+
assert_geom_closed(read('LINEARRING(0 0, 1 1, 2 2, 0 0)'))
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
if ENV['FORCE_TESTS'] || Geos::LineString.method_defined?(:num_points)
|
129
|
+
def test_num_points
|
130
|
+
assert_equal(4, read('LINESTRING (0 0, 1 0, 1 1, 0 1)').num_points)
|
131
|
+
|
132
|
+
assert_raises(NoMethodError) do
|
133
|
+
read('POINT (0 0)').num_points
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
if ENV['FORCE_TESTS'] || Geos::LineString.method_defined?(:point_n)
|
139
|
+
def test_point_n
|
140
|
+
writer.rounding_precision = 0
|
141
|
+
|
142
|
+
tester = lambda { |expected, geom, n|
|
143
|
+
assert_equal(expected, write(geom.point_n(n)))
|
144
|
+
}
|
145
|
+
|
146
|
+
geom = read('LINESTRING (10 10, 10 14, 14 14, 14 10)')
|
147
|
+
tester['POINT (10 10)', geom, 0]
|
148
|
+
tester['POINT (10 14)', geom, 1]
|
149
|
+
tester['POINT (14 14)', geom, 2]
|
150
|
+
tester['POINT (14 10)', geom, 3]
|
151
|
+
|
152
|
+
assert_raises(RuntimeError) do
|
153
|
+
tester['POINT (0 0)', geom, 4]
|
154
|
+
end
|
155
|
+
|
156
|
+
geom = read('LINEARRING (11 11, 11 12, 12 11, 11 11)')
|
157
|
+
tester['POINT (11 11)', geom, 0]
|
158
|
+
tester['POINT (11 12)', geom, 1]
|
159
|
+
tester['POINT (12 11)', geom, 2]
|
160
|
+
tester['POINT (11 11)', geom, 3]
|
161
|
+
|
162
|
+
assert_raises(NoMethodError) do
|
163
|
+
tester[nil, read('POINT (0 0)'), 0]
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
$: << File.dirname(__FILE__)
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class LinearRingTests < MiniTest::Unit::TestCase
|
5
|
+
include TestHelper
|
6
|
+
|
7
|
+
def test_to_polygon
|
8
|
+
geom = read('POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0))')
|
9
|
+
ring = geom.exterior_ring
|
10
|
+
|
11
|
+
assert_equal(write(geom), write(ring.to_polygon))
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_to_polygon_with_srid
|
15
|
+
writer.trim = true
|
16
|
+
|
17
|
+
wkt = 'LINEARRING (0 0, 5 0, 5 5, 0 5, 0 0)'
|
18
|
+
expected = 'POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0))'
|
19
|
+
|
20
|
+
srid_copy_tester(:to_polygon, expected, 0, :zero, wkt)
|
21
|
+
srid_copy_tester(:to_polygon, expected, 4326, :lenient, wkt)
|
22
|
+
srid_copy_tester(:to_polygon, expected, 4326, :strict, wkt)
|
23
|
+
end
|
24
|
+
end
|
data/test/misc_tests.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
$: << File.dirname(__FILE__)
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
|
-
class MiscTests <
|
5
|
+
class MiscTests < MiniTest::Unit::TestCase
|
6
6
|
include TestHelper
|
7
7
|
|
8
8
|
def thread_tester(name, dims, byte_order, polygon, pause)
|
@@ -85,13 +85,13 @@ class MiscTests < Test::Unit::TestCase
|
|
85
85
|
end
|
86
86
|
|
87
87
|
def test_cant_clone_buffer_params
|
88
|
-
|
88
|
+
assert_raises(NoMethodError) do
|
89
89
|
Geos::BufferParams.new.clone
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
93
|
def test_cant_dup_buffer_params
|
94
|
-
|
94
|
+
assert_raises(NoMethodError) do
|
95
95
|
Geos::BufferParams.new.dup
|
96
96
|
end
|
97
97
|
end
|
data/test/point_tests.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
$: << File.dirname(__FILE__)
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
|
-
class PointTests <
|
5
|
+
class PointTests < MiniTest::Unit::TestCase
|
6
6
|
include TestHelper
|
7
7
|
|
8
8
|
def test_default_srid
|
@@ -28,4 +28,65 @@ class PointTests < Test::Unit::TestCase
|
|
28
28
|
geom = read('POINT(1 2)')
|
29
29
|
assert_equal(1, geom.num_geometries)
|
30
30
|
end
|
31
|
+
|
32
|
+
def test_get_x
|
33
|
+
geom = read('POINT (1 2)')
|
34
|
+
assert_equal(1, geom.get_x)
|
35
|
+
assert_equal(1, geom.x)
|
36
|
+
|
37
|
+
assert_raises(NoMethodError) do
|
38
|
+
read('LINESTRING (0 0, 1 1)').get_x
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_get_y
|
43
|
+
geom = read('POINT (1 2)')
|
44
|
+
assert_equal(2, geom.get_y)
|
45
|
+
assert_equal(2, geom.y)
|
46
|
+
|
47
|
+
assert_raises(NoMethodError) do
|
48
|
+
read('LINESTRING (0 0, 1 1)').get_x
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_get_z
|
53
|
+
geom = read('POINT Z (1 2 3)')
|
54
|
+
assert_equal(3, geom.get_z)
|
55
|
+
assert_equal(3, geom.z)
|
56
|
+
assert_raises(NoMethodError) do
|
57
|
+
read('LINESTRING (0 0, 1 1)').get_z
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_simplify_clone_srid_correctly
|
62
|
+
geom = read('POINT (0 0)')
|
63
|
+
geom.srid = 4326
|
64
|
+
|
65
|
+
Geos.srid_copy_policy = :zero
|
66
|
+
assert_equal(0, geom.simplify(0.1).srid)
|
67
|
+
|
68
|
+
Geos.srid_copy_policy = :lenient
|
69
|
+
assert_equal(4326, geom.simplify(0.1).srid)
|
70
|
+
|
71
|
+
Geos.srid_copy_policy = :strict
|
72
|
+
assert_equal(4326, geom.simplify(0.1).srid)
|
73
|
+
ensure
|
74
|
+
Geos.srid_copy_policy = :default
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_extract_unique_points_clone_srid_correctly
|
78
|
+
geom = read('POINT (0 0)')
|
79
|
+
geom.srid = 4326
|
80
|
+
|
81
|
+
Geos.srid_copy_policy = :zero
|
82
|
+
assert_equal(0, geom.extract_unique_points.srid)
|
83
|
+
|
84
|
+
Geos.srid_copy_policy = :lenient
|
85
|
+
assert_equal(4326, geom.extract_unique_points.srid)
|
86
|
+
|
87
|
+
Geos.srid_copy_policy = :strict
|
88
|
+
assert_equal(4326, geom.extract_unique_points.srid)
|
89
|
+
ensure
|
90
|
+
Geos.srid_copy_policy = :default
|
91
|
+
end
|
31
92
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
$: << File.dirname(__FILE__)
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class PolygonTests < MiniTest::Unit::TestCase
|
6
|
+
include TestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
writer.rounding_precision = 2
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_default_srid
|
14
|
+
geom = read('POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0))')
|
15
|
+
assert_equal(0, geom.srid)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_setting_srid_manually
|
19
|
+
geom = read('POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0))')
|
20
|
+
geom.srid = 4326
|
21
|
+
assert_equal(4326, geom.srid)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_dimensions
|
25
|
+
geom = read('POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0))')
|
26
|
+
assert_equal(2, geom.dimensions)
|
27
|
+
|
28
|
+
geom = read('POLYGON ((0 0 0, 5 0 0, 5 5 0, 0 5 0, 0 0 0))')
|
29
|
+
assert_equal(2, geom.dimensions)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_num_geometries
|
33
|
+
geom = read('POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0))')
|
34
|
+
assert_equal(1, geom.num_geometries)
|
35
|
+
end
|
36
|
+
end
|
@@ -3,7 +3,7 @@ $: << File.dirname(__FILE__)
|
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
5
|
if defined?(Geos::PreparedGeometry)
|
6
|
-
class PreparedGeometryTests <
|
6
|
+
class PreparedGeometryTests < MiniTest::Unit::TestCase
|
7
7
|
include TestHelper
|
8
8
|
|
9
9
|
POINT_A = 'POINT(0 0)'
|
@@ -72,19 +72,19 @@ if defined?(Geos::PreparedGeometry)
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def test_cant_clone
|
75
|
-
|
75
|
+
assert_raises(NoMethodError) do
|
76
76
|
read(POINT_A).to_prepared.clone
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
80
|
def test_cant_dup
|
81
|
-
|
81
|
+
assert_raises(NoMethodError) do
|
82
82
|
read(POINT_A).to_prepared.dup
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
86
|
def test_initializer_type_exception
|
87
|
-
|
87
|
+
assert_raises(TypeError) do
|
88
88
|
Geos::PreparedGeometry.new('hello world')
|
89
89
|
end
|
90
90
|
end
|
data/test/strtree_tests.rb
CHANGED
@@ -3,7 +3,7 @@ $: << File.dirname(__FILE__)
|
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
5
|
if defined?(Geos::STRtree)
|
6
|
-
class STRtreeTests <
|
6
|
+
class STRtreeTests < MiniTest::Unit::TestCase
|
7
7
|
include TestHelper
|
8
8
|
|
9
9
|
def setup_tree
|
@@ -26,7 +26,7 @@ if defined?(Geos::STRtree)
|
|
26
26
|
|
27
27
|
@tree.query(read('POINT(5 5)'))
|
28
28
|
|
29
|
-
|
29
|
+
assert_raises(RuntimeError) do
|
30
30
|
@tree.insert(read('POINT(0 0)'), 'test')
|
31
31
|
end
|
32
32
|
end
|
@@ -155,13 +155,13 @@ if defined?(Geos::STRtree)
|
|
155
155
|
end
|
156
156
|
|
157
157
|
def test_cant_clone
|
158
|
-
|
158
|
+
assert_raises(NoMethodError) do
|
159
159
|
Geos::STRtree.new(3).clone
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
163
163
|
def test_cant_dup
|
164
|
-
|
164
|
+
assert_raises(NoMethodError) do
|
165
165
|
Geos::STRtree.new(3).dup
|
166
166
|
end
|
167
167
|
end
|
@@ -187,13 +187,13 @@ if defined?(Geos::STRtree)
|
|
187
187
|
end
|
188
188
|
|
189
189
|
def test_capacity
|
190
|
-
|
190
|
+
assert_raises(ArgumentError) do
|
191
191
|
Geos::STRtree.new(0)
|
192
192
|
end
|
193
193
|
end
|
194
194
|
|
195
195
|
def test_geometries
|
196
|
-
|
196
|
+
assert_raises(TypeError) do
|
197
197
|
Geos::STRtree.new([])
|
198
198
|
end
|
199
199
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
|
2
2
|
require 'rubygems'
|
3
|
-
require '
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'turn/autorun'
|
4
5
|
|
5
6
|
if ENV['USE_BINARY_GEOS']
|
6
7
|
require 'geos'
|
@@ -45,4 +46,50 @@ module TestHelper
|
|
45
46
|
def write(*args)
|
46
47
|
writer.write(*args)
|
47
48
|
end
|
49
|
+
|
50
|
+
def srid_copy_tester(method, expected, expected_srid, srid_policy, wkt, *args)
|
51
|
+
geom = read(wkt)
|
52
|
+
geom.srid = 4326
|
53
|
+
|
54
|
+
Geos.srid_copy_policy = srid_policy
|
55
|
+
geom_b = geom.send(method, *args)
|
56
|
+
|
57
|
+
assert_equal(4326, geom.srid)
|
58
|
+
assert_equal(expected_srid, geom_b.srid)
|
59
|
+
assert_equal(expected, write(geom_b))
|
60
|
+
ensure
|
61
|
+
Geos.srid_copy_policy = :default
|
62
|
+
end
|
63
|
+
|
64
|
+
{
|
65
|
+
:empty => 'to be empty',
|
66
|
+
:valid => 'to be valid',
|
67
|
+
:simple => 'to be simple',
|
68
|
+
:ring => 'to be ring',
|
69
|
+
:closed => 'to be closed',
|
70
|
+
:has_z => 'to have z dimension'
|
71
|
+
}.each do |t, m|
|
72
|
+
self.class_eval(<<-EOF, __FILE__, __LINE__ + 1)
|
73
|
+
def assert_geom_#{t}(geom)
|
74
|
+
assert(geom.#{t}?, "Expected geom #{m}")
|
75
|
+
end
|
76
|
+
|
77
|
+
def refute_geom_#{t}(geom)
|
78
|
+
assert(!geom.#{t}?, "Did not expect geom #{m}")
|
79
|
+
end
|
80
|
+
EOF
|
81
|
+
end
|
82
|
+
|
83
|
+
def assert_geom_eql_exact(geom, result, tolerance = TOLERANCE)
|
84
|
+
assert(geom.eql_exact?(result, tolerance), "Expected geom.eql_exact? to be within #{tolerance}")
|
85
|
+
end
|
48
86
|
end
|
87
|
+
|
88
|
+
if ENV['autotest']
|
89
|
+
module Turn::Colorize
|
90
|
+
def self.color_supported?
|
91
|
+
true
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|