ppe-georuby 1.7.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/History.txt +4 -0
- data/LICENSE +21 -0
- data/README.txt +118 -0
- data/Rakefile +48 -0
- data/VERSION +1 -0
- data/lib/geo_ruby.rb +22 -0
- data/lib/geo_ruby/gpx.rb +1 -0
- data/lib/geo_ruby/gpx4r/gpx.rb +117 -0
- data/lib/geo_ruby/shp.rb +1 -0
- data/lib/geo_ruby/shp4r/dbf.rb +41 -0
- data/lib/geo_ruby/shp4r/shp.rb +697 -0
- data/lib/geo_ruby/simple_features/envelope.rb +167 -0
- data/lib/geo_ruby/simple_features/ewkb_parser.rb +216 -0
- data/lib/geo_ruby/simple_features/ewkt_parser.rb +336 -0
- data/lib/geo_ruby/simple_features/geometry.rb +228 -0
- data/lib/geo_ruby/simple_features/geometry_collection.rb +136 -0
- data/lib/geo_ruby/simple_features/geometry_factory.rb +81 -0
- data/lib/geo_ruby/simple_features/georss_parser.rb +135 -0
- data/lib/geo_ruby/simple_features/helper.rb +18 -0
- data/lib/geo_ruby/simple_features/line_string.rb +206 -0
- data/lib/geo_ruby/simple_features/linear_ring.rb +12 -0
- data/lib/geo_ruby/simple_features/multi_line_string.rb +51 -0
- data/lib/geo_ruby/simple_features/multi_point.rb +46 -0
- data/lib/geo_ruby/simple_features/multi_polygon.rb +52 -0
- data/lib/geo_ruby/simple_features/point.rb +364 -0
- data/lib/geo_ruby/simple_features/polygon.rb +157 -0
- data/ppe-georuby.gemspec +133 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +82 -0
- data/spec/data/gpx/fells_loop.gpx +1077 -0
- data/spec/data/gpx/long.gpx +1642 -0
- data/spec/data/gpx/long.kml +31590 -0
- data/spec/data/gpx/long.nmea +2220 -0
- data/spec/data/gpx/short.gpx +13634 -0
- data/spec/data/gpx/short.kml +130 -0
- data/spec/data/gpx/tracktreks.gpx +706 -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/gpx4r/gpx_spec.rb +106 -0
- data/spec/geo_ruby/shp4r/shp_spec.rb +240 -0
- data/spec/geo_ruby/simple_features/envelope_spec.rb +45 -0
- data/spec/geo_ruby/simple_features/ewkb_parser_spec.rb +158 -0
- data/spec/geo_ruby/simple_features/ewkt_parser_spec.rb +179 -0
- data/spec/geo_ruby/simple_features/geometry_collection_spec.rb +55 -0
- data/spec/geo_ruby/simple_features/geometry_factory_spec.rb +11 -0
- data/spec/geo_ruby/simple_features/geometry_spec.rb +32 -0
- data/spec/geo_ruby/simple_features/georss_parser_spec.rb +218 -0
- data/spec/geo_ruby/simple_features/line_string_spec.rb +245 -0
- data/spec/geo_ruby/simple_features/linear_ring_spec.rb +14 -0
- data/spec/geo_ruby/simple_features/multi_line_string_spec.rb +54 -0
- data/spec/geo_ruby/simple_features/multi_point_spec.rb +35 -0
- data/spec/geo_ruby/simple_features/multi_polygon_spec.rb +50 -0
- data/spec/geo_ruby/simple_features/point_spec.rb +356 -0
- data/spec/geo_ruby/simple_features/polygon_spec.rb +108 -0
- data/spec/geo_ruby_spec.rb +27 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +65 -0
- metadata +162 -0
@@ -0,0 +1,179 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe EWKTParser do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@factory = GeometryFactory::new
|
7
|
+
@ewkt_parser = EWKTParser::new(@factory)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "test_point" do
|
11
|
+
ewkt="POINT( 3.456 0.123)"
|
12
|
+
@ewkt_parser.parse(ewkt)
|
13
|
+
point = @factory.geometry
|
14
|
+
point.should be_instance_of Point
|
15
|
+
point.should == Point.from_x_y(3.456,0.123)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "test_point_with_srid" do
|
19
|
+
ewkt="SRID=245;POINT(0.0 2.0)"
|
20
|
+
@ewkt_parser.parse(ewkt)
|
21
|
+
point = @factory.geometry
|
22
|
+
point.should be_instance_of Point
|
23
|
+
point.should == Point.from_x_y(0,2,245)
|
24
|
+
point.srid.should eql(245)
|
25
|
+
ewkt.should == point.as_ewkt(true,false)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "test_point3dz" do
|
29
|
+
ewkt="POINT(3.456 0.123 123.667)"
|
30
|
+
@ewkt_parser.parse(ewkt)
|
31
|
+
point = @factory.geometry
|
32
|
+
point.should be_instance_of Point
|
33
|
+
point.should == Point.from_x_y_z(3.456,0.123,123.667)
|
34
|
+
ewkt.should == point.as_ewkt(false)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "test_point3dm" do
|
38
|
+
ewkt="POINTM(3.456 0.123 123.667)"
|
39
|
+
@ewkt_parser.parse(ewkt)
|
40
|
+
point = @factory.geometry
|
41
|
+
point.should be_instance_of Point
|
42
|
+
point.should == Point.from_x_y_m(3.456,0.123,123.667)
|
43
|
+
ewkt.should == point.as_ewkt(false)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "test_point4d" do
|
47
|
+
ewkt="POINT(3.456 0.123 123.667 15.0)"
|
48
|
+
@ewkt_parser.parse(ewkt)
|
49
|
+
point = @factory.geometry
|
50
|
+
point.should be_instance_of Point
|
51
|
+
point.should == Point.from_x_y_z_m(3.456,0.123,123.667,15.0)
|
52
|
+
ewkt.should == point.as_ewkt(false)
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
it "test_linestring" do
|
57
|
+
@ewkt_parser.parse("LINESTRING(3.456 0.123,123.44 123.56,54555.22 123.3)")
|
58
|
+
line_string = @factory.geometry
|
59
|
+
line_string.should be_instance_of LineString
|
60
|
+
line_string.should == LineString.from_coordinates([[3.456,0.123],[123.44,123.56],[54555.22,123.3]])
|
61
|
+
|
62
|
+
@ewkt_parser.parse("SRID=256;LINESTRING(12.4 -45.3,45.4 41.6)")
|
63
|
+
line_string = @factory.geometry
|
64
|
+
line_string.should be_instance_of LineString
|
65
|
+
line_string.should == LineString.from_coordinates([[12.4,-45.3],[45.4,41.6]],256)
|
66
|
+
|
67
|
+
@ewkt_parser.parse("SRID=256;LINESTRING(12.4 -45.3 35.3,45.4 41.6 12.3)")
|
68
|
+
line_string = @factory.geometry
|
69
|
+
line_string.should be_instance_of LineString
|
70
|
+
line_string.should == LineString.from_coordinates([[12.4,-45.3,35.3],[45.4,41.6,12.3]],256,true)
|
71
|
+
|
72
|
+
@ewkt_parser.parse("SRID=256;LINESTRINGM(12.4 -45.3 35.3,45.4 41.6 12.3)")
|
73
|
+
line_string = @factory.geometry
|
74
|
+
line_string.should be_instance_of LineString
|
75
|
+
line_string.should == LineString.from_coordinates([[12.4,-45.3,35.3],[45.4,41.6,12.3]],256,false,true)
|
76
|
+
|
77
|
+
@ewkt_parser.parse("SRID=256;LINESTRING(12.4 -45.3 35.3 25.2,45.4 41.6 12.3 13.75)")
|
78
|
+
line_string = @factory.geometry
|
79
|
+
line_string.should be_instance_of LineString
|
80
|
+
line_string.should == LineString.from_coordinates([[12.4,-45.3,35.3,25.2],[45.4,41.6,12.3,13.75]],256,true,true)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "test_polygon" do
|
84
|
+
@ewkt_parser.parse("POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1,3 1,3 3,1 3,1 1))")
|
85
|
+
polygon = @factory.geometry
|
86
|
+
polygon.should be_instance_of Polygon
|
87
|
+
polygon.should == Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)
|
88
|
+
|
89
|
+
@ewkt_parser.parse("SRID=256;POLYGON( ( 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))")
|
90
|
+
polygon = @factory.geometry
|
91
|
+
polygon.should be_instance_of Polygon
|
92
|
+
polygon.should == 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,true)
|
93
|
+
|
94
|
+
@ewkt_parser.parse("SRID=256;POLYGONM((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))")
|
95
|
+
polygon = @factory.geometry
|
96
|
+
polygon.should be_instance_of Polygon
|
97
|
+
polygon.should == 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,false,true)
|
98
|
+
|
99
|
+
@ewkt_parser.parse("SRID=256;POLYGON((0 0 2 -45.1,4 0 2 5,4 4 2 4.67,0 4 2 1.34,0 0 2 -45.1),(1 1 2 12.3,3 1 2 123,3 3 2 12.2,1 3 2 12,1 1 2 12.3))")
|
100
|
+
polygon = @factory.geometry
|
101
|
+
polygon.should be_instance_of Polygon
|
102
|
+
polygon.should == Polygon.from_coordinates([[[0,0,2,-45.1],[4,0,2,5],[4,4,2,4.67],[0,4,2,1.34],[0,0,2,-45.1]],[[1,1,2,12.3],[3,1,2,123],[3,3,2,12.2],[1,3,2,12],[1,1,2,12.3]]],256,true,true)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "test_multi_point" do
|
106
|
+
#Form output by the current version of PostGIS. Future versions will output the one in the specification
|
107
|
+
@ewkt_parser.parse("SRID=444;MULTIPOINT(12.4 -123.3,-65.1 123.4,123.55555555 123)")
|
108
|
+
multi_point = @factory.geometry
|
109
|
+
multi_point.should be_instance_of MultiPoint
|
110
|
+
multi_point.should == MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]],444)
|
111
|
+
multi_point.srid.should eql(444)
|
112
|
+
multi_point[0].srid.should eql(444)
|
113
|
+
|
114
|
+
@ewkt_parser.parse("SRID=444;MULTIPOINT(12.4 -123.3 4.5,-65.1 123.4 6.7,123.55555555 123 7.8)")
|
115
|
+
multi_point = @factory.geometry
|
116
|
+
multi_point.should be_instance_of MultiPoint
|
117
|
+
multi_point.should == MultiPoint.from_coordinates([[12.4,-123.3,4.5],[-65.1,123.4,6.7],[123.55555555,123,7.8]],444,true)
|
118
|
+
multi_point.srid.should eql(444)
|
119
|
+
multi_point[0].srid.should eql(444)
|
120
|
+
|
121
|
+
#Form in the EWKT specification (from the OGC)
|
122
|
+
@ewkt_parser.parse("SRID=444;MULTIPOINT( ( 12.4 -123.3 4.5 ) , (-65.1 123.4 6.7),(123.55555555 123 7.8))")
|
123
|
+
multi_point = @factory.geometry
|
124
|
+
multi_point.should be_instance_of MultiPoint
|
125
|
+
multi_point.should == MultiPoint.from_coordinates([[12.4,-123.3,4.5],[-65.1,123.4,6.7],[123.55555555,123,7.8]],444,true)
|
126
|
+
multi_point.srid.should eql(444)
|
127
|
+
multi_point[0].srid.should eql(444)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "test_multi_line_string" do
|
131
|
+
@ewkt_parser.parse("SRID=256;MULTILINESTRING((1.5 45.2,-54.12312 -0.012),(1.5 45.2,-54.12312 -0.012,45.123 123.3))")
|
132
|
+
multi_line_string = @factory.geometry
|
133
|
+
multi_line_string.should be_instance_of MultiLineString
|
134
|
+
multi_line_string.should == 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)
|
135
|
+
multi_line_string.srid.should eql(256)
|
136
|
+
multi_line_string[0].srid.should eql(256)
|
137
|
+
|
138
|
+
@ewkt_parser.parse("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))")
|
139
|
+
multi_line_string = @factory.geometry
|
140
|
+
multi_line_string.should be_instance_of MultiLineString
|
141
|
+
multi_line_string.should == 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)
|
142
|
+
multi_line_string.srid.should eql(256)
|
143
|
+
multi_line_string[0].srid.should eql(256)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "test_multi_polygon" do
|
147
|
+
ewkt="SRID=256;MULTIPOLYGON(((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)),((0.0 0.0,4.0 0.0,4.0 4.0,0.0 4.0,0.0 0.0),(1.0 1.0,3.0 1.0,3.0 3.0,1.0 3.0,1.0 1.0)))"
|
148
|
+
@ewkt_parser.parse(ewkt)
|
149
|
+
multi_polygon = @factory.geometry
|
150
|
+
multi_polygon.should be_instance_of MultiPolygon
|
151
|
+
multi_polygon.should == MultiPolygon.from_polygons([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),Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)],256)
|
152
|
+
multi_polygon.srid.should eql(256)
|
153
|
+
multi_polygon[0].srid.should eql(256)
|
154
|
+
ewkt.should == multi_polygon.as_ewkt
|
155
|
+
|
156
|
+
ewkt="MULTIPOLYGON(((12.4 -45.3 2,45.4 41.6 3,4.456 1.0698 4,12.4 -45.3 2),(2.4 5.3 1,5.4 1.4263 3.44,14.46 1.06 4.5,2.4 5.3 1)),((0 0 5.6,4 0 5.4,4 4 1,0 4 23,0 0 5.6),(1 1 2.3,3 1 4,3 3 5,1 3 6,1 1 2.3)))"
|
157
|
+
@ewkt_parser.parse(ewkt)
|
158
|
+
multi_polygon = @factory.geometry
|
159
|
+
multi_polygon.should be_instance_of MultiPolygon
|
160
|
+
multi_polygon.should == MultiPolygon.from_polygons([Polygon.from_coordinates([[[12.4,-45.3,2],[45.4,41.6,3],[4.456,1.0698,4],[12.4,-45.3,2]],[[2.4,5.3,1],[5.4,1.4263,3.44],[14.46,1.06,4.5],[2.4,5.3,1]]],4326,true),Polygon.from_coordinates([[[0,0,5.6],[4,0,5.4],[4,4,1],[0,4,23],[0,0,5.6]],[[1,1,2.3],[3,1,4],[3,3,5],[1,3,6],[1,1,2.3]]],4326,true)],4326,true)
|
161
|
+
multi_polygon.srid.should eql(4326)
|
162
|
+
multi_polygon[0].srid.should eql(4326)
|
163
|
+
end
|
164
|
+
|
165
|
+
it "test_geometry_collection" do
|
166
|
+
@ewkt_parser.parse("SRID=256;GEOMETRYCOLLECTION(POINT(4.67 45.4),LINESTRING(5.7 12.45,67.55 54),POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1,3 1,3 3,1 3,1 1)))")
|
167
|
+
geometry_collection = @factory.geometry
|
168
|
+
geometry_collection.should be_instance_of GeometryCollection
|
169
|
+
geometry_collection.should == 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],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)],256)
|
170
|
+
geometry_collection[0].srid.should eql(256)
|
171
|
+
|
172
|
+
@ewkt_parser.parse("SRID=256;GEOMETRYCOLLECTIONM(POINTM(4.67 45.4 45.6),LINESTRINGM(5.7 12.45 5.6,67.55 54 6.7))")
|
173
|
+
geometry_collection = @factory.geometry
|
174
|
+
geometry_collection.should be_instance_of GeometryCollection
|
175
|
+
geometry_collection.should == 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)
|
176
|
+
geometry_collection[0].srid.should eql(256)
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
@@ -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,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_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)],4326,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
|