ffi-geos 0.0.1.beta1

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.
@@ -0,0 +1,120 @@
1
+
2
+ $: << File.dirname(__FILE__)
3
+ require 'test_helper'
4
+
5
+ class WktReaderTests < Test::Unit::TestCase
6
+ include TestHelper
7
+
8
+ def wkt_tester(type_id, geom_type, klass, *geoms)
9
+ geoms.each do |g|
10
+ geom = read(g)
11
+ assert(geom)
12
+ assert_equal(type_id, geom.type_id)
13
+ assert_equal(geom_type, geom.geom_type)
14
+ assert(geom.is_a?(klass))
15
+ end
16
+ end
17
+
18
+ def test_read_point
19
+ wkt_tester(
20
+ Geos::GEOS_POINT,
21
+ 'Point',
22
+ Geos::Point,
23
+
24
+ 'POINT(0 0)',
25
+ 'POINT(0 0 0)',
26
+ 'POINT Z(0 0 0)',
27
+ 'POINT EMPTY'
28
+ )
29
+ end
30
+
31
+ def test_read_multi_point
32
+ wkt_tester(
33
+ Geos::GEOS_MULTIPOINT,
34
+ 'MultiPoint',
35
+ Geos::MultiPoint,
36
+ 'MULTIPOINT(0 0 1, 2 3 4)',
37
+ 'MULTIPOINT Z (0 0 1, 2 3 4)',
38
+ 'MULTIPOINT((0 0), (2 3))',
39
+ 'MULTIPOINT EMPTY'
40
+ )
41
+ end
42
+
43
+ def test_read_linestring
44
+ wkt_tester(
45
+ Geos::GEOS_LINESTRING,
46
+ 'LineString',
47
+ Geos::LineString,
48
+ 'LINESTRING(0 0 1, 2 3 4)',
49
+ 'LINESTRING EMPTY'
50
+ )
51
+ end
52
+
53
+ def test_multi_line_string
54
+ wkt_tester(
55
+ Geos::GEOS_MULTILINESTRING,
56
+ 'MultiLineString',
57
+ Geos::MultiLineString,
58
+ 'MULTILINESTRING((0 0 1, 2 3 4), (10 10 2, 3 4 5))',
59
+ 'MULTILINESTRING Z ((0 0 1, 2 3 4), (10 10 2, 3 4 5))'
60
+ )
61
+ end
62
+
63
+ def test_polygon
64
+ wkt_tester(
65
+ Geos::GEOS_POLYGON,
66
+ 'Polygon',
67
+ Geos::Polygon,
68
+ 'POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))',
69
+ 'POLYGON EMPTY'
70
+ )
71
+ end
72
+
73
+ def test_multi_polygon
74
+ wkt_tester(
75
+ Geos::GEOS_MULTIPOLYGON,
76
+ 'MultiPolygon',
77
+ Geos::MultiPolygon,
78
+ 'MULTIPOLYGON(
79
+ ((0 0, 1 0, 1 1, 0 1, 0 0)),
80
+ ((10 10, 10 14, 14 14, 14 10, 10 10),
81
+ (11 11, 11 12, 12 12, 12 11, 11 11))
82
+ )',
83
+ 'MULTIPOLYGON EMPTY'
84
+ )
85
+ end
86
+
87
+ def test_geometry_collection
88
+ wkt_tester(
89
+ Geos::GEOS_GEOMETRYCOLLECTION,
90
+ 'GeometryCollection',
91
+ Geos::GeometryCollection,
92
+ 'GEOMETRYCOLLECTION(
93
+ MULTIPOLYGON(
94
+ ((0 0, 1 0, 1 1, 0 1, 0 0)),
95
+ ((10 10, 10 14, 14 14, 14 10, 10 10),
96
+ (11 11, 11 12, 12 12, 12 11, 11 11))
97
+ ),
98
+ POLYGON((0 0, 1 0, 1 1, 0 1, 0 0)),
99
+ MULTILINESTRING((0 0, 2 3), (10 10, 3 4)),
100
+ LINESTRING(0 0, 2 3),
101
+ MULTIPOINT(0 0, 2 3),
102
+ POINT(9 0)
103
+ )',
104
+ 'GEOMETRYCOLLECTION EMPTY'
105
+ )
106
+ end
107
+
108
+ def test_read_linearring
109
+ geom = read('LINEARRING(0 0, 1 1, 2 2, 3 3, 0 0)')
110
+ assert_equal(Geos::GEOS_LINEARRING, geom.type_id)
111
+ assert_equal('LinearRing', geom.geom_type)
112
+ assert(geom.is_a?(Geos::LinearRing))
113
+ end
114
+
115
+ def test_read_exception
116
+ assert_raise(RuntimeError) do
117
+ geom = read('gibberish')
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,149 @@
1
+
2
+ $: << File.dirname(__FILE__)
3
+ require 'test_helper'
4
+
5
+ class WktWriterTests < Test::Unit::TestCase
6
+ include TestHelper
7
+
8
+ def test_write_point
9
+ geom = read('POINT(12.3456789 98.7654321)')
10
+ wkt = write(geom)
11
+
12
+ x, y = if wkt =~ /^POINT\s\((\d+\.\d+)\s*(\d+\.\d+)\)$/
13
+ [ $1.to_f, $2.to_f ]
14
+ end
15
+
16
+ assert_in_delta(12.3456789, x, TOLERANCE)
17
+ assert_in_delta(98.7654321, y, TOLERANCE)
18
+ end
19
+
20
+ if ENV['FORCE_TESTS'] || Geos::WktWriter.method_defined?(:trim=)
21
+ def test_trim
22
+ geom = read('POINT(6 7)')
23
+
24
+ writer.trim = true
25
+ assert_equal('POINT (6 7)', write(geom))
26
+
27
+ writer.trim = false
28
+ assert_equal('POINT (6.0000000000000000 7.0000000000000000)', write(geom))
29
+ end
30
+
31
+ def test_round_trip
32
+ writer.trim = true
33
+
34
+ [
35
+ 'POINT (0 0)',
36
+ 'POINT EMPTY',
37
+ 'MULTIPOINT (0 1, 2 3)',
38
+ 'MULTIPOINT EMPTY',
39
+ 'LINESTRING (0 0, 2 3)',
40
+ 'LINESTRING EMPTY',
41
+ 'MULTILINESTRING ((0 1, 2 3), (10 10, 3 4))',
42
+ 'MULTILINESTRING EMPTY',
43
+ 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))',
44
+ 'POLYGON EMPTY',
45
+ '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)))',
46
+ 'MULTIPOLYGON EMPTY',
47
+ '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))',
48
+ 'GEOMETRYCOLLECTION EMPTY'
49
+ ].each do |g|
50
+ assert_equal(g, write(read(g)))
51
+ end
52
+ end
53
+ end
54
+
55
+ if ENV['FORCE_TESTS'] || Geos::WktWriter.method_defined?(:rounding_precision=)
56
+ def test_rounding_precision
57
+ geom = read('POINT(6.123456 7.123456)')
58
+
59
+ tester = lambda { |expected, precision|
60
+ writer.rounding_precision = precision if precision
61
+ assert_equal(expected, write(geom))
62
+ }
63
+
64
+ tester['POINT (6.1234560000000000 7.1234560000000000)', nil]
65
+ tester['POINT (6.12 7.12)', 2]
66
+ tester['POINT (6.12346 7.12346)', 5]
67
+ tester['POINT (6.1 7.1)', 1]
68
+ tester['POINT (6 7)', 0]
69
+ end
70
+ end
71
+
72
+ if ENV['FORCE_TESTS'] || Geos::WktWriter.method_defined?(:output_dimensions)
73
+ def test_output_dimensions
74
+ assert_equal(2, writer.output_dimensions)
75
+ end
76
+ end
77
+
78
+ if ENV['FORCE_TESTS'] || Geos::WktWriter.method_defined?(:output_dimensions=)
79
+ def test_output_dimensions_set
80
+ geom_3d = read('POINT(1 2 3)')
81
+ geom_2d = read('POINT(3 2)')
82
+
83
+ writer.trim = true
84
+
85
+ # Only 2d by default
86
+ assert_equal('POINT (1 2)', write(geom_3d))
87
+
88
+ # 3d if requested _and_ available
89
+ writer.output_dimensions = 3
90
+ assert_equal('POINT Z (1 2 3)', write(geom_3d))
91
+ assert_equal('POINT (3 2)', write(geom_2d))
92
+
93
+ # 1 is invalid
94
+ assert_raise(RuntimeError) do
95
+ writer.output_dimensions = 1
96
+ end
97
+
98
+ # 4 is invalid
99
+ assert_raise(RuntimeError) do
100
+ writer.output_dimensions = 4
101
+ end
102
+ end
103
+
104
+ def test_write_with_options
105
+ @writer.rounding_precision = 2
106
+
107
+ geom = read('POINT(1 2 3)')
108
+ assert_equal('POINT (1 2)', write(geom, {
109
+ :trim => true
110
+ }))
111
+
112
+ assert_equal('POINT (1.0000 2.0000)', write(geom, {
113
+ :rounding_precision => 4
114
+ }))
115
+
116
+ assert_equal('POINT Z (1 2 3)', write(geom, {
117
+ :output_dimensions => 3,
118
+ :trim => true
119
+ }))
120
+
121
+ assert_equal('POINT (1.00 2.00)', write(geom))
122
+ end
123
+ end
124
+
125
+ if ENV['FORCE_TESTS'] || Geos::WktWriter.method_defined?(:old_3d=)
126
+ def test_old_3d_set
127
+ geom_3d = read('POINT(1 2 3)')
128
+ writer.trim = true
129
+
130
+ # New 3d WKT by default
131
+ writer.output_dimensions = 3
132
+ assert_equal('POINT Z (1 2 3)', write(geom_3d))
133
+
134
+ # Switch to old
135
+ writer.old_3d = true
136
+ assert_equal('POINT (1 2 3)', write(geom_3d))
137
+
138
+ # Old3d flag is not reset when changing dimensions
139
+ writer.output_dimensions = 2
140
+ assert_equal('POINT (1 2)', write(geom_3d))
141
+ writer.output_dimensions = 3
142
+ assert_equal('POINT (1 2 3)', write(geom_3d))
143
+
144
+ # Likewise, dimensions spec is not reset when changing old3d flag
145
+ writer.old_3d = false
146
+ assert_equal('POINT Z (1 2 3)', write(geom_3d))
147
+ end
148
+ end
149
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ffi-geos
3
+ version: !ruby/object:Gem::Version
4
+ hash: 62196393
5
+ prerelease: 6
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ - beta
11
+ - 1
12
+ version: 0.0.1.beta1
13
+ platform: ruby
14
+ authors:
15
+ - J Smith
16
+ autorequire:
17
+ bindir: bin
18
+ cert_chain: []
19
+
20
+ date: 2011-04-14 00:00:00 Z
21
+ dependencies: []
22
+
23
+ description: An ffi wrapper for GEOS, a C++ port of the Java Topology Suite (JTS).
24
+ email: dark.panda@gmail.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files:
30
+ - README.rdoc
31
+ files:
32
+ - MIT-LICENSE
33
+ - README.rdoc
34
+ - Rakefile
35
+ - VERSION
36
+ - lib/coordinate_sequence.rb
37
+ - lib/ffi-geos.rb
38
+ - lib/geometry.rb
39
+ - lib/geometry_collection.rb
40
+ - lib/line_string.rb
41
+ - lib/linear_ring.rb
42
+ - lib/multi_line_string.rb
43
+ - lib/multi_point.rb
44
+ - lib/multi_polygon.rb
45
+ - lib/point.rb
46
+ - lib/polygon.rb
47
+ - lib/prepared_geometry.rb
48
+ - lib/strtree.rb
49
+ - lib/tools.rb
50
+ - lib/utils.rb
51
+ - lib/wkb_reader.rb
52
+ - lib/wkb_writer.rb
53
+ - lib/wkt_reader.rb
54
+ - lib/wkt_writer.rb
55
+ - test/coordinate_sequence_tests.rb
56
+ - test/geometry_tests.rb
57
+ - test/misc_tests.rb
58
+ - test/point_tests.rb
59
+ - test/prepared_geometry_tests.rb
60
+ - test/strtree_tests.rb
61
+ - test/test_helper.rb
62
+ - test/utils_tests.rb
63
+ - test/wkb_reader_tests.rb
64
+ - test/wkb_writer_tests.rb
65
+ - test/wkt_reader_tests.rb
66
+ - test/wkt_writer_tests.rb
67
+ homepage: http://github.com/dark-panda/ffi-geos
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options: []
72
+
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">"
88
+ - !ruby/object:Gem::Version
89
+ hash: 25
90
+ segments:
91
+ - 1
92
+ - 3
93
+ - 1
94
+ version: 1.3.1
95
+ requirements: []
96
+
97
+ rubyforge_project:
98
+ rubygems_version: 1.7.2
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: An ffi wrapper for GEOS, a C++ port of the Java Topology Suite (JTS).
102
+ test_files:
103
+ - test/coordinate_sequence_tests.rb
104
+ - test/geometry_tests.rb
105
+ - test/misc_tests.rb
106
+ - test/point_tests.rb
107
+ - test/prepared_geometry_tests.rb
108
+ - test/strtree_tests.rb
109
+ - test/test_helper.rb
110
+ - test/utils_tests.rb
111
+ - test/wkb_reader_tests.rb
112
+ - test/wkb_writer_tests.rb
113
+ - test/wkt_reader_tests.rb
114
+ - test/wkt_writer_tests.rb