georuby 1.9.9 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +1,17 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
2
 
3
- describe Polygon do
3
+ describe GeoRuby::SimpleFeatures::Polygon do
4
4
 
5
5
  describe "Instance Methods" do
6
6
 
7
- let(:poly) { Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256) }
7
+ let(:poly) { GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256) }
8
8
 
9
9
  it "should check if contains point" do
10
- poly.contains_point?(Point.from_x_y(3, 3)).should be_true
10
+ poly.contains_point?(GeoRuby::SimpleFeatures::Point.from_x_y(3, 3)).should be_true
11
11
  end
12
12
 
13
13
  it "should check if not contains point" do
14
- poly.contains_point?(Point.from_x_y(5, 5)).should be_false
14
+ poly.contains_point?(GeoRuby::SimpleFeatures::Point.from_x_y(5, 5)).should be_false
15
15
  end
16
16
 
17
17
  end
@@ -19,18 +19,18 @@ describe Polygon do
19
19
  describe "tu converted" do
20
20
  #no test of the binary representation for linear_rings : always with polygons and like line_string
21
21
  it "should test_polygon_creation" do
22
- linear_ring1 = LinearRing.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],256)
23
- linear_ring2 = LinearRing.from_coordinates([[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]],256)
24
- point1 = Point.from_x_y(12.4,-45.3,256)
25
- point2 = Point.from_x_y(45.4,41.6,256)
26
- point3 = Point.from_x_y(4.456,1.0698,256)
27
- point4 = Point.from_x_y(12.4,-45.3,256)
28
- point5 = Point.from_x_y(2.4,5.3,256)
29
- point6 = Point.from_x_y(5.4,1.4263,256)
30
- point7 = Point.from_x_y(14.46,1.06,256)
31
- point8 = Point.from_x_y(2.4,5.3,256)
32
-
33
- polygon = Polygon::new(256)
22
+ linear_ring1 = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],256)
23
+ linear_ring2 = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]],256)
24
+ point1 = GeoRuby::SimpleFeatures::Point.from_x_y(12.4,-45.3,256)
25
+ point2 = GeoRuby::SimpleFeatures::Point.from_x_y(45.4,41.6,256)
26
+ point3 = GeoRuby::SimpleFeatures::Point.from_x_y(4.456,1.0698,256)
27
+ point4 = GeoRuby::SimpleFeatures::Point.from_x_y(12.4,-45.3,256)
28
+ point5 = GeoRuby::SimpleFeatures::Point.from_x_y(2.4,5.3,256)
29
+ point6 = GeoRuby::SimpleFeatures::Point.from_x_y(5.4,1.4263,256)
30
+ point7 = GeoRuby::SimpleFeatures::Point.from_x_y(14.46,1.06,256)
31
+ point8 = GeoRuby::SimpleFeatures::Point.from_x_y(2.4,5.3,256)
32
+
33
+ polygon = GeoRuby::SimpleFeatures::Polygon::new(256)
34
34
  polygon.length.should be_zero
35
35
 
36
36
  polygon << linear_ring1
@@ -42,78 +42,78 @@ describe Polygon do
42
42
  polygon.length.should eql(2)
43
43
  polygon[1].should == linear_ring2
44
44
 
45
- polygon = Polygon.from_linear_rings([linear_ring1,linear_ring2],256)
46
- polygon.class.should eql(Polygon)
45
+ polygon = GeoRuby::SimpleFeatures::Polygon.from_linear_rings([linear_ring1,linear_ring2],256)
46
+ polygon.class.should eql(GeoRuby::SimpleFeatures::Polygon)
47
47
  polygon.length.should eql(2)
48
48
  polygon[0].should == linear_ring1
49
49
  polygon[1].should == linear_ring2
50
50
 
51
- 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)
52
- polygon.class.should eql(Polygon)
51
+ polygon = GeoRuby::SimpleFeatures::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)
52
+ polygon.class.should eql(GeoRuby::SimpleFeatures::Polygon)
53
53
  polygon.length.should eql(2)
54
54
  polygon[0].should == linear_ring1
55
55
  polygon[1].should == linear_ring2
56
56
 
57
- polygon = Polygon.from_points([[point1,point2,point3,point4],[point5,point6,point7,point8]],256)
57
+ polygon = GeoRuby::SimpleFeatures::Polygon.from_points([[point1,point2,point3,point4],[point5,point6,point7,point8]],256)
58
58
  polygon.length.should eql(2)
59
59
  polygon[0].should == linear_ring1
60
60
  polygon[1].should == linear_ring2
61
61
 
62
- 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)
63
- polygon.class.should eql(Polygon)
62
+ polygon = GeoRuby::SimpleFeatures::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)
63
+ polygon.class.should eql(GeoRuby::SimpleFeatures::Polygon)
64
64
  polygon.length.should eql(2)
65
65
 
66
- 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)
67
- 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)
66
+ linear_ring1 = GeoRuby::SimpleFeatures::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)
67
+ linear_ring2 = GeoRuby::SimpleFeatures::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)
68
68
  polygon[0].should == linear_ring1
69
69
  polygon[1].should == linear_ring2
70
70
  end
71
71
 
72
72
  it "bbox" do
73
- 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
73
+ bbox = GeoRuby::SimpleFeatures::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
74
74
  bbox.length.should eql(2)
75
- bbox[0].should == Point.from_x_y_z(4.456,-45.3,2.4)
76
- bbox[1].should == Point.from_x_y_z(45.4,41.6,123.1)
75
+ bbox[0].should == GeoRuby::SimpleFeatures::Point.from_x_y_z(4.456,-45.3,2.4)
76
+ bbox[1].should == GeoRuby::SimpleFeatures::Point.from_x_y_z(45.4,41.6,123.1)
77
77
  end
78
78
 
79
79
 
80
80
  it "test_polygon_equal" do
81
- 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)
82
- 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]]])
83
- point = Point.from_x_y(12.4,-45.3,123)
81
+ polygon1 = GeoRuby::SimpleFeatures::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)
82
+ polygon2 = GeoRuby::SimpleFeatures::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]]])
83
+ point = GeoRuby::SimpleFeatures::Point.from_x_y(12.4,-45.3,123)
84
84
 
85
- 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)
85
+ polygon1.should == GeoRuby::SimpleFeatures::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)
86
86
  polygon1.should_not == polygon2
87
87
  polygon1.should_not == point
88
88
  end
89
89
 
90
90
  it "test_polygon_binary" do
91
- 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)
91
+ polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)
92
92
  #taken from PostGIS answer
93
93
  polygon.as_hex_ewkb.should eql("0103000020000100000200000005000000000000000000000000000000000000000000000000001040000000000000000000000000000010400000000000001040000000000000000000000000000010400000000000000000000000000000000005000000000000000000F03F000000000000F03F0000000000000840000000000000F03F00000000000008400000000000000840000000000000F03F0000000000000840000000000000F03F000000000000F03F")
94
94
 
95
- 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)
95
+ polygon = GeoRuby::SimpleFeatures::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)
96
96
  #taken from PostGIS answer
97
97
  polygon.as_hex_ewkb.should eql("01030000A000010000020000000500000000000000000000000000000000000000000000000000004000000000000010400000000000000000000000000000004000000000000010400000000000001040000000000000004000000000000000000000000000001040000000000000004000000000000000000000000000000000000000000000004005000000000000000000F03F000000000000F03F00000000000000400000000000000840000000000000F03F0000000000000040000000000000084000000000000008400000000000000040000000000000F03F00000000000008400000000000000040000000000000F03F000000000000F03F0000000000000040")
98
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)
99
+ polygon = GeoRuby::SimpleFeatures::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
100
  polygon.as_hex_ewkb.should eql("010300006000010000020000000500000000000000000000000000000000000000000000000000004000000000000010400000000000000000000000000000004000000000000010400000000000001040000000000000004000000000000000000000000000001040000000000000004000000000000000000000000000000000000000000000004005000000000000000000F03F000000000000F03F00000000000000400000000000000840000000000000F03F0000000000000040000000000000084000000000000008400000000000000040000000000000F03F00000000000008400000000000000040000000000000F03F000000000000F03F0000000000000040")
101
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)
102
+ polygon = GeoRuby::SimpleFeatures::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
103
  polygon.as_hex_ewkb.should eql("01030000E0000100000200000005000000000000000000000000000000000000000000000000000040CDCCCCCCCC8C46C00000000000001040000000000000000000000000000000400000000000001440000000000000104000000000000010400000000000000040AE47E17A14AE1240000000000000000000000000000010400000000000000040713D0AD7A370F53F000000000000000000000000000000000000000000000040CDCCCCCCCC8C46C005000000000000000000F03F000000000000F03F00000000000000409A999999999928400000000000000840000000000000F03F00000000000000400000000000C05E400000000000000840000000000000084000000000000000406666666666662840000000000000F03F000000000000084000000000000000400000000000002840000000000000F03F000000000000F03F00000000000000409A99999999992840")
104
104
  end
105
105
 
106
106
  it "should test_polygon_text" do
107
- 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)
107
+ polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)
108
108
  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))")
109
109
 
110
- 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)
110
+ polygon = GeoRuby::SimpleFeatures::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)
111
111
  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))")
112
112
 
113
- 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)
113
+ polygon = GeoRuby::SimpleFeatures::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)
114
114
  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))")
115
115
 
116
- 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)
116
+ polygon = GeoRuby::SimpleFeatures::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)
117
117
  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))")
118
118
  end
119
119
 
@@ -2,26 +2,21 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  # Time to add your specs!
4
4
  # http://rspec.info/
5
- describe "GeoRuby Stuff" do
6
-
5
+ describe GeoRuby do
6
+
7
7
  it "should instantiate Geometry" do
8
8
  @geo = GeoRuby::SimpleFeatures::Geometry.new
9
- @geo.class.should eql(Geometry)
10
- end
11
-
12
- it "should instantiate from SimpleFeatures for compatibility" do
13
- @geo = GeoRuby::SimpleFeatures::Geometry.new
14
- @geo.class.should eql(Geometry)
9
+ @geo.class.should eql(::GeoRuby::SimpleFeatures::Geometry)
15
10
  end
16
11
 
17
12
  it "should instantiate Point" do
18
- @point = Point.new
19
- @point.should be_instance_of(Point)
13
+ @point = GeoRuby::SimpleFeatures::Point.new
14
+ @point.should be_instance_of(::GeoRuby::SimpleFeatures::Point)
20
15
  end
21
16
 
22
17
  it "should instantiate Line" do
23
- @line = LineString.new
24
- @line.should be_instance_of(LineString)
18
+ @line = GeoRuby::SimpleFeatures::LineString.new
19
+ @line.should be_instance_of(::GeoRuby::SimpleFeatures::LineString)
25
20
  end
26
21
 
27
22
  end
@@ -6,13 +6,8 @@ require 'rubygems'
6
6
  #require 'active_support/core_ext/object'
7
7
  #require 'json/pure'
8
8
 
9
- # begin
10
- # require 'spec'
11
- # rescue LoadError
12
9
  require 'rspec'
13
- #end
14
10
 
15
- $:.unshift(File.dirname(__FILE__) + '/../lib')
16
11
  require 'geo_ruby'
17
12
  require 'geo_ruby/shp'
18
13
  require 'geo_ruby/gpx'
@@ -20,9 +15,6 @@ require 'geo_ruby/geojson'
20
15
  require 'geo_ruby/georss'
21
16
  require 'geo_ruby/kml'
22
17
 
23
- include GeoRuby
24
- include SimpleFeatures
25
-
26
18
  module GeorubyMatchers
27
19
 
28
20
  class BeGeometric
@@ -52,7 +44,7 @@ module GeorubyMatchers
52
44
  end
53
45
  end
54
46
  end
55
- actual.should be_instance_of(Point)
47
+ actual.should be_instance_of(GeoRuby::SimpleFeatures::Point)
56
48
  end
57
49
 
58
50
  def failure_message; "expected #{@expect} but received #{@actual.inspect}"; end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: georuby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.9
4
+ version: 2.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2012-10-20 00:00:00.000000000 Z
15
+ date: 2012-10-31 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: nokogiri
@@ -78,6 +78,22 @@ dependencies:
78
78
  - - ! '>='
79
79
  - !ruby/object:Gem::Version
80
80
  version: 2.3.0
81
+ - !ruby/object:Gem::Dependency
82
+ name: rake
83
+ requirement: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
81
97
  description: GeoRuby provides geometric data types from the OGC 'Simple Features'
82
98
  specification.
83
99
  email: x@nofxx.com
@@ -106,6 +122,7 @@ files:
106
122
  - lib/geo_ruby/simple_features/polygon.rb
107
123
  - lib/geo_ruby/simple_features/geometry.rb
108
124
  - lib/geo_ruby/simple_features/ewkb_parser.rb
125
+ - lib/geo_ruby/simple_features.rb
109
126
  - lib/geo_ruby/shp4r/shp.rb
110
127
  - lib/geo_ruby/shp4r/dbf.rb
111
128
  - lib/geo_ruby/kml.rb
@@ -154,7 +171,6 @@ files:
154
171
  - spec/geo_ruby/simple_features/linear_ring_spec.rb
155
172
  - spec/geo_ruby/georss_spec.rb
156
173
  - spec/geo_ruby/shp4r/shp_spec.rb
157
- - spec/geo_ruby/georss.rb
158
174
  - README.rdoc
159
175
  - Rakefile
160
176
  homepage: http://github.com/nofxx/georuby
@@ -171,7 +187,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
187
  version: '0'
172
188
  segments:
173
189
  - 0
174
- hash: 2815257623280011863
190
+ hash: 4371088518288572487
175
191
  required_rubygems_version: !ruby/object:Gem::Requirement
176
192
  none: false
177
193
  requirements:
@@ -180,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
196
  version: '0'
181
197
  segments:
182
198
  - 0
183
- hash: 2815257623280011863
199
+ hash: 4371088518288572487
184
200
  requirements: []
185
201
  rubyforge_project:
186
202
  rubygems_version: 1.8.23
@@ -1,218 +0,0 @@
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,-45,5],[45,41,6],[4,1,8],[12.4,-45,3]],256,true)
49
- linear_ring2 = LinearRing.from_coordinates([[2,5,9],[5.4,1,-5.4],[14,1,34],[2,5,3]],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 4 41 45</georss:box>")
55
- #center
56
- e.as_georss(:dialect => :w3cgeo).gsub("\n","").should eql("<geo:lat>-2</geo:lat><geo:long>24</geo:long>")
57
- e.as_georss(:dialect => :gml).gsub("\n","").should eql("<georss:where><gml:Envelope><gml:LowerCorner>-45 4</gml:LowerCorner><gml:UpperCorner>41 45</gml:UpperCorner></gml:Envelope></georss:where>")
58
-
59
- e.as_kml.gsub("\n","").should eql("<LatLonAltBox><north>41</north><south>-45</south><east>45</east><west>4</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