ffi-geos 0.1.1 → 0.1.2
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 +15 -0
- data/lib/ffi-geos.rb +1 -0
- data/lib/ffi-geos/coordinate_sequence.rb +22 -18
- data/lib/ffi-geos/geometry.rb +19 -16
- data/lib/ffi-geos/point.rb +9 -9
- data/lib/ffi-geos/version.rb +1 -1
- data/test/geometry_collection_tests.rb +46 -44
- data/test/geometry_tests.rb +360 -356
- data/test/line_string_tests.rb +116 -116
- data/test/prepared_geometry_tests.rb +93 -70
- data/test/strtree_tests.rb +161 -142
- data/test/utils_tests.rb +139 -129
- data/test/wkb_writer_tests.rb +8 -9
- data/test/wkt_writer_tests.rb +107 -103
- metadata +10 -14
data/test/utils_tests.rb
CHANGED
@@ -6,31 +6,29 @@ require 'test_helper'
|
|
6
6
|
class UtilsTests < MiniTest::Unit::TestCase
|
7
7
|
include TestHelper
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
9
|
+
def test_orientation_index
|
10
|
+
skip unless ENV['FORCE_TESTS'] || (defined?(Geos::Utils) && Geos::Utils.respond_to?(:orientation_index))
|
11
|
+
|
12
|
+
assert_equal(0, Geos::Utils.orientation_index(0, 0, 10, 0, 5, 0))
|
13
|
+
assert_equal(0, Geos::Utils.orientation_index(0, 0, 10, 0, 10, 0))
|
14
|
+
assert_equal(0, Geos::Utils.orientation_index(0, 0, 10, 0, 0, 0))
|
15
|
+
assert_equal(0, Geos::Utils.orientation_index(0, 0, 10, 0, -5, 0))
|
16
|
+
assert_equal(0, Geos::Utils.orientation_index(0, 0, 10, 0, 20, 0))
|
17
|
+
assert_equal(1, Geos::Utils.orientation_index(0, 0, 10, 10, 5, 6))
|
18
|
+
assert_equal(1, Geos::Utils.orientation_index(0, 0, 10, 10, 5, 20))
|
19
|
+
assert_equal(-1, Geos::Utils.orientation_index(0, 0, 10, 10, 5, 3))
|
20
|
+
assert_equal(-1, Geos::Utils.orientation_index(0, 0, 10, 10, 5, -2))
|
21
|
+
assert_equal(1, Geos::Utils.orientation_index(0, 0, 10, 10, 1000000, 1000001))
|
22
|
+
assert_equal(-1, Geos::Utils.orientation_index(0, 0, 10, 10, 1000000, 999999))
|
23
|
+
end
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
25
|
+
def test_relate_match
|
26
|
+
skip unless ENV['FORCE_TESTS'] || (defined?(Geos::Utils) && Geos::Utils.respond_to?(:relate_match))
|
27
|
+
|
28
|
+
assert(Geos::Utils.relate_match('0FFFFFFF2', '0FFFFFFF2'), "'0FFFFFFF2' and '0FFFFFFF2' patterns match")
|
29
|
+
assert(Geos::Utils.relate_match('0FFFFFFF2', '0FFFFFFF*'), "'0FFFFFFF2' and '0FFFFFFF*' patterns match")
|
30
|
+
assert(Geos::Utils.relate_match('0FFFFFFF2', 'TFFFFFFF2'), "'0FFFFFFF2' and 'TFFFFFFF2' patterns match")
|
31
|
+
assert(!Geos::Utils.relate_match('0FFFFFFF2', '0FFFFFFFF'), "'0FFFFFFF2' and '0FFFFFFFF' patterns match")
|
34
32
|
end
|
35
33
|
|
36
34
|
def create_method_tester(expected, method, cs, type_id, klass)
|
@@ -264,147 +262,159 @@ class UtilsTests < MiniTest::Unit::TestCase
|
|
264
262
|
assert_equal(1, geom.num_geometries)
|
265
263
|
end
|
266
264
|
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
265
|
+
def test_create_multi_point
|
266
|
+
skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_multi_point)
|
267
|
+
|
268
|
+
writer.rounding_precision = 0
|
269
|
+
assert_equal('MULTIPOINT EMPTY', write(Geos.create_multi_point))
|
270
|
+
assert_equal('MULTIPOINT (0 0, 10 10)', write(Geos.create_multi_point(
|
271
|
+
read('POINT(0 0)'),
|
272
|
+
read('POINT(10 10)')
|
273
|
+
)))
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_create_bad_multi_point
|
277
|
+
skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_multi_point)
|
278
|
+
|
279
|
+
assert_raises(TypeError) do
|
280
|
+
Geos.create_multi_point(
|
272
281
|
read('POINT(0 0)'),
|
273
|
-
read('
|
274
|
-
)
|
282
|
+
read('POLYGON((10 10, 10 15, 15 15, 15 10, 10 10))')
|
283
|
+
)
|
275
284
|
end
|
285
|
+
end
|
276
286
|
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
287
|
+
def test_create_multi_line_string
|
288
|
+
skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_multi_line_string)
|
289
|
+
|
290
|
+
writer.rounding_precision = 0
|
291
|
+
assert_equal('MULTILINESTRING EMPTY', write(Geos.create_multi_line_string))
|
292
|
+
assert_equal('MULTILINESTRING ((0 0, 10 10), (10 10, 20 20))', write(Geos.create_multi_line_string(
|
293
|
+
read('LINESTRING(0 0, 10 10)'),
|
294
|
+
read('LINESTRING(10 10, 20 20)')
|
295
|
+
)))
|
285
296
|
end
|
286
297
|
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
read('
|
293
|
-
read('LINESTRING(
|
294
|
-
)
|
298
|
+
def test_create_bad_multi_line_string
|
299
|
+
skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_multi_line_string)
|
300
|
+
|
301
|
+
assert_raises(TypeError) do
|
302
|
+
Geos.create_multi_point(
|
303
|
+
read('POINT(0 0)'),
|
304
|
+
read('LINESTRING(0 0, 10 0)')
|
305
|
+
)
|
295
306
|
end
|
307
|
+
end
|
308
|
+
|
309
|
+
def test_create_multi_polygon
|
310
|
+
skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_multi_polygon)
|
311
|
+
|
312
|
+
writer.rounding_precision = 0
|
313
|
+
assert_equal('MULTIPOLYGON EMPTY', write(Geos.create_multi_polygon))
|
314
|
+
assert_equal('MULTIPOLYGON (((0 0, 0 5, 5 5, 5 0, 0 0)), ((10 10, 10 15, 15 15, 15 10, 10 10)))', write(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
|
+
end
|
319
|
+
|
320
|
+
def test_create_bad_multi_polygon
|
321
|
+
skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_multi_polygon)
|
296
322
|
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
)
|
303
|
-
end
|
323
|
+
assert_raises(TypeError) do
|
324
|
+
Geos.create_multi_polygon(
|
325
|
+
read('POINT(0 0)'),
|
326
|
+
read('POLYGON((10 10, 10 15, 15 15, 15 10, 10 10))')
|
327
|
+
)
|
304
328
|
end
|
305
329
|
end
|
306
330
|
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
331
|
+
def test_create_geometry_collection
|
332
|
+
skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_geometry_collection)
|
333
|
+
|
334
|
+
writer.rounding_precision = 0
|
335
|
+
assert_equal('GEOMETRYCOLLECTION EMPTY', write(Geos.create_geometry_collection))
|
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)))',
|
337
|
+
write(Geos.create_geometry_collection(
|
312
338
|
read('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'),
|
313
339
|
read('POLYGON((10 10, 10 15, 15 15, 15 10, 10 10))')
|
314
|
-
))
|
315
|
-
|
340
|
+
))
|
341
|
+
)
|
342
|
+
end
|
316
343
|
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
)
|
323
|
-
end
|
324
|
-
end
|
344
|
+
def test_create_geometry_collection_with_constants_and_symbols
|
345
|
+
skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_geometry_collection)
|
346
|
+
|
347
|
+
assert_kind_of(Geos::MultiLineString, Geos.create_collection(Geos::GeomTypes::GEOS_MULTILINESTRING))
|
348
|
+
assert_kind_of(Geos::MultiLineString, Geos.create_collection(:multi_line_string))
|
325
349
|
end
|
326
350
|
|
327
|
-
|
328
|
-
|
329
|
-
writer.rounding_precision = 0
|
330
|
-
assert_equal('GEOMETRYCOLLECTION EMPTY', write(Geos.create_geometry_collection))
|
331
|
-
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)))',
|
332
|
-
write(Geos.create_geometry_collection(
|
333
|
-
read('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'),
|
334
|
-
read('POLYGON((10 10, 10 15, 15 15, 15 10, 10 10))')
|
335
|
-
))
|
336
|
-
)
|
337
|
-
end
|
351
|
+
def test_create_bad_geometry_collection
|
352
|
+
skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_geometry_collection)
|
338
353
|
|
339
|
-
|
340
|
-
|
341
|
-
|
354
|
+
assert_raises(TypeError) do
|
355
|
+
Geos.create_geometry_collection(
|
356
|
+
read('POINT(0 0)'),
|
357
|
+
read('POLYGON((10 10, 10 15, 15 15, 15 10, 10 10))'),
|
358
|
+
'gibberish'
|
359
|
+
)
|
342
360
|
end
|
361
|
+
end
|
343
362
|
|
344
|
-
|
345
|
-
|
346
|
-
Geos.create_geometry_collection(
|
347
|
-
read('POINT(0 0)'),
|
348
|
-
read('POLYGON((10 10, 10 15, 15 15, 15 10, 10 10))'),
|
349
|
-
'gibberish'
|
350
|
-
)
|
351
|
-
end
|
352
|
-
end
|
363
|
+
def test_create_geometry_collection_with_options
|
364
|
+
skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_geometry_collection)
|
353
365
|
|
354
|
-
|
355
|
-
geom = Geos.create_collection(:multi_line_string, :srid => 4326)
|
366
|
+
geom = Geos.create_collection(:multi_line_string, :srid => 4326)
|
356
367
|
|
357
|
-
|
358
|
-
|
359
|
-
end
|
368
|
+
assert_kind_of(Geos::MultiLineString, geom)
|
369
|
+
assert_equal(4326, geom.srid)
|
360
370
|
end
|
361
371
|
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
372
|
+
def test_create_empty_point
|
373
|
+
skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_empty_point)
|
374
|
+
|
375
|
+
assert_equal('POINT EMPTY', write(Geos.create_empty_point))
|
366
376
|
end
|
367
377
|
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
378
|
+
def test_create_empty_line_string
|
379
|
+
skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_empty_line_string)
|
380
|
+
|
381
|
+
assert_equal('LINESTRING EMPTY', write(Geos.create_empty_line_string))
|
372
382
|
end
|
373
383
|
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
384
|
+
def test_create_empty_polygon
|
385
|
+
skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_empty_polygon)
|
386
|
+
|
387
|
+
assert_equal('POLYGON EMPTY', write(Geos.create_empty_polygon))
|
378
388
|
end
|
379
389
|
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
390
|
+
def test_create_empty_multi_point
|
391
|
+
skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_multi_point)
|
392
|
+
|
393
|
+
assert_equal('MULTIPOINT EMPTY', write(Geos.create_empty_multi_point))
|
384
394
|
end
|
385
395
|
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
396
|
+
def test_create_empty_multi_line_string
|
397
|
+
skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_empty_multi_line_string)
|
398
|
+
|
399
|
+
assert_equal('MULTILINESTRING EMPTY', write(Geos.create_empty_multi_line_string))
|
390
400
|
end
|
391
401
|
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
402
|
+
def test_create_empty_multi_polygon
|
403
|
+
skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_empty_multi_polygon)
|
404
|
+
|
405
|
+
assert_equal('MULTIPOLYGON EMPTY', write(Geos.create_empty_multi_polygon))
|
396
406
|
end
|
397
407
|
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
408
|
+
def test_create_empty_geometry_collection
|
409
|
+
skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_empty_geometry_collection)
|
410
|
+
|
411
|
+
assert_equal('GEOMETRYCOLLECTION EMPTY', write(Geos.create_empty_geometry_collection))
|
402
412
|
end
|
403
413
|
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
414
|
+
def test_create_empty_linear_ring
|
415
|
+
skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_empty_linear_ring)
|
416
|
+
|
417
|
+
assert_equal('LINEARRING EMPTY', write(Geos.create_empty_linear_ring))
|
408
418
|
end
|
409
419
|
|
410
420
|
def test_create_geometry_segfault
|
data/test/wkb_writer_tests.rb
CHANGED
@@ -426,18 +426,17 @@ class WkbWriterTests < MiniTest::Unit::TestCase
|
|
426
426
|
end
|
427
427
|
end
|
428
428
|
|
429
|
-
|
430
|
-
|
431
|
-
geom = read('POINT(1 2 3)')
|
432
|
-
geom.srid = 4326
|
429
|
+
def test_write_with_options
|
430
|
+
skip unless ENV['FORCE_TESTS'] || defined?(Geos::FFIGeos)
|
433
431
|
|
432
|
+
geom = read('POINT(1 2 3)')
|
433
|
+
geom.srid = 4326
|
434
434
|
|
435
|
-
|
436
|
-
|
437
|
-
|
435
|
+
assert_equal('0101000020E6100000000000000000F03F0000000000000040', @wkb_writer.write_hex(geom, {
|
436
|
+
:include_srid => true
|
437
|
+
}))
|
438
438
|
|
439
|
-
|
440
|
-
end
|
439
|
+
assert_equal('0101000000000000000000F03F0000000000000040', @wkb_writer.write_hex(geom))
|
441
440
|
end
|
442
441
|
|
443
442
|
def test_illegal_output_dimensions
|
data/test/wkt_writer_tests.rb
CHANGED
@@ -18,139 +18,143 @@ class WktWriterTests < MiniTest::Unit::TestCase
|
|
18
18
|
assert_in_delta(98.7654321, y, TOLERANCE)
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
geom = read('POINT(6 7)')
|
21
|
+
def test_trim
|
22
|
+
skip unless ENV['FORCE_TESTS'] || Geos::WktWriter.method_defined?(:trim=)
|
24
23
|
|
25
|
-
|
26
|
-
assert_equal('POINT (6 7)', write(geom))
|
24
|
+
geom = read('POINT(6 7)')
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
writer.trim = true
|
27
|
+
assert_equal('POINT (6 7)', write(geom))
|
28
|
+
|
29
|
+
writer.trim = false
|
30
|
+
assert_equal('POINT (6.0000000000000000 7.0000000000000000)', write(geom))
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
33
|
+
def test_round_trip
|
34
|
+
skip unless ENV['FORCE_TESTS'] || Geos::WktWriter.method_defined?(:trim=)
|
35
|
+
|
36
|
+
writer.trim = true
|
37
|
+
|
38
|
+
[
|
39
|
+
'POINT (0 0)',
|
40
|
+
'POINT EMPTY',
|
41
|
+
'MULTIPOINT (0 1, 2 3)',
|
42
|
+
'MULTIPOINT EMPTY',
|
43
|
+
'LINESTRING (0 0, 2 3)',
|
44
|
+
'LINESTRING EMPTY',
|
45
|
+
'MULTILINESTRING ((0 1, 2 3), (10 10, 3 4))',
|
46
|
+
'MULTILINESTRING EMPTY',
|
47
|
+
'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))',
|
48
|
+
'POLYGON EMPTY',
|
49
|
+
'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)))',
|
50
|
+
'MULTIPOLYGON EMPTY',
|
51
|
+
'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))',
|
52
|
+
'GEOMETRYCOLLECTION EMPTY'
|
53
|
+
].each do |g|
|
54
|
+
assert_equal(g, write(read(g)))
|
53
55
|
end
|
54
56
|
end
|
55
57
|
|
56
|
-
|
57
|
-
|
58
|
-
geom = read('POINT(6.123456 7.123456)')
|
58
|
+
def test_rounding_precision
|
59
|
+
skip unless ENV['FORCE_TESTS'] || Geos::WktWriter.method_defined?(:rounding_precision=)
|
59
60
|
|
60
|
-
|
61
|
-
writer.rounding_precision = precision if precision
|
62
|
-
assert_equal(expected, write(geom))
|
63
|
-
}
|
61
|
+
geom = read('POINT(6.123456 7.123456)')
|
64
62
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
tester['POINT (6 7)', 0]
|
70
|
-
end
|
63
|
+
tester = lambda { |expected, precision|
|
64
|
+
writer.rounding_precision = precision if precision
|
65
|
+
assert_equal(expected, write(geom))
|
66
|
+
}
|
71
67
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
68
|
+
tester['POINT (6.1234560000000000 7.1234560000000000)', nil]
|
69
|
+
tester['POINT (6.12 7.12)', 2]
|
70
|
+
tester['POINT (6.12346 7.12346)', 5]
|
71
|
+
tester['POINT (6.1 7.1)', 1]
|
72
|
+
tester['POINT (6 7)', 0]
|
77
73
|
end
|
78
74
|
|
79
|
-
|
80
|
-
|
81
|
-
|
75
|
+
def test_rounding_precision_too_high
|
76
|
+
assert_raises(RuntimeError) do
|
77
|
+
@writer.rounding_precision = 1000
|
82
78
|
end
|
83
79
|
end
|
84
80
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
81
|
+
def test_output_dimensions
|
82
|
+
skip unless ENV['FORCE_TESTS'] || Geos::WktWriter.method_defined?(:output_dimensions)
|
83
|
+
|
84
|
+
assert_equal(2, writer.output_dimensions)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_output_dimensions_set
|
88
|
+
skip unless ENV['FORCE_TESTS'] || Geos::WktWriter.method_defined?(:output_dimensions=)
|
89
89
|
|
90
|
-
|
90
|
+
geom_3d = read('POINT(1 2 3)')
|
91
|
+
geom_2d = read('POINT(3 2)')
|
91
92
|
|
92
|
-
|
93
|
-
assert_equal('POINT (1 2)', write(geom_3d))
|
93
|
+
writer.trim = true
|
94
94
|
|
95
|
-
|
96
|
-
|
97
|
-
assert_equal('POINT Z (1 2 3)', write(geom_3d))
|
98
|
-
assert_equal('POINT (3 2)', write(geom_2d))
|
95
|
+
# Only 2d by default
|
96
|
+
assert_equal('POINT (1 2)', write(geom_3d))
|
99
97
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
98
|
+
# 3d if requested _and_ available
|
99
|
+
writer.output_dimensions = 3
|
100
|
+
assert_equal('POINT Z (1 2 3)', write(geom_3d))
|
101
|
+
assert_equal('POINT (3 2)', write(geom_2d))
|
104
102
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
end
|
103
|
+
# 1 is invalid
|
104
|
+
assert_raises(RuntimeError) do
|
105
|
+
writer.output_dimensions = 1
|
109
106
|
end
|
110
107
|
|
111
|
-
|
112
|
-
|
108
|
+
# 4 is invalid
|
109
|
+
assert_raises(RuntimeError) do
|
110
|
+
writer.output_dimensions = 4
|
111
|
+
end
|
112
|
+
end
|
113
113
|
|
114
|
-
|
115
|
-
|
116
|
-
:trim => true
|
117
|
-
}))
|
114
|
+
def test_write_with_options
|
115
|
+
skip unless ENV['FORCE_TESTS'] || defined?(Geos::FFIGeos)
|
118
116
|
|
119
|
-
|
120
|
-
:rounding_precision => 4
|
121
|
-
}))
|
117
|
+
@writer.rounding_precision = 2
|
122
118
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
119
|
+
geom = read('POINT(1 2 3)')
|
120
|
+
assert_equal('POINT (1 2)', write(geom, {
|
121
|
+
:trim => true
|
122
|
+
}))
|
127
123
|
|
128
|
-
|
129
|
-
|
124
|
+
assert_equal('POINT (1.0000 2.0000)', write(geom, {
|
125
|
+
:rounding_precision => 4
|
126
|
+
}))
|
127
|
+
|
128
|
+
assert_equal('POINT Z (1 2 3)', write(geom, {
|
129
|
+
:output_dimensions => 3,
|
130
|
+
:trim => true
|
131
|
+
}))
|
132
|
+
|
133
|
+
assert_equal('POINT (1.00 2.00)', write(geom))
|
130
134
|
end
|
131
135
|
|
132
|
-
|
133
|
-
|
134
|
-
geom_3d = read('POINT(1 2 3)')
|
135
|
-
writer.trim = true
|
136
|
+
def test_old_3d_set
|
137
|
+
skip unless ENV['FORCE_TESTS'] || Geos::WktWriter.method_defined?(:old_3d=)
|
136
138
|
|
137
|
-
|
138
|
-
|
139
|
-
assert_equal('POINT Z (1 2 3)', write(geom_3d))
|
139
|
+
geom_3d = read('POINT(1 2 3)')
|
140
|
+
writer.trim = true
|
140
141
|
|
141
|
-
|
142
|
-
|
143
|
-
|
142
|
+
# New 3d WKT by default
|
143
|
+
writer.output_dimensions = 3
|
144
|
+
assert_equal('POINT Z (1 2 3)', write(geom_3d))
|
144
145
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
writer.output_dimensions = 3
|
149
|
-
assert_equal('POINT (1 2 3)', write(geom_3d))
|
146
|
+
# Switch to old
|
147
|
+
writer.old_3d = true
|
148
|
+
assert_equal('POINT (1 2 3)', write(geom_3d))
|
150
149
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
150
|
+
# Old3d flag is not reset when changing dimensions
|
151
|
+
writer.output_dimensions = 2
|
152
|
+
assert_equal('POINT (1 2)', write(geom_3d))
|
153
|
+
writer.output_dimensions = 3
|
154
|
+
assert_equal('POINT (1 2 3)', write(geom_3d))
|
155
|
+
|
156
|
+
# Likewise, dimensions spec is not reset when changing old3d flag
|
157
|
+
writer.old_3d = false
|
158
|
+
assert_equal('POINT Z (1 2 3)', write(geom_3d))
|
155
159
|
end
|
156
160
|
end
|