nofxx-georuby 1.3.7
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/LICENSE +21 -0
- data/README.txt +59 -0
- data/Rakefile +49 -0
- data/VERSION.yml +4 -0
- data/lib/geo_ruby.rb +21 -0
- data/lib/geo_ruby/base/envelope.rb +167 -0
- data/lib/geo_ruby/base/ewkb_parser.rb +216 -0
- data/lib/geo_ruby/base/ewkt_parser.rb +336 -0
- data/lib/geo_ruby/base/geometry.rb +234 -0
- data/lib/geo_ruby/base/geometry_collection.rb +136 -0
- data/lib/geo_ruby/base/geometry_factory.rb +81 -0
- data/lib/geo_ruby/base/georss_parser.rb +135 -0
- data/lib/geo_ruby/base/helper.rb +18 -0
- data/lib/geo_ruby/base/line_string.rb +184 -0
- data/lib/geo_ruby/base/linear_ring.rb +12 -0
- data/lib/geo_ruby/base/multi_line_string.rb +39 -0
- data/lib/geo_ruby/base/multi_point.rb +41 -0
- data/lib/geo_ruby/base/multi_polygon.rb +37 -0
- data/lib/geo_ruby/base/point.rb +310 -0
- data/lib/geo_ruby/base/polygon.rb +150 -0
- data/lib/geo_ruby/shp4r/dbf.rb +180 -0
- data/lib/geo_ruby/shp4r/shp.rb +701 -0
- data/spec/data/multipoint.dbf +0 -0
- data/spec/data/multipoint.shp +0 -0
- data/spec/data/multipoint.shx +0 -0
- data/spec/data/point.dbf +0 -0
- data/spec/data/point.shp +0 -0
- data/spec/data/point.shx +0 -0
- data/spec/data/polygon.dbf +0 -0
- data/spec/data/polygon.shp +0 -0
- data/spec/data/polygon.shx +0 -0
- data/spec/data/polyline.dbf +0 -0
- data/spec/data/polyline.shp +0 -0
- data/spec/data/polyline.shx +0 -0
- data/spec/geo_ruby/base/envelope_spec.rb +45 -0
- data/spec/geo_ruby/base/ewkb_parser_spec.rb +158 -0
- data/spec/geo_ruby/base/ewkt_parser_spec.rb +179 -0
- data/spec/geo_ruby/base/geometry_collection_spec.rb +55 -0
- data/spec/geo_ruby/base/geometry_factory_spec.rb +11 -0
- data/spec/geo_ruby/base/geometry_spec.rb +32 -0
- data/spec/geo_ruby/base/georss_parser_spec.rb +218 -0
- data/spec/geo_ruby/base/line_string_spec.rb +208 -0
- data/spec/geo_ruby/base/linear_ring_spec.rb +14 -0
- data/spec/geo_ruby/base/multi_line_string_spec.rb +35 -0
- data/spec/geo_ruby/base/multi_point_spec.rb +29 -0
- data/spec/geo_ruby/base/multi_polygon_spec.rb +35 -0
- data/spec/geo_ruby/base/point_spec.rb +275 -0
- data/spec/geo_ruby/base/polygon_spec.rb +108 -0
- data/spec/geo_ruby/shp4r/shp_spec.rb +238 -0
- data/spec/geo_ruby_spec.rb +27 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +12 -0
- metadata +123 -0
@@ -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(@@default_srid) #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_close(12.4, 0.1)
|
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,218 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe GeorssParser do
|
4
|
+
it "test_point_creation" do
|
5
|
+
point = Point.from_x_y(3,4)
|
6
|
+
|
7
|
+
point.as_georss(:dialect => :simple, :elev => 45.7, :featuretypetag => "hoyoyo").gsub("\n","").should eql("<georss:point featuretypetag=\"hoyoyo\" elev=\"45.7\">4 3</georss:point>")
|
8
|
+
point.as_georss(:dialect => :w3cgeo).gsub("\n","").should eql("<geo:lat>4</geo:lat><geo:long>3</geo:long>")
|
9
|
+
point.as_georss(:dialect => :gml).gsub("\n","").should eql("<georss:where><gml:Point><gml:pos>4 3</gml:pos></gml:Point></georss:where>")
|
10
|
+
|
11
|
+
point.as_kml(:id => "HOYOYO-42").gsub("\n","").should eql("<Point id=\"HOYOYO-42\"><coordinates>3,4</coordinates></Point>")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "test_line_string" do
|
15
|
+
ls = LineString.from_points([Point.from_lon_lat_z(12.4,-45.3,56),Point.from_lon_lat_z(45.4,41.6,45)],123,true)
|
16
|
+
|
17
|
+
ls.as_georss.gsub("\n","").should eql("<georss:line>-45.3 12.4 41.6 45.4</georss:line>")
|
18
|
+
ls.as_georss(:dialect => :w3cgeo).gsub("\n","").should eql("<geo:lat>-45.3</geo:lat><geo:long>12.4</geo:long>")
|
19
|
+
ls.as_georss(:dialect => :gml).gsub("\n","").should eql("<georss:where><gml:LineString><gml:posList>-45.3 12.4 41.6 45.4</gml:posList></gml:LineString></georss:where>")
|
20
|
+
|
21
|
+
ls.as_kml(:extrude => 1, :altitude_mode => "absolute").gsub("\n","").should eql("<LineString><extrude>1</extrude><altitudeMode>absolute</altitudeMode><coordinates>12.4,-45.3,56 45.4,41.6,45</coordinates></LineString>")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "test_polygon" do
|
25
|
+
linear_ring1 = LinearRing.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],256)
|
26
|
+
linear_ring2 = LinearRing.from_coordinates([[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]],256)
|
27
|
+
polygon = Polygon.from_linear_rings([linear_ring1,linear_ring2],256)
|
28
|
+
|
29
|
+
polygon.as_georss(:georss_ns => "hoyoyo").gsub("\n","").should eql("<hoyoyo:polygon>-45.3 12.4 41.6 45.4 1.0698 4.456 -45.3 12.4</hoyoyo:polygon>")
|
30
|
+
polygon.as_georss(:dialect => :w3cgeo, :w3cgeo_ns => "bouyoul").gsub("\n","").should eql("<bouyoul:lat>-45.3</bouyoul:lat><bouyoul:long>12.4</bouyoul:long>")
|
31
|
+
polygon.as_georss(:dialect => :gml).gsub("\n","").should eql("<georss:where><gml:Polygon><gml:exterior><gml:LinearRing><gml:posList>-45.3 12.4 41.6 45.4 1.0698 4.456 -45.3 12.4</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></georss:where>")
|
32
|
+
|
33
|
+
polygon.as_kml.gsub("\n","").should eql("<Polygon><outerBoundaryIs><LinearRing><coordinates>12.4,-45.3 45.4,41.6 4.456,1.0698 12.4,-45.3</coordinates></LinearRing></outerBoundaryIs><innerBoundaryIs><LinearRing><coordinates>2.4,5.3 5.4,1.4263 14.46,1.06 2.4,5.3</coordinates></LinearRing></innerBoundaryIs></Polygon>")
|
34
|
+
end
|
35
|
+
|
36
|
+
it "test_geometry_collection" do
|
37
|
+
gc = GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4,256),LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256)
|
38
|
+
|
39
|
+
#only the first geometry is output
|
40
|
+
gc.as_georss(:dialect => :simple,:floor => 4).gsub("\n","").should eql("<georss:point floor=\"4\">45.4 4.67</georss:point>")
|
41
|
+
gc.as_georss(:dialect => :w3cgeo).gsub("\n","").should eql("<geo:lat>45.4</geo:lat><geo:long>4.67</geo:long>")
|
42
|
+
gc.as_georss(:dialect => :gml).gsub("\n","").should eql("<georss:where><gml:Point><gml:pos>45.4 4.67</gml:pos></gml:Point></georss:where>")
|
43
|
+
|
44
|
+
gc.as_kml(:id => "HOYOYO-42").gsub("\n","").should eql("<MultiGeometry id=\"HOYOYO-42\"><Point><coordinates>4.67,45.4</coordinates></Point><LineString><coordinates>5.7,12.45 67.55,54</coordinates></LineString></MultiGeometry>")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "test_envelope" do
|
48
|
+
linear_ring1 = LinearRing.from_coordinates([[12.4,-45.3,5],[45.4,41.6,6],[4.456,1.0698,8],[12.4,-45.3,3.5]],256,true)
|
49
|
+
linear_ring2 = LinearRing.from_coordinates([[2.4,5.3,9.0],[5.4,1.4263,-5.4],[14.46,1.06,34],[2.4,5.3,3.14]],256,true)
|
50
|
+
polygon = Polygon.from_linear_rings([linear_ring1,linear_ring2],256,true)
|
51
|
+
|
52
|
+
e = polygon.envelope
|
53
|
+
|
54
|
+
e.as_georss(:dialect => :simple).gsub("\n","").should eql("<georss:box>-45.3 4.456 41.6 45.4</georss:box>")
|
55
|
+
#center
|
56
|
+
e.as_georss(:dialect => :w3cgeo).gsub("\n","").should eql("<geo:lat>-1.85</geo:lat><geo:long>24.928</geo:long>")
|
57
|
+
e.as_georss(:dialect => :gml).gsub("\n","").should eql("<georss:where><gml:Envelope><gml:LowerCorner>-45.3 4.456</gml:LowerCorner><gml:UpperCorner>41.6 45.4</gml:UpperCorner></gml:Envelope></georss:where>")
|
58
|
+
|
59
|
+
e.as_kml.gsub("\n","").should eql("<LatLonAltBox><north>41.6</north><south>-45.3</south><east>45.4</east><west>4.456</west><minAltitude>-5.4</minAltitude><maxAltitude>34</maxAltitude></LatLonAltBox>")
|
60
|
+
end
|
61
|
+
|
62
|
+
it "test_point_georss_read" do
|
63
|
+
#W3CGeo
|
64
|
+
str = " <geo:lat >12.3</geo:lat >\n\t <geo:long> 4.56</geo:long> "
|
65
|
+
geom = Geometry.from_georss(str)
|
66
|
+
geom.class.should eql(Point)
|
67
|
+
geom.lat.should eql(12.3)
|
68
|
+
geom.lon.should eql(4.56)
|
69
|
+
|
70
|
+
str = " <geo:Point> \n \t <geo:long> 4.56</geo:long> \n\t <geo:lat >12.3</geo:lat > </geo:Point> "
|
71
|
+
geom = Geometry.from_georss(str)
|
72
|
+
geom.class.should eql(Point)
|
73
|
+
geom.lat.should eql(12.3)
|
74
|
+
geom.lon.should eql(4.56)
|
75
|
+
|
76
|
+
#gml
|
77
|
+
str = " <georss:where> \t\r <gml:Point > \t <gml:pos> 4 \t 3 </gml:pos> </gml:Point> </georss:where>"
|
78
|
+
geom = Geometry.from_georss(str)
|
79
|
+
geom.class.should eql(Point)
|
80
|
+
geom.lat.should eql(4.0)
|
81
|
+
geom.lon.should eql(3.0)
|
82
|
+
|
83
|
+
#simple
|
84
|
+
str = "<georss:point > 4 \r\t 3 \t</georss:point >"
|
85
|
+
geom = Geometry.from_georss(str)
|
86
|
+
geom.class.should eql(Point)
|
87
|
+
geom.lat.should eql(4.0)
|
88
|
+
geom.lon.should eql(3.0)
|
89
|
+
|
90
|
+
#simple with tags
|
91
|
+
str = "<georss:point featuretypetag=\"hoyoyo\" elev=\"45.7\" \n floor=\"2\" relationshiptag=\"puyopuyo\" radius=\"42\" > 4 \n 3 \t</georss:point >"
|
92
|
+
geom,tags = Geometry.from_georss_with_tags(str)
|
93
|
+
geom.class.should eql(Point)
|
94
|
+
geom.lat.should eql(4.0)
|
95
|
+
geom.lon.should eql(3.0)
|
96
|
+
tags.featuretypetag.should eql("hoyoyo")
|
97
|
+
tags.elev.should eql(45.7)
|
98
|
+
tags.relationshiptag.should eql("puyopuyo")
|
99
|
+
tags.floor.should eql(2)
|
100
|
+
tags.radius.should eql(42.0)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "test_line_string_georss_read" do
|
104
|
+
ls = LineString.from_points([Point.from_lon_lat(12.4,-45.3),Point.from_lon_lat(45.4,41.6)])
|
105
|
+
|
106
|
+
str = "<georss:line > -45.3 12.4 \n \r41.6\t 45.4</georss:line>"
|
107
|
+
geom = Geometry.from_georss(str)
|
108
|
+
geom.class.should eql(LineString)
|
109
|
+
ls.should == geom
|
110
|
+
|
111
|
+
str = "<georss:where><gml:LineString><gml:posList>-45.3 12.4 41.6 45.4</gml:posList></gml:LineString></georss:where>"
|
112
|
+
geom = Geometry.from_georss(str)
|
113
|
+
geom.class.should eql(LineString)
|
114
|
+
ls.should == geom
|
115
|
+
end
|
116
|
+
|
117
|
+
it "test_polygon_georss_read" do
|
118
|
+
linear_ring = LinearRing.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]])
|
119
|
+
polygon = Polygon.from_linear_rings([linear_ring])
|
120
|
+
|
121
|
+
str = "<hoyoyo:polygon featuretypetag=\"42\" > -45.3 12.4 41.6 \n\r 45.4 1.0698 \r 4.456 -45.3 12.4 </hoyoyo:polygon>"
|
122
|
+
geom = Geometry.from_georss(str)
|
123
|
+
geom.class.should eql(Polygon)
|
124
|
+
polygon.should == geom
|
125
|
+
|
126
|
+
str = "<georss:where>\r\t \n <gml:Polygon><gml:exterior> <gml:LinearRing><gml:posList> -45.3 \n\r 12.4 41.6 \n\t 45.4 1.0698 4.456 -45.3 12.4</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></georss:where>"
|
127
|
+
geom = Geometry.from_georss(str)
|
128
|
+
geom.class.should eql(Polygon)
|
129
|
+
polygon.should == geom
|
130
|
+
end
|
131
|
+
|
132
|
+
it "test_envelope_georss_read" do
|
133
|
+
e = Envelope.from_coordinates([[4.456,-45.3],[45.4,41.6]])
|
134
|
+
|
135
|
+
str = "<georss:box >-45.3 4.456 \n41.6 45.4</georss:box>"
|
136
|
+
geom = Geometry.from_georss(str)
|
137
|
+
geom.class.should eql(Envelope)
|
138
|
+
geom.should == e
|
139
|
+
|
140
|
+
str = "<georss:where><gml:Envelope><gml:lowerCorner>-45.3 \n 4.456</gml:lowerCorner><gml:upperCorner>41.6 \t\n 45.4</gml:upperCorner></gml:Envelope></georss:where>"
|
141
|
+
geom = Geometry.from_georss(str)
|
142
|
+
geom.class.should eql(Envelope)
|
143
|
+
geom.should == e
|
144
|
+
end
|
145
|
+
|
146
|
+
it "test_kml_read" do
|
147
|
+
g = Geometry.from_kml("<Point><coordinates>45,12,25</coordinates></Point>")
|
148
|
+
g.should be_a Point
|
149
|
+
g.should == Point.from_x_y_z(45,12,25)
|
150
|
+
|
151
|
+
g = Geometry.from_kml("<LineString>
|
152
|
+
<extrude>1</extrude>
|
153
|
+
<tessellate>1</tessellate>
|
154
|
+
<coordinates>
|
155
|
+
-122.364383,37.824664,0 -122.364152,37.824322,0
|
156
|
+
</coordinates>
|
157
|
+
</LineString>")
|
158
|
+
g.should be_a LineString
|
159
|
+
g.length.should eql(2)
|
160
|
+
g.should == LineString.from_points([Point.from_x_y_z(-122.364383,37.824664,0),Point.from_x_y_z(-122.364152,37.824322,0)],@@default_srid,true)
|
161
|
+
|
162
|
+
g = Geometry.from_kml("<Polygon>
|
163
|
+
<extrude>1</extrude>
|
164
|
+
<altitudeMode>relativeToGround</altitudeMode>
|
165
|
+
<outerBoundaryIs>
|
166
|
+
<LinearRing>
|
167
|
+
<coordinates>
|
168
|
+
-122.366278,37.818844,30
|
169
|
+
-122.365248,37.819267,30
|
170
|
+
-122.365640,37.819861,30
|
171
|
+
-122.366669,37.819429,30
|
172
|
+
-122.366278,37.818844,30
|
173
|
+
</coordinates>
|
174
|
+
</LinearRing>
|
175
|
+
</outerBoundaryIs>
|
176
|
+
<innerBoundaryIs>
|
177
|
+
<LinearRing>
|
178
|
+
<coordinates>
|
179
|
+
-122.366212,37.818977,30
|
180
|
+
-122.365424,37.819294,30
|
181
|
+
-122.365704,37.819731,30
|
182
|
+
-122.366488,37.819402,30
|
183
|
+
-122.366212,37.818977,30
|
184
|
+
</coordinates>
|
185
|
+
</LinearRing>
|
186
|
+
</innerBoundaryIs>
|
187
|
+
<innerBoundaryIs>
|
188
|
+
<LinearRing>
|
189
|
+
<coordinates>
|
190
|
+
-122.366212,37.818977,30
|
191
|
+
-122.365424,37.819294,30
|
192
|
+
-122.365704,37.819731,30
|
193
|
+
-122.366488,37.819402,30
|
194
|
+
-122.366212,37.818977,30
|
195
|
+
</coordinates>
|
196
|
+
</LinearRing>
|
197
|
+
</innerBoundaryIs>
|
198
|
+
</Polygon>")
|
199
|
+
g.should be_a Polygon
|
200
|
+
g.length.should eql(3)
|
201
|
+
end
|
202
|
+
|
203
|
+
it "test_to_kml_for_point_does_not_raise_type_error_if_geom_data_not_provided" do
|
204
|
+
point = Point.from_coordinates([1.6,2.8],123)
|
205
|
+
lambda { point.kml_representation }.should_not raise_error(TypeError)
|
206
|
+
end
|
207
|
+
|
208
|
+
it "test_to_kml_for_polygon_does_not_raise_type_error_if_geom_data_not_provided" do
|
209
|
+
polygon = Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],256)
|
210
|
+
lambda { polygon.kml_representation }.should_not raise_error(TypeError)
|
211
|
+
end
|
212
|
+
|
213
|
+
it "test_to_kml_for_line_string_does_not_raise_type_error_if_geom_data_not_provided" do
|
214
|
+
ls = LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)
|
215
|
+
lambda { ls.kml_representation }.should_not raise_error(TypeError)
|
216
|
+
end
|
217
|
+
|
218
|
+
end
|
@@ -0,0 +1,208 @@
|
|
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
|
+
include LineSpecHelper
|
16
|
+
|
17
|
+
before(:each) do
|
18
|
+
@line = LineString.from_points([mock(Point)])
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should instantiate" do
|
22
|
+
violated unless @line
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should have binary_geometry_type 2" do
|
26
|
+
@line.binary_geometry_type.should eql(2)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should have text_geometry_type" do
|
30
|
+
@line.text_geometry_type.should eql("LINESTRING")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should have a points array" do
|
34
|
+
@line.points.should be_instance_of(Array)
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "tu converted" do
|
38
|
+
|
39
|
+
it "should concat points" do
|
40
|
+
line_string = LineString::new
|
41
|
+
line_string.concat([Point.from_x_y(12.4,45.3),Point.from_x_y(45.4,41.6)])
|
42
|
+
|
43
|
+
line_string.length.should eql(2)
|
44
|
+
line_string[0].should == Point.from_x_y(12.4,45.3)
|
45
|
+
|
46
|
+
point=Point.from_x_y(123,45.8777)
|
47
|
+
line_string[0]=point
|
48
|
+
line_string[0].should == point
|
49
|
+
|
50
|
+
points=[Point.from_x_y(123,45.8777),Point.from_x_y(45.4,41.6)]
|
51
|
+
line_string.each_index {|i| line_string[i].should == points[i] }
|
52
|
+
|
53
|
+
point=Point.from_x_y(22.4,13.56)
|
54
|
+
line_string << point
|
55
|
+
line_string.length.should eql(3)
|
56
|
+
line_string[2].should eql(point)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should create" do
|
60
|
+
line_string = LineString.from_points([Point.from_x_y(12.4,-45.3),Point.from_x_y(45.4,41.6)],123)
|
61
|
+
line_string.class.should eql(LineString)
|
62
|
+
line_string.length.should eql(2)
|
63
|
+
line_string[0].should == Point.from_x_y(12.4,-45.3)
|
64
|
+
line_string[1].should == Point.from_x_y(45.4,41.6)
|
65
|
+
|
66
|
+
line_string = LineString.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698]],123)
|
67
|
+
line_string.class.should eql(LineString)
|
68
|
+
line_string.length.should eql(3)
|
69
|
+
line_string[0].should == Point.from_x_y(12.4,-45.3)
|
70
|
+
line_string[1].should == Point.from_x_y(45.4,41.6)
|
71
|
+
|
72
|
+
line_string = LineString.from_coordinates([[12.4,-45.3,123],[45.4,41.6,333],[4.456,1.0698,987]],123,true)
|
73
|
+
line_string.class.should eql(LineString)
|
74
|
+
line_string.length.should eql(3)
|
75
|
+
line_string[0].should == Point.from_x_y_z(12.4,-45.3,123,123)
|
76
|
+
|
77
|
+
line_string = LineString.from_coordinates([[12.4,-45.3,123],[45.4,41.6,333],[4.456,1.0698,987]],123,true)
|
78
|
+
line_string.class.should eql(LineString)
|
79
|
+
line_string.length.should eql(3)
|
80
|
+
line_string[0].should == Point.from_x_y_z(12.4,-45.3,123,123)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should bbox it" do
|
84
|
+
bbox = LineString.from_coordinates([[12.4,-45.3,123],[45.4,41.6,333],[4.456,1.0698,987]],123,true).bounding_box
|
85
|
+
bbox.length.should eql(2)
|
86
|
+
bbox[0].should == Point.from_x_y_z(4.456,-45.3,123)
|
87
|
+
bbox[1].should == Point.from_x_y_z(45.4,41.6,987)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should test_line_string_equal" do
|
91
|
+
line_string1 = LineString.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698]],123)
|
92
|
+
line_string2 = LineString.from_coordinates([[12.4,-45.3],[45.4,41.6]],123)
|
93
|
+
point = Point.from_x_y(12.4,-45.3,123)
|
94
|
+
|
95
|
+
line_string1.should == LineString.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698]],123)
|
96
|
+
line_string1.should_not == line_string2
|
97
|
+
line_string1.should_not == point
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should test_line_string_binary" do
|
101
|
+
line_string = LineString.from_coordinates([[12.4,-45.3],[45.4,41.6]],256)
|
102
|
+
line_string.as_hex_ewkb.should eql("01020000200001000002000000CDCCCCCCCCCC28406666666666A646C03333333333B34640CDCCCCCCCCCC4440")
|
103
|
+
|
104
|
+
line_string = LineString.from_coordinates([[12.4,-45.3,35.3],[45.4,41.6,12.3]],256,true)
|
105
|
+
line_string.as_hex_ewkb.should eql("01020000A00001000002000000CDCCCCCCCCCC28406666666666A646C06666666666A641403333333333B34640CDCCCCCCCCCC44409A99999999992840")
|
106
|
+
|
107
|
+
line_string = LineString.from_coordinates([[12.4,-45.3,35.3,45.1],[45.4,41.6,12.3,40.23]],256,true,true)
|
108
|
+
line_string.as_hex_ewkb.should eql("01020000E00001000002000000CDCCCCCCCCCC28406666666666A646C06666666666A64140CDCCCCCCCC8C46403333333333B34640CDCCCCCCCCCC44409A999999999928403D0AD7A3701D4440")
|
109
|
+
end
|
110
|
+
|
111
|
+
it "test_line_string_text" do
|
112
|
+
line_string = LineString.from_coordinates([[12.4,-45.3],[45.4,41.6]],256)
|
113
|
+
line_string.as_ewkt.should eql("SRID=256;LINESTRING(12.4 -45.3,45.4 41.6)")
|
114
|
+
|
115
|
+
line_string = LineString.from_coordinates([[12.4,-45.3,35.3],[45.4,41.6,12.3]],256,true)
|
116
|
+
line_string.as_ewkt.should eql("SRID=256;LINESTRING(12.4 -45.3 35.3,45.4 41.6 12.3)")
|
117
|
+
|
118
|
+
line_string = LineString.from_coordinates([[12.4,-45.3,35.3],[45.4,41.6,12.3]],256,false,true)
|
119
|
+
line_string.as_ewkt.should eql("SRID=256;LINESTRINGM(12.4 -45.3 35.3,45.4 41.6 12.3)")
|
120
|
+
|
121
|
+
line_string = LineString.from_coordinates([[12.4,-45.3,35.3,25.2],[45.4,41.6,12.3,13.75]],256,true,true)
|
122
|
+
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)")
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should test_linear_ring_creation" do
|
126
|
+
#testing just the constructor helpers since the rest is the same as for line_string
|
127
|
+
linear_ring = LinearRing.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],345)
|
128
|
+
linear_ring.class.should eql(LinearRing)
|
129
|
+
linear_ring.length.should eql(4)
|
130
|
+
linear_ring.should be_closed
|
131
|
+
linear_ring[1].should == Point.from_x_y(45.4,41.6,345)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "> Coordinates" do
|
136
|
+
|
137
|
+
before(:each) do
|
138
|
+
Point.should_receive(:from_coordinates).
|
139
|
+
exactly(4).with(anything, 4326, false, false).and_return(mock_point)
|
140
|
+
@line = LineString.from_coordinates([1.2,2.5,2.2,4.5])
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should instantiate from coordinates" do
|
144
|
+
@line.points.length.should eql(4)
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
describe "> Instantiated" do
|
150
|
+
|
151
|
+
before(:each) do
|
152
|
+
@line = LineString.from_points(mock_points(7))
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should be closed if the last point equals the first" do
|
156
|
+
@line.push(@line.first)
|
157
|
+
@line.should be_closed
|
158
|
+
@line.length.should eql(8)
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should print the text representation" do
|
162
|
+
@line.text_representation.should eql("0 0,1 1,2 2,3 3,4 4,5 5,6 6")
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should print the georss_simple_representation" do
|
166
|
+
@line.georss_simple_representation({:geom_attr => nil}).
|
167
|
+
should eql("<georss:line>0 0 1 1 2 2 3 3 4 4 5 5 6 6</georss:line>\n")
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should map the georss_poslist" do
|
171
|
+
@line.georss_poslist.should eql("0 0 1 1 2 2 3 3 4 4 5 5 6 6")
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should print the kml_representation" do
|
175
|
+
@line.kml_representation.should
|
176
|
+
eql("<LineString>\n<coordinates>0,0 1,1 2,2 3,3 4,4 5,5 6,6</coordinates>\n</LineString>\n")
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should print the kml_poslist without reverse or z" do
|
180
|
+
@line.kml_poslist({}).should eql("0,0 1,1 2,2 3,3 4,4 5,5 6,6")
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should print the kml_poslist reverse" do
|
184
|
+
@line.kml_poslist({:reverse => true}).should eql("6,6 5,5 4,4 3,3 2,2 1,1 0,0")
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe "> Distances..." do
|
189
|
+
before(:each) do
|
190
|
+
@p1 = mock(Point)
|
191
|
+
@p2 = mock(Point)
|
192
|
+
@p3 = mock(Point)
|
193
|
+
@line = LineString.from_points([@p1,@p2,@p3])
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should print the length with haversine" do
|
197
|
+
@p1.should_receive(:spherical_distance).with(@p2).and_return(10)
|
198
|
+
@p2.should_receive(:spherical_distance).with(@p3).and_return(10)
|
199
|
+
@line.spherical_distance.should eql(20)
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should print lenght as euclidian" do
|
203
|
+
@p1.should_receive(:euclidian_distance).with(@p2).and_return(10)
|
204
|
+
@p2.should_receive(:euclidian_distance).with(@p3).and_return(10)
|
205
|
+
@line.euclidian_distance.should eql(20)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|