nofxx-georuby 1.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/History.txt +4 -0
  2. data/LICENSE +21 -0
  3. data/README.txt +59 -0
  4. data/Rakefile +49 -0
  5. data/VERSION.yml +4 -0
  6. data/lib/geo_ruby.rb +21 -0
  7. data/lib/geo_ruby/base/envelope.rb +167 -0
  8. data/lib/geo_ruby/base/ewkb_parser.rb +216 -0
  9. data/lib/geo_ruby/base/ewkt_parser.rb +336 -0
  10. data/lib/geo_ruby/base/geometry.rb +234 -0
  11. data/lib/geo_ruby/base/geometry_collection.rb +136 -0
  12. data/lib/geo_ruby/base/geometry_factory.rb +81 -0
  13. data/lib/geo_ruby/base/georss_parser.rb +135 -0
  14. data/lib/geo_ruby/base/helper.rb +18 -0
  15. data/lib/geo_ruby/base/line_string.rb +184 -0
  16. data/lib/geo_ruby/base/linear_ring.rb +12 -0
  17. data/lib/geo_ruby/base/multi_line_string.rb +39 -0
  18. data/lib/geo_ruby/base/multi_point.rb +41 -0
  19. data/lib/geo_ruby/base/multi_polygon.rb +37 -0
  20. data/lib/geo_ruby/base/point.rb +310 -0
  21. data/lib/geo_ruby/base/polygon.rb +150 -0
  22. data/lib/geo_ruby/shp4r/dbf.rb +180 -0
  23. data/lib/geo_ruby/shp4r/shp.rb +701 -0
  24. data/spec/data/multipoint.dbf +0 -0
  25. data/spec/data/multipoint.shp +0 -0
  26. data/spec/data/multipoint.shx +0 -0
  27. data/spec/data/point.dbf +0 -0
  28. data/spec/data/point.shp +0 -0
  29. data/spec/data/point.shx +0 -0
  30. data/spec/data/polygon.dbf +0 -0
  31. data/spec/data/polygon.shp +0 -0
  32. data/spec/data/polygon.shx +0 -0
  33. data/spec/data/polyline.dbf +0 -0
  34. data/spec/data/polyline.shp +0 -0
  35. data/spec/data/polyline.shx +0 -0
  36. data/spec/geo_ruby/base/envelope_spec.rb +45 -0
  37. data/spec/geo_ruby/base/ewkb_parser_spec.rb +158 -0
  38. data/spec/geo_ruby/base/ewkt_parser_spec.rb +179 -0
  39. data/spec/geo_ruby/base/geometry_collection_spec.rb +55 -0
  40. data/spec/geo_ruby/base/geometry_factory_spec.rb +11 -0
  41. data/spec/geo_ruby/base/geometry_spec.rb +32 -0
  42. data/spec/geo_ruby/base/georss_parser_spec.rb +218 -0
  43. data/spec/geo_ruby/base/line_string_spec.rb +208 -0
  44. data/spec/geo_ruby/base/linear_ring_spec.rb +14 -0
  45. data/spec/geo_ruby/base/multi_line_string_spec.rb +35 -0
  46. data/spec/geo_ruby/base/multi_point_spec.rb +29 -0
  47. data/spec/geo_ruby/base/multi_polygon_spec.rb +35 -0
  48. data/spec/geo_ruby/base/point_spec.rb +275 -0
  49. data/spec/geo_ruby/base/polygon_spec.rb +108 -0
  50. data/spec/geo_ruby/shp4r/shp_spec.rb +238 -0
  51. data/spec/geo_ruby_spec.rb +27 -0
  52. data/spec/spec.opts +6 -0
  53. data/spec/spec_helper.rb +12 -0
  54. metadata +123 -0
@@ -0,0 +1,14 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe LinearRing do
4
+ # before(:each) do
5
+ # @po = Polygon.new
6
+ # end
7
+
8
+ it "should instantiate" do
9
+ lr = LinearRing.new([1.2,2.5,2.2,4.5])
10
+ lr.should be_instance_of(LinearRing)
11
+ end
12
+
13
+
14
+ end
@@ -0,0 +1,35 @@
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
+ end
@@ -0,0 +1,29 @@
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
+ end
@@ -0,0 +1,35 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe MultiPolygon do
4
+
5
+ it "test_multi_polygon_creation" do
6
+ multi_polygon1 = 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)
7
+ multi_polygon1.should be_instance_of MultiPolygon
8
+ multi_polygon1.length.should eql(2)
9
+ multi_polygon1[0].should == 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)
10
+
11
+ multi_polygon2 = MultiPolygon.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]]],[[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]]],256)
12
+ multi_polygon1.should be_instance_of MultiPolygon
13
+ multi_polygon1.length.should eql(2)
14
+
15
+ multi_polygon2[0].should == 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)
16
+ multi_polygon1.should == multi_polygon2
17
+ end
18
+
19
+ it "test_multi_polygon_binary" do
20
+ multi_polygon = 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)
21
+ multi_polygon.as_hex_ewkb.should eql("0106000020000100000200000001030000000200000004000000CDCCCCCCCCCC28406666666666A646C03333333333B34640CDCCCCCCCCCC44406DE7FBA9F1D211403D2CD49AE61DF13FCDCCCCCCCCCC28406666666666A646C004000000333333333333034033333333333315409A999999999915408A8EE4F21FD2F63FEC51B81E85EB2C40F6285C8FC2F5F03F3333333333330340333333333333154001030000000200000005000000000000000000000000000000000000000000000000001040000000000000000000000000000010400000000000001040000000000000000000000000000010400000000000000000000000000000000005000000000000000000F03F000000000000F03F0000000000000840000000000000F03F00000000000008400000000000000840000000000000F03F0000000000000840000000000000F03F000000000000F03F")
22
+
23
+ multi_polygon = MultiPolygon.from_polygons([Polygon.from_coordinates([[[12.4,-45.3,1.2],[45.4,41.6,1.2],[4.456,1.0698,1.2],[12.4,-45.3,1.2]],[[2.4,5.3,1.2],[5.4,1.4263,1.2],[14.46,1.06,1.2],[2.4,5.3,1.2]]],256,false,true),Polygon.from_coordinates([[[0,0,1.2],[4,0,1.2],[4,4,2.3],[0,4,1.2],[0,0,1.2]],[[1,1,2.2],[3,1,3.3],[3,3,1.1],[1,3,2.4],[1,1,2.2]]],256,false,true)],256,false,true)
24
+ multi_polygon.as_hex_ewkb.should eql("0106000020000100000200000001030000400200000004000000CDCCCCCCCCCC28406666666666A646C0333333333333F33F3333333333B34640CDCCCCCCCCCC4440333333333333F33F6DE7FBA9F1D211403D2CD49AE61DF13F333333333333F33FCDCCCCCCCCCC28406666666666A646C0333333333333F33F0400000033333333333303403333333333331540333333333333F33F9A999999999915408A8EE4F21FD2F63F333333333333F33FEC51B81E85EB2C40F6285C8FC2F5F03F333333333333F33F33333333333303403333333333331540333333333333F33F0103000040020000000500000000000000000000000000000000000000333333333333F33F00000000000010400000000000000000333333333333F33F00000000000010400000000000001040666666666666024000000000000000000000000000001040333333333333F33F00000000000000000000000000000000333333333333F33F05000000000000000000F03F000000000000F03F9A999999999901400000000000000840000000000000F03F6666666666660A40000000000000084000000000000008409A9999999999F13F000000000000F03F00000000000008403333333333330340000000000000F03F000000000000F03F9A99999999990140")
25
+ end
26
+
27
+ it "test_multi_polygon_text" do
28
+ multi_polygon = 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)
29
+ multi_polygon.as_ewkt.should eql("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,4 0,4 4,0 4,0 0),(1 1,3 1,3 3,1 3,1 1)))")
30
+
31
+ multi_polygon = 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]]],@@default_srid,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]]],@@default_srid,true)],@@default_srid,true)
32
+ multi_polygon.as_ewkt.should eql("SRID=4326;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)))")
33
+ end
34
+
35
+ end
@@ -0,0 +1,275 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
3
+
4
+ describe Point do
5
+ before(:each) do
6
+ @point = Point.new(4326)
7
+ end
8
+
9
+ it "should instantiatember" do
10
+ violated unless @point
11
+ @point.should be_instance_of(Point)
12
+ end
13
+
14
+ it "should be subclassable" do
15
+ place = Class.new(Point)
16
+ p = place.from_x_y(1,2)
17
+ p.should be_a place
18
+ end
19
+
20
+ it "should have binary_geometry_type 2" do
21
+ @point.binary_geometry_type.should eql(1)
22
+ end
23
+
24
+ it "should have the correct srid" do
25
+ @point.srid.should eql(4326)
26
+ end
27
+
28
+ it "should not have z or m" do
29
+ @point.with_z.should be_false
30
+ @point.should_not be_with_z
31
+ @point.with_m.should be_false
32
+ @point.should_not be_with_m
33
+ end
34
+
35
+ it "should set params to 0.0" do
36
+ @point.x.should eql(0.0)
37
+ @point.y.should eql(0.0)
38
+ @point.z.should eql(0.0)
39
+ @point.m.should eql(0.0)
40
+ end
41
+
42
+ it "should compare ok" do
43
+ point1= Point::new
44
+ point1.set_x_y(1.5,45.4)
45
+ point2= Point::new
46
+ point2.set_x_y(1.5,45.4)
47
+ point3= Point::new
48
+ point3.set_x_y(4.5,12.3)
49
+ point4= Point::new
50
+ point4.set_x_y_z(1.5,45.4,423)
51
+ point5= Point::new
52
+ point5.set_x_y(1.5,45.4)
53
+ point5.m=15
54
+ geometry= Geometry::new
55
+
56
+ point1.should == point2
57
+ point1.should_not == point3
58
+ point1.should_not == point4
59
+ point1.should_not == point5
60
+ point1.should_not == geometry
61
+ end
62
+
63
+ describe "> Instantiation" do
64
+
65
+ it "should instantiate a 2d point" do
66
+ point = Point.from_x_y(10,20,123)
67
+ point.x.should eql(10)
68
+ point.y.should eql(20)
69
+ point.srid.should eql(123)
70
+ point.z.should eql(0.0)
71
+ end
72
+
73
+ it "should instantiate a 3d point" do
74
+ point = Point.from_x_y_z(-10,-20,-30)
75
+ point.x.should eql(-10)
76
+ point.y.should eql(-20)
77
+ point.z.should eql(-30)
78
+ end
79
+
80
+ it "should instantiate a 3d(m) point" do
81
+ point = Point.from_x_y_m(10,20,30)
82
+ point.x.should eql(10)
83
+ point.y.should eql(20)
84
+ point.m.should eql(30)
85
+ point.z.should eql(0.0)
86
+ end
87
+
88
+ it "should instantiate a 4d point" do
89
+ point = Point.from_x_y_z_m(10,20,30,40,123)
90
+ point.x.should eql(10)
91
+ point.y.should eql(20)
92
+ point.z.should eql(30)
93
+ point.m.should eql(40)
94
+ point.srid.should eql(123)
95
+ end
96
+
97
+ it "should instantiate a point from polar coordinates" do
98
+ point = Point.from_r_t(1.4142,45)
99
+ point.y.should be_close(1, 0.00001)
100
+ point.x.should be_close(1, 0.00001)
101
+ end
102
+
103
+ it "should instantiate from coordinates x,y" do
104
+ point = Point.from_coordinates([1.6,2.8],123)
105
+ point.x.should eql(1.6)
106
+ point.y.should eql(2.8)
107
+ point.should_not be_with_z
108
+ point.z.should eql(0.0)
109
+ point.srid.should eql(123)
110
+ end
111
+
112
+ it "should instantiate from coordinates x,y,z" do
113
+ point = Point.from_coordinates([1.6,2.8,3.4],123, true)
114
+ point.x.should eql(1.6)
115
+ point.y.should eql(2.8)
116
+ point.z.should eql(3.4)
117
+ point.should be_with_z
118
+ point.srid.should eql(123)
119
+ end
120
+
121
+ it "should instantiate from coordinates x,y,z,m" do
122
+ point = Point.from_coordinates([1.6,2.8,3.4,15],123, true, true)
123
+ point.x.should eql(1.6)
124
+ point.y.should eql(2.8)
125
+ point.z.should eql(3.4)
126
+ point.m.should eql(15)
127
+ point.should be_with_z
128
+ point.should be_with_m
129
+ point.srid.should eql(123)
130
+ end
131
+
132
+ it "should have a bbox" do
133
+ bbox = Point.from_x_y_z_m(-1.6,2.8,-3.4,15,123).bounding_box
134
+ bbox.length.should eql(2)
135
+ bbox[0].should == Point.from_x_y_z(-1.6,2.8,-3.4)
136
+ bbox[1].should == Point.from_x_y_z(-1.6,2.8,-3.4)
137
+ end
138
+
139
+ it "should parse lat long" do
140
+ Point.from_latlong("-20° 47' 26.37","-20° 47' 26.37").x.should be_close(-20.790658, 0.00001)
141
+ Point.from_latlong("20° 47' 26.378","20° 47' 26.378").y.should be_close(20.790658, 0.00001)
142
+ end
143
+
144
+ it "should parse lat long w/o sec" do
145
+ Point.from_latlong("-20°47′26″","-20°47′26″").x.should be_close(-20.790555, 0.00001)
146
+ Point.from_latlong("20°47′26″","20°47′26″").y.should be_close(20.790555, 0.00001)
147
+ end
148
+
149
+ it "should accept with W or S notation" do
150
+ Point.from_latlong("20° 47' 26.37 W","20° 47' 26.37 S").x.should be_close(-20.790658, 0.00001)
151
+ Point.from_latlong("20° 47' 26.37 W","20° 47' 26.37 S").y.should be_close(-20.790658, 0.00001)
152
+ end
153
+
154
+ it "should instantiate a point from positive degrees" do
155
+ point = Point.from_latlong('47`20 06.09E','22`50 77.35N')
156
+ point.y.should be_close(22.8548194, 0.000001)
157
+ point.x.should be_close(47.335025, 0.000001)
158
+ end
159
+
160
+ it "should instantiate a point from negative degrees" do
161
+ point = Point.from_latlong('47`20 06.09W','22`50 77.35S')
162
+ point.y.should be_close(-22.8548194, 0.000001)
163
+ point.x.should be_close(-47.335025, 0.000001)
164
+ end
165
+
166
+ it "should print out nicely" do
167
+ Point.from_x_y(47.88, -20.1).as_latlong.should eql("47°52′48″, -20°06′00″")
168
+ end
169
+
170
+ it "should print out nicely" do
171
+ Point.from_x_y(-20.78, 20.78).as_latlong(:full => true).should eql("-20°46′48.00″, 20°46′48.00″")
172
+ end
173
+
174
+ it "should print out nicely" do
175
+ Point.from_x_y(47.11, -20.2).as_latlong(:full => true).should eql("47°06′36.00″, -20°11′60.00″")
176
+ end
177
+
178
+ it "should print out nicely" do
179
+ Point.from_x_y(47.11, -20.2).as_latlong(:coord => true).should eql("47°06′36″N, 20°11′60″W")
180
+ end
181
+
182
+ it "should print out nicely" do
183
+ Point.from_x_y(-47.11, 20.2).as_latlong(:full => true,:coord => true).should eql("47°06′36.00″S, 20°11′60.00″E")
184
+ end
185
+
186
+ end
187
+
188
+ describe " > Distance" do
189
+
190
+ before(:each) do
191
+ @p1 = Point.from_x_y(1,1)
192
+ @p2 = Point.from_x_y(2,2)
193
+ end
194
+
195
+ it "and a 3th grade child should calculate euclidian distance" do
196
+ @p1.euclidian_distance(@p2).
197
+ should be_close(1.4142135623731, 0.00000001)
198
+ end
199
+
200
+ it "should calculate spherical distance" do
201
+ @p1.spherical_distance(@p2).
202
+ should be_close(157225.358003181,0.00000001)
203
+ end
204
+
205
+ it "should calculate ellipsoidal distance" do
206
+ @p1.ellipsoidal_distance(@p2).
207
+ should be_close(156876.149400742, 0.00000001)
208
+ end
209
+
210
+ end
211
+
212
+ describe "> Export Formats" do
213
+
214
+ before(:each) do
215
+ @point = Point.from_x_y( -11.2431, 32.3141 )
216
+ end
217
+
218
+ it "should print nicely" do
219
+ @point.text_representation.should eql("-11.2431 32.3141")
220
+ end
221
+
222
+ it "should printoout as binary" do
223
+ Point.from_x_y(12.4,45.3,123).as_hex_ewkb.should eql("01010000207B000000CDCCCCCCCCCC28406666666666A64640")
224
+ point = Point.from_x_y_z_m(12.4,45.3,-3.5,15,123)
225
+ point.as_hex_ewkb.should eql("01010000E07B000000CDCCCCCCCCCC28406666666666A646400000000000000CC00000000000002E40")
226
+ point.as_hex_wkb.should eql("0101000000CDCCCCCCCCCC28406666666666A64640")
227
+ end
228
+
229
+ it "should printoout as text" do
230
+ Point.from_x_y(12.4,45.3,123).as_ewkt.should eql("SRID=123;POINT(12.4 45.3)")
231
+ point = Point.from_x_y_z(12.4,45.3,-3.5,123)
232
+ point.as_ewkt.should eql("SRID=123;POINT(12.4 45.3 -3.5)")
233
+ point.as_wkt.should eql("POINT(12.4 45.3)")
234
+ point.as_ewkt(false,true).should eql("POINT(12.4 45.3 -3.5)")
235
+ point = Point.from_x_y_m(12.4,45.3,-3.5,123)
236
+ point.as_ewkt.should eql("SRID=123;POINTM(12.4 45.3 -3.5)")
237
+ point.as_ewkt(true,true,false).should eql("SRID=123;POINT(12.4 45.3)")
238
+ end
239
+
240
+ it "should have a nice bounding box" do
241
+ @point.should have(2).bounding_box
242
+ @point.bounding_box.each do |point|
243
+ point.x.should eql(@point.x)
244
+ point.y.should eql(@point.y)
245
+ end
246
+ end
247
+
248
+ it "should print as kml too" do
249
+ @point.kml_representation.should eql("<Point>\n<coordinates>-11.2431,32.3141</coordinates>\n</Point>\n")
250
+ end
251
+
252
+ it "should print as georss" do
253
+ @point.georss_simple_representation('hey').should eql("<georss:point>32.3141 -11.2431</georss:point>\n")
254
+ end
255
+
256
+ it "should print r (polar coords)" do
257
+ @point.r.should be_close(34.214154, 0.00001)
258
+ end
259
+
260
+ it "should print theta as degrees" do
261
+ @point.theta_deg.should be_close(289.184406352127, 0.0001)
262
+ end
263
+
264
+ it "should print theta as radians" do
265
+ @point.theta_rad.should be_close(5.04722003626982, 0.0001)
266
+ end
267
+
268
+ it "should output as polar" do
269
+ @point.as_polar.should be_instance_of(Array)
270
+ @point.should have(2).as_polar #.length.should eql(2)
271
+ end
272
+
273
+ end
274
+
275
+ end
@@ -0,0 +1,108 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Polygon do
4
+
5
+ describe "tu conveted" do
6
+ #no test of the binary representation for linear_rings : always with polygons and like line_string
7
+ it "should test_polygon_creation" do
8
+ linear_ring1 = LinearRing.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],256)
9
+ linear_ring2 = LinearRing.from_coordinates([[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]],256)
10
+ point1 = Point.from_x_y(12.4,-45.3,256)
11
+ point2 = Point.from_x_y(45.4,41.6,256)
12
+ point3 = Point.from_x_y(4.456,1.0698,256)
13
+ point4 = Point.from_x_y(12.4,-45.3,256)
14
+ point5 = Point.from_x_y(2.4,5.3,256)
15
+ point6 = Point.from_x_y(5.4,1.4263,256)
16
+ point7 = Point.from_x_y(14.46,1.06,256)
17
+ point8 = Point.from_x_y(2.4,5.3,256)
18
+
19
+ polygon = Polygon::new(256)
20
+ polygon.length.should be_zero
21
+
22
+ polygon << linear_ring1
23
+ polygon.length.should eql(1)
24
+ polygon[0].should == linear_ring1
25
+
26
+ #the validity of the hole is not checked : just for the sake of example
27
+ polygon << linear_ring2
28
+ polygon.length.should eql(2)
29
+ polygon[1].should == linear_ring2
30
+
31
+ polygon = Polygon.from_linear_rings([linear_ring1,linear_ring2],256)
32
+ polygon.class.should eql(Polygon)
33
+ polygon.length.should eql(2)
34
+ polygon[0].should == linear_ring1
35
+ polygon[1].should == linear_ring2
36
+
37
+ 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)
38
+ polygon.class.should eql(Polygon)
39
+ polygon.length.should eql(2)
40
+ polygon[0].should == linear_ring1
41
+ polygon[1].should == linear_ring2
42
+
43
+ polygon = Polygon.from_points([[point1,point2,point3,point4],[point5,point6,point7,point8]],256)
44
+ polygon.length.should eql(2)
45
+ polygon[0].should == linear_ring1
46
+ polygon[1].should == linear_ring2
47
+
48
+ polygon = Polygon.from_coordinates([[[12.4,-45.3,15.2],[45.4,41.6,2.4],[4.456,1.0698,5.6],[12.4,-45.3,6.1]],[[2.4,5.3,4.5],[5.4,1.4263,4.2],[14.46,1.06,123.1],[2.4,5.3,4.4]]],256,true)
49
+ polygon.class.should eql(Polygon)
50
+ polygon.length.should eql(2)
51
+
52
+ linear_ring1 = LinearRing.from_coordinates([[12.4,-45.3,15.2],[45.4,41.6,2.4],[4.456,1.0698,5.6],[12.4,-45.3,6.1]],256,true)
53
+ linear_ring2 = LinearRing.from_coordinates([[2.4,5.3,4.5],[5.4,1.4263,4.2],[14.46,1.06,123.1],[2.4,5.3,4.4]],256,true)
54
+ polygon[0].should == linear_ring1
55
+ polygon[1].should == linear_ring2
56
+ end
57
+
58
+ it "bbox" do
59
+ bbox = Polygon.from_coordinates([[[12.4,-45.3,15.2],[45.4,41.6,2.4],[4.456,1.0698,5.6],[12.4,-45.3,6.1]],[[2.4,5.3,4.5],[5.4,1.4263,4.2],[14.46,1.06,123.1],[2.4,5.3,4.4]]],256,true).bounding_box
60
+ bbox.length.should eql(2)
61
+ bbox[0].should == Point.from_x_y_z(4.456,-45.3,2.4)
62
+ bbox[1].should == Point.from_x_y_z(45.4,41.6,123.1)
63
+ end
64
+
65
+
66
+ it "test_polygon_equal" do
67
+ polygon1 = 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)
68
+ polygon2 = 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]]])
69
+ point = Point.from_x_y(12.4,-45.3,123)
70
+
71
+ polygon1.should == 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)
72
+ polygon1.should_not == polygon2
73
+ polygon1.should_not == point
74
+ end
75
+
76
+ it "test_polygon_binary" do
77
+ polygon = Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)
78
+ #taken from PostGIS answer
79
+ polygon.as_hex_ewkb.should eql("0103000020000100000200000005000000000000000000000000000000000000000000000000001040000000000000000000000000000010400000000000001040000000000000000000000000000010400000000000000000000000000000000005000000000000000000F03F000000000000F03F0000000000000840000000000000F03F00000000000008400000000000000840000000000000F03F0000000000000840000000000000F03F000000000000F03F")
80
+
81
+ polygon = 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)
82
+ #taken from PostGIS answer
83
+ polygon.as_hex_ewkb.should eql("01030000A000010000020000000500000000000000000000000000000000000000000000000000004000000000000010400000000000000000000000000000004000000000000010400000000000001040000000000000004000000000000000000000000000001040000000000000004000000000000000000000000000000000000000000000004005000000000000000000F03F000000000000F03F00000000000000400000000000000840000000000000F03F0000000000000040000000000000084000000000000008400000000000000040000000000000F03F00000000000008400000000000000040000000000000F03F000000000000F03F0000000000000040")
84
+
85
+ polygon = 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)
86
+ polygon.as_hex_ewkb.should eql("010300006000010000020000000500000000000000000000000000000000000000000000000000004000000000000010400000000000000000000000000000004000000000000010400000000000001040000000000000004000000000000000000000000000001040000000000000004000000000000000000000000000000000000000000000004005000000000000000000F03F000000000000F03F00000000000000400000000000000840000000000000F03F0000000000000040000000000000084000000000000008400000000000000040000000000000F03F00000000000008400000000000000040000000000000F03F000000000000F03F0000000000000040")
87
+
88
+ polygon = 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)
89
+ polygon.as_hex_ewkb.should eql("01030000E0000100000200000005000000000000000000000000000000000000000000000000000040CDCCCCCCCC8C46C00000000000001040000000000000000000000000000000400000000000001440000000000000104000000000000010400000000000000040AE47E17A14AE1240000000000000000000000000000010400000000000000040713D0AD7A370F53F000000000000000000000000000000000000000000000040CDCCCCCCCC8C46C005000000000000000000F03F000000000000F03F00000000000000409A999999999928400000000000000840000000000000F03F00000000000000400000000000C05E400000000000000840000000000000084000000000000000406666666666662840000000000000F03F000000000000084000000000000000400000000000002840000000000000F03F000000000000F03F00000000000000409A99999999992840")
90
+ end
91
+
92
+ it "should test_polygon_text" do
93
+ polygon = Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)
94
+ polygon.as_ewkt.should eql("SRID=256;POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1,3 1,3 3,1 3,1 1))")
95
+
96
+ polygon = 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)
97
+ polygon.as_ewkt.should eql("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))")
98
+
99
+ polygon = 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)
100
+ polygon.as_ewkt.should eql("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))")
101
+
102
+ polygon = 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
+ polygon.as_ewkt.should eql("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))")
104
+ end
105
+
106
+ end
107
+
108
+ end