georuby 1.9.9 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,21 +1,7 @@
1
1
  # $:.unshift(File.dirname(__FILE__)) #unless
2
2
  # $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
- require 'geo_ruby/simple_features/helper'
5
- require 'geo_ruby/simple_features/ewkt_parser'
6
- require 'geo_ruby/simple_features/ewkb_parser'
7
- require 'geo_ruby/simple_features/geometry'
8
- require 'geo_ruby/simple_features/point'
9
- require 'geo_ruby/simple_features/line_string'
10
- require 'geo_ruby/simple_features/linear_ring'
11
- require 'geo_ruby/simple_features/circle'
12
- require 'geo_ruby/simple_features/polygon'
13
- require 'geo_ruby/simple_features/multi_point'
14
- require 'geo_ruby/simple_features/multi_line_string'
15
- require 'geo_ruby/simple_features/multi_polygon'
16
- require 'geo_ruby/simple_features/geometry_collection'
17
- require 'geo_ruby/simple_features/envelope'
18
- require 'geo_ruby/simple_features/geometry_factory'
4
+ require 'geo_ruby/simple_features'
19
5
 
20
6
  # Require if you need
21
7
  # require 'geo_ruby/shp4r/shp'
@@ -8,6 +8,7 @@ rescue LoadError
8
8
  end
9
9
 
10
10
  module GeoRuby
11
+
11
12
  #Raised when an error in the GeoJSON string is detected
12
13
  class GeojsonFormatError < StandardError
13
14
  end
@@ -73,6 +74,7 @@ module GeoRuby
73
74
 
74
75
 
75
76
  class GeojsonParser
77
+ include GeoRuby::SimpleFeatures
76
78
  attr_reader :geometry
77
79
 
78
80
  def parse(geojson, srid=DEFAULT_SRID)
@@ -21,6 +21,7 @@ module GeoRuby
21
21
  #Parses GeoRSS strings
22
22
  #You can also use directly the static method Geometry.from_georss
23
23
  class GeorssParser
24
+ include GeoRuby::SimpleFeatures
24
25
  attr_reader :georss_tags, :geometry
25
26
 
26
27
  #Parses the georss geometry passed as argument and notifies the factory of events
@@ -61,7 +61,7 @@ module GeoRuby
61
61
  def accumulate_end(e); @buffer << "</#{e[0]}>"; end
62
62
 
63
63
  def parse_coordinates(buffer)
64
- if(buffer =~ /<coordinates>(.+)<\/coordinates>/)
64
+ if(buffer =~ /<coordinates>(.+)<\/coordinates>/m)
65
65
  $1.gsub(/\n/, " ").strip.split(/\s+/).each do |coord|
66
66
  x,y,z = coord.split(',')
67
67
  if(x.nil? || y.nil?)
@@ -0,0 +1,25 @@
1
+ module GeoRuby
2
+ module SimpleFeatures
3
+
4
+ %w[
5
+ geometry
6
+ circle
7
+ envelope
8
+ ewkb_parser
9
+ ewkt_parser
10
+ geometry_collection
11
+ geometry_factory
12
+ helper
13
+ line_string
14
+ linear_ring
15
+ multi_line_string
16
+ multi_point
17
+ multi_polygon
18
+ point
19
+ polygon
20
+ ].each do |rel_file|
21
+ require File.join(File.dirname(__FILE__), 'simple_features', rel_file)
22
+ end
23
+
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module GeoRuby
2
- VERSION = '1.9.9'
2
+ VERSION = '2.0.0'
3
3
  end
@@ -7,25 +7,25 @@ DATA_DIR = File.dirname(__FILE__) + '/../data/geojson/'
7
7
  #
8
8
  # TODO Refactor comon test approaches into methods
9
9
  # TODO Add use of contexts?
10
- describe GeojsonParser do
10
+ describe GeoRuby::GeojsonParser do
11
11
 
12
- it "should create a specified Point" do
12
+ it "should create a specified GeoRuby::SimpleFeatures::Point" do
13
13
  point_json = %{ { "type": "Point", "coordinates": [100.0, 0.0] } }
14
- point = Geometry.from_geojson(point_json)
15
- point.class.should eql(Point)
14
+ point = GeoRuby::SimpleFeatures::Geometry.from_geojson(point_json)
15
+ point.class.should eql(GeoRuby::SimpleFeatures::Point)
16
16
  point_hash = JSON.parse(point_json)
17
17
  point.to_coordinates.should eql(point_hash['coordinates'])
18
18
  end
19
19
 
20
- it "should create a specified LineString" do
20
+ it "should create a specified GeoRuby::SimpleFeatures::LineString" do
21
21
  ls_json = %{ { "type": "LineString", "coordinates": [ [100.0, 0.0], [101.0, 1.0] ]} }
22
- line_string = Geometry.from_geojson(ls_json)
23
- line_string.class.should eql(LineString)
22
+ line_string = GeoRuby::SimpleFeatures::Geometry.from_geojson(ls_json)
23
+ line_string.class.should eql(GeoRuby::SimpleFeatures::LineString)
24
24
  ls_hash = JSON.parse(ls_json)
25
25
  line_string.to_coordinates.should eql(ls_hash['coordinates'])
26
26
  end
27
27
 
28
- it "should create a specified Polygon" do
28
+ it "should create a specified GeoRuby::SimpleFeatures::Polygon" do
29
29
  poly_json = <<-EOJ
30
30
  { "type": "Polygon",
31
31
  "coordinates": [
@@ -34,26 +34,26 @@ describe GeojsonParser do
34
34
  ]
35
35
  }
36
36
  EOJ
37
- polygon = Geometry.from_geojson(poly_json)
38
- polygon.class.should eql(Polygon)
37
+ polygon = GeoRuby::SimpleFeatures::Geometry.from_geojson(poly_json)
38
+ polygon.class.should eql(GeoRuby::SimpleFeatures::Polygon)
39
39
  polygon.rings.size.should eql(2)
40
40
  poly_hash = JSON.parse(poly_json)
41
41
  polygon.to_coordinates.should eql(poly_hash['coordinates'])
42
42
  end
43
43
 
44
- it "should create a specified MultiPoint" do
44
+ it "should create a specified GeoRuby::SimpleFeatures::MultiPoint" do
45
45
  mp_json = <<-EOJ
46
46
  { "type": "MultiPoint",
47
47
  "coordinates": [ [100.0, 0.0], [101.0, 1.0] ]
48
48
  }
49
49
  EOJ
50
- multi_point = Geometry.from_geojson(mp_json)
51
- multi_point.class.should eql(MultiPoint)
50
+ multi_point = GeoRuby::SimpleFeatures::Geometry.from_geojson(mp_json)
51
+ multi_point.class.should eql(GeoRuby::SimpleFeatures::MultiPoint)
52
52
  mp_hash = JSON.parse(mp_json)
53
53
  multi_point.to_coordinates.should eql(mp_hash['coordinates'])
54
54
  end
55
55
 
56
- it "should create a specified MultiLineString" do
56
+ it "should create a specified GeoRuby::SimpleFeatures::MultiLineString" do
57
57
  mls_json = <<-EOJ
58
58
  { "type": "MultiLineString",
59
59
  "coordinates": [
@@ -62,13 +62,13 @@ describe GeojsonParser do
62
62
  ]
63
63
  }
64
64
  EOJ
65
- multi_ls = Geometry.from_geojson(mls_json)
66
- multi_ls.class.should eql(MultiLineString)
65
+ multi_ls = GeoRuby::SimpleFeatures::Geometry.from_geojson(mls_json)
66
+ multi_ls.class.should eql(GeoRuby::SimpleFeatures::MultiLineString)
67
67
  mls_hash = JSON.parse(mls_json)
68
68
  multi_ls.to_coordinates.should eql(mls_hash['coordinates'])
69
69
  end
70
70
 
71
- it "should create a specifiead MultiPolygon" do
71
+ it "should create a specifiead GeoRuby::SimpleFeatures::MultiPolygon" do
72
72
  mpoly_json = <<-EOJ
73
73
  { "type": "MultiPolygon",
74
74
  "coordinates": [
@@ -78,13 +78,13 @@ describe GeojsonParser do
78
78
  ]
79
79
  }
80
80
  EOJ
81
- mpoly = Geometry.from_geojson(mpoly_json)
82
- mpoly.class.should eql(MultiPolygon)
81
+ mpoly = GeoRuby::SimpleFeatures::Geometry.from_geojson(mpoly_json)
82
+ mpoly.class.should eql(GeoRuby::SimpleFeatures::MultiPolygon)
83
83
  mpoly_hash = JSON.parse(mpoly_json)
84
84
  mpoly.to_coordinates.should eql(mpoly_hash['coordinates'])
85
85
  end
86
86
 
87
- it "should create a specified GeometryCollection" do
87
+ it "should create a specified GeoRuby::SimpleFeatures::GeometryCollection" do
88
88
  gcol_json = <<-EOJ
89
89
  { "type": "GeometryCollection",
90
90
  "geometries": [
@@ -97,8 +97,8 @@ describe GeojsonParser do
97
97
  ]
98
98
  }
99
99
  EOJ
100
- gcol = Geometry.from_geojson(gcol_json)
101
- gcol.class.should eql(GeometryCollection)
100
+ gcol = GeoRuby::SimpleFeatures::Geometry.from_geojson(gcol_json)
101
+ gcol.class.should eql(GeoRuby::SimpleFeatures::GeometryCollection)
102
102
  gcol_hash = JSON.parse(gcol_json)
103
103
  gcol.geometries.each_with_index do |g,i|
104
104
  gh = gcol_hash['geometries'][i]
@@ -120,8 +120,8 @@ describe GeojsonParser do
120
120
  }
121
121
  }
122
122
  EOJ
123
- f = Geometry.from_geojson(feature_json)
124
- f.class.should eql(GeojsonFeature)
123
+ f = GeoRuby::SimpleFeatures::Geometry.from_geojson(feature_json)
124
+ f.class.should eql(GeoRuby::GeojsonFeature)
125
125
  feature_hash = JSON.parse(feature_json)
126
126
  f.id.should eql(feature_hash['id'])
127
127
  f.properties.should eql(feature_hash['properties'])
@@ -131,8 +131,8 @@ describe GeojsonParser do
131
131
 
132
132
  it "should create a specified FeatureCollection" do
133
133
  fcol_json = File.read(DATA_DIR + 'feature_collection.json')
134
- fcol = Geometry.from_geojson(fcol_json)
135
- fcol.class.should eql(GeojsonFeatureCollection)
134
+ fcol = GeoRuby::SimpleFeatures::Geometry.from_geojson(fcol_json)
135
+ fcol.class.should eql(GeoRuby::GeojsonFeatureCollection)
136
136
  fcol_hash = JSON.parse(fcol_json)
137
137
  fcol.features.each_with_index do |f,i|
138
138
  fgh = fcol_hash['features'][i]['geometry']
@@ -2,13 +2,225 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  RSS_DATA_DIR = File.dirname(__FILE__) + '/../data/georss/'
4
4
 
5
- describe GeorssParser do
5
+ describe GeoRuby::GeorssParser do
6
6
 
7
7
  it "should parse an rss file" do
8
- geo = GeorssParser.new.parse(File.read(RSS_DATA_DIR + "/w3c.xml"))
9
- geo.should be_a Point
8
+ geo = subject.parse(File.read(RSS_DATA_DIR + "/w3c.xml"))
9
+ geo.should be_a GeoRuby::SimpleFeatures::Point
10
10
  end
11
11
 
12
+ it "test_point_creation" do
13
+ point = GeoRuby::SimpleFeatures::Point.from_x_y(3,4)
12
14
 
15
+ 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>")
16
+ point.as_georss(:dialect => :w3cgeo).gsub("\n","").should eql("<geo:lat>4</geo:lat><geo:long>3</geo:long>")
17
+ point.as_georss(:dialect => :gml).gsub("\n","").should eql("<georss:where><gml:Point><gml:pos>4 3</gml:pos></gml:Point></georss:where>")
18
+
19
+ point.as_kml(:id => "HOYOYO-42").gsub("\n","").should eql("<Point id=\"HOYOYO-42\"><coordinates>3,4</coordinates></Point>")
20
+ end
21
+
22
+ it "test_line_string" do
23
+ ls = GeoRuby::SimpleFeatures::LineString.from_points([GeoRuby::SimpleFeatures::Point.from_lon_lat_z(12.4,-45.3,56),GeoRuby::SimpleFeatures::Point.from_lon_lat_z(45.4,41.6,45)],123,true)
24
+
25
+ ls.as_georss.gsub("\n","").should eql("<georss:line>-45.3 12.4 41.6 45.4</georss:line>")
26
+ ls.as_georss(:dialect => :w3cgeo).gsub("\n","").should eql("<geo:lat>-45.3</geo:lat><geo:long>12.4</geo:long>")
27
+ 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>")
28
+
29
+ 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>")
30
+ end
31
+
32
+ it "test_polygon" do
33
+ linear_ring1 = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],256)
34
+ linear_ring2 = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]],256)
35
+ polygon = GeoRuby::SimpleFeatures::Polygon.from_linear_rings([linear_ring1,linear_ring2],256)
36
+
37
+ 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>")
38
+ polygon.as_georss(:dialect => :w3cgeo, :w3cgeo_ns => "bouyoul").gsub("\n","").should eql("<bouyoul:lat>-45.3</bouyoul:lat><bouyoul:long>12.4</bouyoul:long>")
39
+ 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>")
40
+
41
+ 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>")
42
+ end
43
+
44
+ it "test_geometry_collection" do
45
+ gc = GeoRuby::SimpleFeatures::GeometryCollection.from_geometries([GeoRuby::SimpleFeatures::Point.from_x_y(4.67,45.4,256),GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256)
46
+
47
+ #only the first geometry is output
48
+ gc.as_georss(:dialect => :simple,:floor => 4).gsub("\n","").should eql("<georss:point floor=\"4\">45.4 4.67</georss:point>")
49
+ gc.as_georss(:dialect => :w3cgeo).gsub("\n","").should eql("<geo:lat>45.4</geo:lat><geo:long>4.67</geo:long>")
50
+ 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>")
51
+
52
+ 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>")
53
+ end
54
+
55
+ it "test_envelope" do
56
+ linear_ring1 = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[12,-45,5],[45,41,6],[4,1,8],[12.4,-45,3]],256,true)
57
+ linear_ring2 = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[2,5,9],[5.4,1,-5.4],[14,1,34],[2,5,3]],256,true)
58
+ polygon = GeoRuby::SimpleFeatures::Polygon.from_linear_rings([linear_ring1,linear_ring2],256,true)
59
+
60
+ e = polygon.envelope
61
+
62
+ e.as_georss(:dialect => :simple).gsub("\n","").should eql("<georss:box>-45 4 41 45</georss:box>")
63
+ #center
64
+ e.as_georss(:dialect => :w3cgeo).gsub("\n","").should eql("<geo:lat>-2</geo:lat><geo:long>24</geo:long>")
65
+ 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>")
66
+
67
+ 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>")
68
+ end
69
+
70
+ it "test_point_georss_read" do
71
+ #W3CGeo
72
+ str = " <geo:lat >12.3</geo:lat >\n\t <geo:long> 4.56</geo:long> "
73
+ geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str)
74
+ geom.class.should eql(GeoRuby::SimpleFeatures::Point)
75
+ geom.lat.should eql(12.3)
76
+ geom.lon.should eql(4.56)
77
+
78
+ str = " <geo:Point> \n \t <geo:long> 4.56</geo:long> \n\t <geo:lat >12.3</geo:lat > </geo:Point> "
79
+ geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str)
80
+ geom.class.should eql(GeoRuby::SimpleFeatures::Point)
81
+ geom.lat.should eql(12.3)
82
+ geom.lon.should eql(4.56)
83
+
84
+ #gml
85
+ str = " <georss:where> \t\r <gml:Point > \t <gml:pos> 4 \t 3 </gml:pos> </gml:Point> </georss:where>"
86
+ geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str)
87
+ geom.class.should eql(GeoRuby::SimpleFeatures::Point)
88
+ geom.lat.should eql(4.0)
89
+ geom.lon.should eql(3.0)
90
+
91
+ #simple
92
+ str = "<georss:point > 4 \r\t 3 \t</georss:point >"
93
+ geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str)
94
+ geom.class.should eql(GeoRuby::SimpleFeatures::Point)
95
+ geom.lat.should eql(4.0)
96
+ geom.lon.should eql(3.0)
97
+
98
+ #simple with tags
99
+ str = "<georss:point featuretypetag=\"hoyoyo\" elev=\"45.7\" \n floor=\"2\" relationshiptag=\"puyopuyo\" radius=\"42\" > 4 \n 3 \t</georss:point >"
100
+ geom,tags = GeoRuby::SimpleFeatures::Geometry.from_georss_with_tags(str)
101
+ geom.class.should eql(GeoRuby::SimpleFeatures::Point)
102
+ geom.lat.should eql(4.0)
103
+ geom.lon.should eql(3.0)
104
+ tags.featuretypetag.should eql("hoyoyo")
105
+ tags.elev.should eql(45.7)
106
+ tags.relationshiptag.should eql("puyopuyo")
107
+ tags.floor.should eql(2)
108
+ tags.radius.should eql(42.0)
109
+ end
110
+
111
+ it "test_line_string_georss_read" do
112
+ ls = GeoRuby::SimpleFeatures::LineString.from_points([GeoRuby::SimpleFeatures::Point.from_lon_lat(12.4,-45.3),GeoRuby::SimpleFeatures::Point.from_lon_lat(45.4,41.6)])
113
+
114
+ str = "<georss:line > -45.3 12.4 \n \r41.6\t 45.4</georss:line>"
115
+ geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str)
116
+ geom.class.should eql(GeoRuby::SimpleFeatures::LineString)
117
+ ls.should == geom
118
+
119
+ str = "<georss:where><gml:LineString><gml:posList>-45.3 12.4 41.6 45.4</gml:posList></gml:LineString></georss:where>"
120
+ geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str)
121
+ geom.class.should eql(GeoRuby::SimpleFeatures::LineString)
122
+ ls.should == geom
123
+ end
124
+
125
+ it "test_polygon_georss_read" do
126
+ linear_ring = GeoRuby::SimpleFeatures::LinearRing.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]])
127
+ polygon = GeoRuby::SimpleFeatures::Polygon.from_linear_rings([linear_ring])
128
+
129
+ 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>"
130
+ geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str)
131
+ geom.class.should eql(GeoRuby::SimpleFeatures::Polygon)
132
+ polygon.should == geom
133
+
134
+ 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>"
135
+ geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str)
136
+ geom.class.should eql(GeoRuby::SimpleFeatures::Polygon)
137
+ polygon.should == geom
138
+ end
139
+
140
+ it "test_envelope_georss_read" do
141
+ e = GeoRuby::SimpleFeatures::Envelope.from_coordinates([[4.456,-45.3],[45.4,41.6]])
142
+
143
+ str = "<georss:box >-45.3 4.456 \n41.6 45.4</georss:box>"
144
+ geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str)
145
+ geom.class.should eql(GeoRuby::SimpleFeatures::Envelope)
146
+ geom.should == e
147
+
148
+ 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>"
149
+ geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str)
150
+ geom.class.should eql(GeoRuby::SimpleFeatures::Envelope)
151
+ geom.should == e
152
+ end
153
+
154
+ it "test_kml_read" do
155
+ g = GeoRuby::SimpleFeatures::Geometry.from_kml("<Point><coordinates>45,12,25</coordinates></Point>")
156
+ g.should be_a GeoRuby::SimpleFeatures::Point
157
+ g.should == GeoRuby::SimpleFeatures::Point.from_x_y_z('45','12','25')
158
+
159
+ g = GeoRuby::SimpleFeatures::Geometry.from_kml("<LineString>
160
+ <extrude>1</extrude>
161
+ <tessellate>1</tessellate>
162
+ <coordinates>
163
+ -122.364383,37.824664,0 -122.364152,37.824322,0
164
+ </coordinates>
165
+ </LineString>")
166
+ g.should be_a GeoRuby::SimpleFeatures::LineString
167
+ g.length.should eql(2)
168
+ g.should == GeoRuby::SimpleFeatures::LineString.from_points([GeoRuby::SimpleFeatures::Point.from_x_y_z('-122.364383','37.824664','0'),GeoRuby::SimpleFeatures::Point.from_x_y_z('-122.364152','37.824322','0')],4326,true)
169
+
170
+ g = GeoRuby::SimpleFeatures::Geometry.from_kml("<Polygon>
171
+ <extrude>1</extrude>
172
+ <altitudeMode>relativeToGround</altitudeMode>
173
+ <outerBoundaryIs>
174
+ <LinearRing>
175
+ <coordinates>
176
+ -122.366278,37.818844,30
177
+ -122.365248,37.819267,30
178
+ -122.365640,37.819861,30
179
+ -122.366669,37.819429,30
180
+ -122.366278,37.818844,30
181
+ </coordinates>
182
+ </LinearRing>
183
+ </outerBoundaryIs>
184
+ <innerBoundaryIs>
185
+ <LinearRing>
186
+ <coordinates>
187
+ -122.366212,37.818977,30
188
+ -122.365424,37.819294,30
189
+ -122.365704,37.819731,30
190
+ -122.366488,37.819402,30
191
+ -122.366212,37.818977,30
192
+ </coordinates>
193
+ </LinearRing>
194
+ </innerBoundaryIs>
195
+ <innerBoundaryIs>
196
+ <LinearRing>
197
+ <coordinates>
198
+ -122.366212,37.818977,30
199
+ -122.365424,37.819294,30
200
+ -122.365704,37.819731,30
201
+ -122.366488,37.819402,30
202
+ -122.366212,37.818977,30
203
+ </coordinates>
204
+ </LinearRing>
205
+ </innerBoundaryIs>
206
+ </Polygon>")
207
+ g.should be_a GeoRuby::SimpleFeatures::Polygon
208
+ g.length.should eql(3)
209
+ end
210
+
211
+ it "test_to_kml_for_point_does_not_raise_type_error_if_geom_data_not_provided" do
212
+ point = GeoRuby::SimpleFeatures::Point.from_coordinates([1.6,2.8],123)
213
+ lambda { point.kml_representation }.should_not raise_error(TypeError)
214
+ end
215
+
216
+ it "test_to_kml_for_polygon_does_not_raise_type_error_if_geom_data_not_provided" do
217
+ 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)
218
+ lambda { polygon.kml_representation }.should_not raise_error(TypeError)
219
+ end
220
+
221
+ it "test_to_kml_for_line_string_does_not_raise_type_error_if_geom_data_not_provided" do
222
+ ls = GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)
223
+ lambda { ls.kml_representation }.should_not raise_error(TypeError)
224
+ end
13
225
 
14
226
  end