georuby 1.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/Gemfile +8 -0
  2. data/Gemfile.lock +29 -0
  3. data/History.txt +4 -0
  4. data/LICENSE +21 -0
  5. data/README.rdoc +184 -0
  6. data/Rakefile +48 -0
  7. data/VERSION +1 -0
  8. data/georuby.gemspec +128 -0
  9. data/lib/geo_ruby.rb +23 -0
  10. data/lib/geo_ruby/geojson.rb +129 -0
  11. data/lib/geo_ruby/georss.rb +133 -0
  12. data/lib/geo_ruby/gpx.rb +1 -0
  13. data/lib/geo_ruby/gpx4r/gpx.rb +118 -0
  14. data/lib/geo_ruby/shp.rb +1 -0
  15. data/lib/geo_ruby/shp4r/dbf.rb +42 -0
  16. data/lib/geo_ruby/shp4r/shp.rb +718 -0
  17. data/lib/geo_ruby/simple_features/envelope.rb +167 -0
  18. data/lib/geo_ruby/simple_features/ewkb_parser.rb +218 -0
  19. data/lib/geo_ruby/simple_features/ewkt_parser.rb +336 -0
  20. data/lib/geo_ruby/simple_features/geometry.rb +236 -0
  21. data/lib/geo_ruby/simple_features/geometry_collection.rb +144 -0
  22. data/lib/geo_ruby/simple_features/geometry_factory.rb +81 -0
  23. data/lib/geo_ruby/simple_features/helper.rb +18 -0
  24. data/lib/geo_ruby/simple_features/line_string.rb +228 -0
  25. data/lib/geo_ruby/simple_features/linear_ring.rb +34 -0
  26. data/lib/geo_ruby/simple_features/multi_line_string.rb +63 -0
  27. data/lib/geo_ruby/simple_features/multi_point.rb +58 -0
  28. data/lib/geo_ruby/simple_features/multi_polygon.rb +64 -0
  29. data/lib/geo_ruby/simple_features/point.rb +381 -0
  30. data/lib/geo_ruby/simple_features/polygon.rb +175 -0
  31. data/nofxx-georuby.gemspec +149 -0
  32. data/spec/data/geojson/feature_collection.json +34 -0
  33. data/spec/data/georss/atom.xml +21 -0
  34. data/spec/data/georss/gml.xml +40 -0
  35. data/spec/data/georss/w3c.xml +22 -0
  36. data/spec/data/gpx/fells_loop.gpx +1077 -0
  37. data/spec/data/gpx/long.gpx +1642 -0
  38. data/spec/data/gpx/long.kml +31590 -0
  39. data/spec/data/gpx/long.nmea +2220 -0
  40. data/spec/data/gpx/short.gpx +13634 -0
  41. data/spec/data/gpx/short.kml +130 -0
  42. data/spec/data/gpx/tracktreks.gpx +706 -0
  43. data/spec/data/multipoint.dbf +0 -0
  44. data/spec/data/multipoint.shp +0 -0
  45. data/spec/data/multipoint.shx +0 -0
  46. data/spec/data/point.dbf +0 -0
  47. data/spec/data/point.shp +0 -0
  48. data/spec/data/point.shx +0 -0
  49. data/spec/data/polygon.dbf +0 -0
  50. data/spec/data/polygon.shp +0 -0
  51. data/spec/data/polygon.shx +0 -0
  52. data/spec/data/polyline.dbf +0 -0
  53. data/spec/data/polyline.shp +0 -0
  54. data/spec/data/polyline.shx +0 -0
  55. data/spec/geo_ruby/geojson_spec.rb +147 -0
  56. data/spec/geo_ruby/georss.rb +218 -0
  57. data/spec/geo_ruby/georss_spec.rb +14 -0
  58. data/spec/geo_ruby/gpx4r/gpx_spec.rb +106 -0
  59. data/spec/geo_ruby/shp4r/shp_spec.rb +239 -0
  60. data/spec/geo_ruby/simple_features/envelope_spec.rb +47 -0
  61. data/spec/geo_ruby/simple_features/ewkb_parser_spec.rb +158 -0
  62. data/spec/geo_ruby/simple_features/ewkt_parser_spec.rb +179 -0
  63. data/spec/geo_ruby/simple_features/geometry_collection_spec.rb +55 -0
  64. data/spec/geo_ruby/simple_features/geometry_factory_spec.rb +11 -0
  65. data/spec/geo_ruby/simple_features/geometry_spec.rb +32 -0
  66. data/spec/geo_ruby/simple_features/line_string_spec.rb +259 -0
  67. data/spec/geo_ruby/simple_features/linear_ring_spec.rb +24 -0
  68. data/spec/geo_ruby/simple_features/multi_line_string_spec.rb +54 -0
  69. data/spec/geo_ruby/simple_features/multi_point_spec.rb +35 -0
  70. data/spec/geo_ruby/simple_features/multi_polygon_spec.rb +50 -0
  71. data/spec/geo_ruby/simple_features/point_spec.rb +356 -0
  72. data/spec/geo_ruby/simple_features/polygon_spec.rb +122 -0
  73. data/spec/geo_ruby_spec.rb +27 -0
  74. data/spec/spec_helper.rb +73 -0
  75. metadata +228 -0
@@ -0,0 +1,55 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe GeometryCollection do
4
+
5
+ it "should test_geometry_collection_creation" do
6
+ geometry_collection = GeometryCollection::new(256)
7
+ geometry_collection << Point.from_x_y(4.67,45.4,256)
8
+
9
+ geometry_collection.length.should eql(1)
10
+ geometry_collection[0].should == Point.from_x_y(4.67,45.4,256)
11
+
12
+ geometry_collection[0]=LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)
13
+ geometry_collection << Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)
14
+ geometry_collection.length.should eql(2)
15
+ geometry_collection[0].should == LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)
16
+
17
+ geometry_collection = GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4,256),LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256)
18
+ geometry_collection.class.should eql(GeometryCollection)
19
+ geometry_collection.srid.should eql(256)
20
+ geometry_collection.length.should eql(2)
21
+ geometry_collection[1].should == LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)
22
+
23
+ bbox = geometry_collection.bounding_box
24
+ bbox.length.should eql(2)
25
+ bbox[0].should == Point.from_x_y(4.67,12.45)
26
+ bbox[1].should == Point.from_x_y(67.55,54)
27
+ end
28
+
29
+ it "test_geometry_collection_equal" do
30
+ geometry_collection1 = GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4,256),LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256)
31
+ geometry_collection2 = GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4,256),LineString.from_coordinates([[5.7,12.45],[67.55,54]],256),Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256)],256,true)
32
+ line_string=LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)
33
+
34
+ geometry_collection1.should == GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4,256),LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256)
35
+ geometry_collection2.should_not == geometry_collection1
36
+ line_string.should_not == geometry_collection1
37
+ end
38
+
39
+ it "test_geometry_collection_binary" do
40
+ geometry_collection = GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4,256),LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256)
41
+ geometry_collection.as_hex_ewkb.should eql("010700002000010000020000000101000000AE47E17A14AE12403333333333B34640010200000002000000CDCCCCCCCCCC16406666666666E628403333333333E350400000000000004B40")
42
+
43
+ geometry_collection = GeometryCollection.from_geometries([Point.from_x_y_z_m(4.67,45.4,45.67,2.3,256),LineString.from_coordinates([[5.7,12.45,4.56,98.3],[67.55,54,12.2,3.4]],256,true, true)],256,true, true)
44
+ geometry_collection.as_hex_ewkb.should eql("01070000E0000100000200000001010000C0AE47E17A14AE12403333333333B34640F6285C8FC2D54640666666666666024001020000C002000000CDCCCCCCCCCC16406666666666E628403D0AD7A3703D124033333333339358403333333333E350400000000000004B4066666666666628403333333333330B40")
45
+ end
46
+
47
+ it "should test_geometry_collection_text" do
48
+ geometry_collection = GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4,256),LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256)
49
+ geometry_collection.as_ewkt.should eql("SRID=256;GEOMETRYCOLLECTION(POINT(4.67 45.4),LINESTRING(5.7 12.45,67.55 54))")
50
+
51
+ geometry_collection = GeometryCollection.from_geometries([Point.from_x_y_m(4.67,45.4,45.6,256),LineString.from_coordinates([[5.7,12.45,5.6],[67.55,54,6.7]],256,false,true)],256,false,true)
52
+ geometry_collection.as_ewkt.should eql("SRID=256;GEOMETRYCOLLECTIONM(POINTM(4.67 45.4 45.6),LINESTRINGM(5.7 12.45 5.6,67.55 54 6.7))")
53
+ end
54
+
55
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe GeometryFactory do
4
+ # before(:each) do
5
+ # @po = MultiPolygon.new
6
+ # end
7
+
8
+ #it "should f" do
9
+ # violated
10
+ #end
11
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Geometry do
4
+ before(:each) do
5
+ @geo = Geometry.new
6
+ end
7
+
8
+ it "should instantiate" do
9
+ violated unless @geo
10
+ end
11
+
12
+ it "should have a default srid" do
13
+ @geo.srid.should eql(4326) #Geometry.default_srid)
14
+ end
15
+
16
+ it "should change srid" do
17
+ geo = Geometry.new(225)
18
+ geo.srid.should eql(225)
19
+ end
20
+
21
+ it "should instantiate from hex ewkb" do
22
+ point = Geometry.from_hex_ewkb("01010000207B000000CDCCCCCCCCCC28406666666666A64640")
23
+ point.class.should == Point
24
+ point.x.should be_within(0.1).of(12.4)
25
+ end
26
+
27
+ it "should output as_ewkb" do
28
+ @geo.stub!(:binary_geometry_type).and_return(1)
29
+ @geo.stub!(:binary_representation).and_return(1)
30
+ @geo.as_ewkb.should eql("\001\001\000\000 \346\020\000\000\001")
31
+ end
32
+ end
@@ -0,0 +1,259 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ module LineSpecHelper
4
+ def mock_points(num)
5
+ # @point = mock(Point, :x => 1.0, :y => 2.0)
6
+ Array.new(num) { |i| mock_point(i,i) }
7
+ end
8
+
9
+ def mock_point(x=1,y=2)
10
+ mock(Point, :x => x, :y => y, :text_representation => "#{x} #{y}")
11
+ end
12
+ end
13
+
14
+ describe LineString do
15
+
16
+ include LineSpecHelper
17
+
18
+ describe "Instance Methods" do
19
+
20
+ let(:line) { LineString.from_points([mock(Point)]) }
21
+
22
+ it "should instantiate" do
23
+ violated unless line
24
+ end
25
+
26
+ it "should have binary_geometry_type 2" do
27
+ line.binary_geometry_type.should eql(2)
28
+ end
29
+
30
+ it "should have text_geometry_type" do
31
+ line.text_geometry_type.should eql("LINESTRING")
32
+ end
33
+
34
+ it "should have a points array" do
35
+ line.points.should be_instance_of(Array)
36
+ end
37
+
38
+ end
39
+
40
+ describe "Valid LineString" do
41
+
42
+ let(:line) { LineString.from_points([Point.xy(1,1), Point.xy(2,2), Point.xy(3,3)]) }
43
+
44
+ it "should check orientation" do
45
+ line.should_not be_clockwise
46
+ end
47
+
48
+ it "should check orientation" do
49
+ l = LineString.from_points([Point.from_x_y(20,20), Point.from_x_y(10,10), Point.from_x_y(-10,10)])
50
+ l.should be_clockwise
51
+ end
52
+
53
+ end
54
+
55
+ describe "tu converted" do
56
+
57
+ it "should concat points" do
58
+ line_string = LineString::new
59
+ line_string.concat([Point.from_x_y(12.4,45.3),Point.from_x_y(45.4,41.6)])
60
+
61
+ line_string.length.should eql(2)
62
+ line_string[0].should == Point.from_x_y(12.4,45.3)
63
+
64
+ point=Point.from_x_y(123,45.8777)
65
+ line_string[0]=point
66
+ line_string[0].should == point
67
+
68
+ points=[Point.from_x_y(123,45.8777),Point.from_x_y(45.4,41.6)]
69
+ line_string.each_index {|i| line_string[i].should == points[i] }
70
+
71
+ point=Point.from_x_y(22.4,13.56)
72
+ line_string << point
73
+ line_string.length.should eql(3)
74
+ line_string[2].should eql(point)
75
+ end
76
+
77
+ it "should create" do
78
+ line_string = LineString.from_points([Point.from_x_y(12.4,-45.3),Point.from_x_y(45.4,41.6)],123)
79
+ line_string.class.should eql(LineString)
80
+ line_string.length.should eql(2)
81
+ line_string[0].should == Point.from_x_y(12.4,-45.3)
82
+ line_string[1].should == Point.from_x_y(45.4,41.6)
83
+
84
+ line_string = LineString.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698]],123)
85
+ line_string.class.should eql(LineString)
86
+ line_string.length.should eql(3)
87
+ line_string[0].should == Point.from_x_y(12.4,-45.3)
88
+ line_string[1].should == Point.from_x_y(45.4,41.6)
89
+
90
+ line_string = LineString.from_coordinates([[12.4,-45.3,123],[45.4,41.6,333],[4.456,1.0698,987]],123,true)
91
+ line_string.class.should eql(LineString)
92
+ line_string.length.should eql(3)
93
+ line_string[0].should == Point.from_x_y_z(12.4,-45.3,123,123)
94
+
95
+ line_string = LineString.from_coordinates([[12.4,-45.3,123],[45.4,41.6,333],[4.456,1.0698,987]],123,true)
96
+ line_string.class.should eql(LineString)
97
+ line_string.length.should eql(3)
98
+ line_string[0].should == Point.from_x_y_z(12.4,-45.3,123,123)
99
+ end
100
+
101
+ it "should bbox it" do
102
+ bbox = LineString.from_coordinates([[12.4,-45.3,123],[45.4,41.6,333],[4.456,1.0698,987]],123,true).bounding_box
103
+ bbox.length.should eql(2)
104
+ bbox[0].should == Point.from_x_y_z(4.456,-45.3,123)
105
+ bbox[1].should == Point.from_x_y_z(45.4,41.6,987)
106
+ end
107
+
108
+ it "should test_line_string_equal" do
109
+ line_string1 = LineString.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698]],123)
110
+ line_string2 = LineString.from_coordinates([[12.4,-45.3],[45.4,41.6]],123)
111
+ point = Point.from_x_y(12.4,-45.3,123)
112
+
113
+ line_string1.should == LineString.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698]],123)
114
+ line_string1.should_not == line_string2
115
+ line_string1.should_not == point
116
+ end
117
+
118
+ it "should test_line_string_binary" do
119
+ line_string = LineString.from_coordinates([[12.4,-45.3],[45.4,41.6]],256)
120
+ line_string.as_hex_ewkb.should eql("01020000200001000002000000CDCCCCCCCCCC28406666666666A646C03333333333B34640CDCCCCCCCCCC4440")
121
+
122
+ line_string = LineString.from_coordinates([[12.4,-45.3,35.3],[45.4,41.6,12.3]],256,true)
123
+ line_string.as_hex_ewkb.should eql("01020000A00001000002000000CDCCCCCCCCCC28406666666666A646C06666666666A641403333333333B34640CDCCCCCCCCCC44409A99999999992840")
124
+
125
+ line_string = LineString.from_coordinates([[12.4,-45.3,35.3,45.1],[45.4,41.6,12.3,40.23]],256,true,true)
126
+ line_string.as_hex_ewkb.should eql("01020000E00001000002000000CDCCCCCCCCCC28406666666666A646C06666666666A64140CDCCCCCCCC8C46403333333333B34640CDCCCCCCCCCC44409A999999999928403D0AD7A3701D4440")
127
+ end
128
+
129
+ it "test_line_string_text" do
130
+ line_string = LineString.from_coordinates([[12.4,-45.3],[45.4,41.6]],256)
131
+ line_string.as_ewkt.should eql("SRID=256;LINESTRING(12.4 -45.3,45.4 41.6)")
132
+
133
+ line_string = LineString.from_coordinates([[12.4,-45.3,35.3],[45.4,41.6,12.3]],256,true)
134
+ line_string.as_ewkt.should eql("SRID=256;LINESTRING(12.4 -45.3 35.3,45.4 41.6 12.3)")
135
+
136
+ line_string = LineString.from_coordinates([[12.4,-45.3,35.3],[45.4,41.6,12.3]],256,false,true)
137
+ line_string.as_ewkt.should eql("SRID=256;LINESTRINGM(12.4 -45.3 35.3,45.4 41.6 12.3)")
138
+
139
+ line_string = LineString.from_coordinates([[12.4,-45.3,35.3,25.2],[45.4,41.6,12.3,13.75]],256,true,true)
140
+ line_string.as_ewkt.should eql("SRID=256;LINESTRING(12.4 -45.3 35.3 25.2,45.4 41.6 12.3 13.75)")
141
+ end
142
+
143
+ it "should test_linear_ring_creation" do
144
+ #testing just the constructor helpers since the rest is the same as for line_string
145
+ linear_ring = LinearRing.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],345)
146
+ linear_ring.class.should eql(LinearRing)
147
+ linear_ring.length.should eql(4)
148
+ linear_ring.should be_closed
149
+ linear_ring[1].should == Point.from_x_y(45.4,41.6,345)
150
+ end
151
+ end
152
+
153
+ describe "> Coordinates" do
154
+
155
+ before(:each) do
156
+ Point.should_receive(:from_coordinates).
157
+ exactly(4).with(anything, 4326, false, false).and_return(mock_point)
158
+ @line = LineString.from_coordinates([1.2,2.5,2.2,4.5])
159
+ end
160
+
161
+ it "should instantiate from coordinates" do
162
+ @line.points.length.should eql(4)
163
+ end
164
+
165
+ end
166
+
167
+ describe "> Instantiated" do
168
+
169
+ let (:line) { LineString.from_points(mock_points(7)) }
170
+
171
+ it "should be closed if the last point equals the first" do
172
+ line.push(line.first)
173
+ line.should be_closed
174
+ line.length.should eql(8)
175
+ end
176
+
177
+ it "should print the text representation" do
178
+ line.text_representation.should eql("0 0,1 1,2 2,3 3,4 4,5 5,6 6")
179
+ end
180
+
181
+ it "should print the georss_simple_representation" do
182
+ line.georss_simple_representation({:geom_attr => nil}).
183
+ should eql("<georss:line>0 0 1 1 2 2 3 3 4 4 5 5 6 6</georss:line>\n")
184
+ end
185
+
186
+ it "should map the georss_poslist" do
187
+ line.georss_poslist.should eql("0 0 1 1 2 2 3 3 4 4 5 5 6 6")
188
+ end
189
+
190
+ it "should print the kml_representation" do
191
+ line.kml_representation.should
192
+ eql("<LineString>\n<coordinates>0,0 1,1 2,2 3,3 4,4 5,5 6,6</coordinates>\n</LineString>\n")
193
+ end
194
+
195
+ it "should print the kml_poslist without reverse or z" do
196
+ line.kml_poslist({}).should eql("0,0 1,1 2,2 3,3 4,4 5,5 6,6")
197
+ end
198
+
199
+ it "should print the kml_poslist reverse" do
200
+ line.kml_poslist({:reverse => true}).should eql("6,6 5,5 4,4 3,3 2,2 1,1 0,0")
201
+ end
202
+ end
203
+
204
+ describe "> Distances..." do
205
+ before(:each) do
206
+ @p1 = mock(Point)
207
+ @p2 = mock(Point)
208
+ @p3 = mock(Point)
209
+ @line = LineString.from_points([@p1,@p2,@p3])
210
+ end
211
+
212
+ it "should print the length with haversine" do
213
+ @p1.should_receive(:spherical_distance).with(@p2).and_return(10)
214
+ @p2.should_receive(:spherical_distance).with(@p3).and_return(10)
215
+ @line.spherical_distance.should eql(20)
216
+ end
217
+
218
+ it "should print lenght as euclidian" do
219
+ @p1.should_receive(:euclidian_distance).with(@p2).and_return(10)
220
+ @p2.should_receive(:euclidian_distance).with(@p3).and_return(10)
221
+ @line.euclidian_distance.should eql(20)
222
+ end
223
+ end
224
+
225
+ describe "Simplify" do
226
+
227
+ let(:line) { LineString.from_coordinates([[6,0],[4,1],[3,4],[4,6],[5,8],[5,9],[4,10],[6,15]], 4326) }
228
+
229
+ it "should simplify a simple linestring" do
230
+ line = LineString.from_coordinates([[12,15],[14,17],[17, 20]], 4326)
231
+ line.simplify.should have(2).points
232
+ end
233
+
234
+ it "should simplify a harder linestring" do
235
+ line.simplify(6).should have(6).points
236
+ line.simplify(9).should have(4).points
237
+ line.simplify(10).should have(3).points
238
+ end
239
+
240
+ it "should barely touch it" do
241
+ line.simplify(1).should have(7).points
242
+ end
243
+
244
+ it "should simplify to five points" do
245
+ line.simplify(7).should have(5).points
246
+ end
247
+
248
+ it "should flatten it" do
249
+ line.simplify(11).should have(2).points
250
+ end
251
+
252
+ it "should be the first and last in a flatten" do
253
+ l = line.simplify(11)
254
+ l[0].should be_a_point(6, 0)
255
+ l[1].should be_a_point(6, 15)
256
+ end
257
+
258
+ end
259
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe LinearRing do
4
+
5
+ it "should instantiate" do
6
+ lr = LinearRing.new(4326)
7
+ lr.should be_instance_of(LinearRing)
8
+ end
9
+
10
+ describe "Instance" do
11
+
12
+ let(:lr) { LinearRing.from_coordinates([[10,10],[20,45],[45,10],[10, 10]],256) }
13
+
14
+ it "should test if contains a point" do
15
+ lr.contains_point?(Point.from_x_y(21,21)).should be_true
16
+ end
17
+
18
+ it "should test if not contains a point" do
19
+ lr.contains_point?(Point.from_x_y(21,51)).should be_false
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,54 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe MultiLineString do
4
+
5
+ it "test_multi_line_string_creation" do
6
+ multi_line_string1 = MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256),LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]],256)],256)
7
+ multi_line_string1.should be_instance_of(MultiLineString)
8
+ multi_line_string1.length.should eql(2)
9
+ multi_line_string1[0].should == LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256)
10
+
11
+ multi_line_string2= MultiLineString.from_coordinates([[[1.5,45.2],[-54.12312,-0.012]],[[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]]],256);
12
+ multi_line_string1.should be_instance_of(MultiLineString)
13
+ multi_line_string1.length.should eql(2)
14
+ multi_line_string2[0].should == LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256)
15
+
16
+ multi_line_string2.should == multi_line_string2
17
+ end
18
+
19
+ it "test_multi_line_string_binary" do
20
+ multi_line_string = MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256),LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]],256)],256)
21
+ multi_line_string.as_hex_ewkb.should eql("01050000200001000002000000010200000002000000000000000000F83F9A99999999994640E4BD6A65C20F4BC0FA7E6ABC749388BF010200000003000000000000000000F83F9A99999999994640E4BD6A65C20F4BC0FA7E6ABC749388BF39B4C876BE8F46403333333333D35E40")
22
+
23
+ multi_line_string = MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2,1.3,1.2],[-54.12312,-0.012,1.2,4.5]],256,true,true),LineString.from_coordinates([[1.5,45.2,5.1,-4.5],[-54.12312,-0.012,-6.8,3.4],[45.123,123.3,4.5,-5.3]],256,true,true)],256,true,true)
24
+ multi_line_string.as_hex_ewkb.should eql("0105000020000100000200000001020000C002000000000000000000F83F9A99999999994640CDCCCCCCCCCCF43F333333333333F33FE4BD6A65C20F4BC0FA7E6ABC749388BF333333333333F33F000000000000124001020000C003000000000000000000F83F9A99999999994640666666666666144000000000000012C0E4BD6A65C20F4BC0FA7E6ABC749388BF3333333333331BC03333333333330B4039B4C876BE8F46403333333333D35E40000000000000124033333333333315C0")
25
+ end
26
+
27
+ it "test_multi_line_string_text" do
28
+ multi_line_string = MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256),LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]],256)],256)
29
+ multi_line_string.as_ewkt.should eql("SRID=256;MULTILINESTRING((1.5 45.2,-54.12312 -0.012),(1.5 45.2,-54.12312 -0.012,45.123 123.3))")
30
+
31
+ multi_line_string = MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2,1.3,1.2],[-54.12312,-0.012,1.2,4.5]],256,true,true),LineString.from_coordinates([[1.5,45.2,5.1,-4.5],[-54.12312,-0.012,-6.8,3.4],[45.123,123.3,4.5,-5.3]],256,true,true)],256,true,true)
32
+ multi_line_string.as_ewkt.should eql("SRID=256;MULTILINESTRING((1.5 45.2 1.3 1.2,-54.12312 -0.012 1.2 4.5),(1.5 45.2 5.1 -4.5,-54.12312 -0.012 -6.8 3.4,45.123 123.3 4.5 -5.3))")
33
+ end
34
+
35
+ describe "Some More" do
36
+ before do
37
+ @mls = MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256),LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]],256)],256)
38
+ end
39
+
40
+ it "should have a accessor to all points" do
41
+ @mls.points.should be_instance_of(Array)
42
+ end
43
+
44
+ it "should flatten the array" do
45
+ @mls.should have(5).points
46
+ end
47
+
48
+ it "should simplify to linestring" do
49
+ ls = @mls.to_line_string
50
+ ls.should be_instance_of(LineString)
51
+ ls.should have(5).points
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,35 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe MultiPoint do
4
+
5
+ it "test_multi_point_creation" do
6
+ multi_point = MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]],444)
7
+ multi_point.should be_instance_of(MultiPoint)
8
+ multi_point.length.should eql(3)
9
+ multi_point[0].should == Point.from_x_y(12.4,-123.3,444)
10
+ multi_point[2].should == Point.from_x_y(123.55555555,123,444)
11
+ end
12
+
13
+ it "test_multi_point_binary" do
14
+ multi_point = MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]],444)
15
+ multi_point.as_hex_ewkb.should eql("0104000020BC010000030000000101000000CDCCCCCCCCCC28403333333333D35EC0010100000066666666664650C09A99999999D95E4001010000001F97DD388EE35E400000000000C05E40")
16
+
17
+ multi_point = MultiPoint.from_coordinates([[12.4,-123.3,4.5],[-65.1,123.4,1.2],[123.55555555,123,2.3]],444,true)
18
+ multi_point.as_hex_ewkb.should eql("01040000A0BC010000030000000101000080CDCCCCCCCCCC28403333333333D35EC00000000000001240010100008066666666664650C09A99999999D95E40333333333333F33F01010000801F97DD388EE35E400000000000C05E406666666666660240")
19
+ end
20
+
21
+ it "test_multi_point_text" do
22
+ multi_point = MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]],444)
23
+ multi_point.as_ewkt.should eql("SRID=444;MULTIPOINT((12.4 -123.3),(-65.1 123.4),(123.55555555 123))")
24
+
25
+ multi_point = MultiPoint.from_coordinates([[12.4,-123.3,4.5],[-65.1,123.4,6.7],[123.55555555,123,7.8]],444,true)
26
+ multi_point.as_ewkt.should eql("SRID=444;MULTIPOINT((12.4 -123.3 4.5),(-65.1 123.4 6.7),(123.55555555 123 7.8))")
27
+ end
28
+
29
+ it "should respond to points" do
30
+ mp = MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]],444)
31
+ mp.should have(3).geometries
32
+ mp.should have(3).points
33
+ end
34
+
35
+ end