georuby 1.9.3
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.
- data/Gemfile +8 -0
- data/Gemfile.lock +29 -0
- data/History.txt +4 -0
- data/LICENSE +21 -0
- data/README.rdoc +184 -0
- data/Rakefile +48 -0
- data/VERSION +1 -0
- data/georuby.gemspec +128 -0
- data/lib/geo_ruby.rb +23 -0
- data/lib/geo_ruby/geojson.rb +129 -0
- data/lib/geo_ruby/georss.rb +133 -0
- data/lib/geo_ruby/gpx.rb +1 -0
- data/lib/geo_ruby/gpx4r/gpx.rb +118 -0
- data/lib/geo_ruby/shp.rb +1 -0
- data/lib/geo_ruby/shp4r/dbf.rb +42 -0
- data/lib/geo_ruby/shp4r/shp.rb +718 -0
- data/lib/geo_ruby/simple_features/envelope.rb +167 -0
- data/lib/geo_ruby/simple_features/ewkb_parser.rb +218 -0
- data/lib/geo_ruby/simple_features/ewkt_parser.rb +336 -0
- data/lib/geo_ruby/simple_features/geometry.rb +236 -0
- data/lib/geo_ruby/simple_features/geometry_collection.rb +144 -0
- data/lib/geo_ruby/simple_features/geometry_factory.rb +81 -0
- data/lib/geo_ruby/simple_features/helper.rb +18 -0
- data/lib/geo_ruby/simple_features/line_string.rb +228 -0
- data/lib/geo_ruby/simple_features/linear_ring.rb +34 -0
- data/lib/geo_ruby/simple_features/multi_line_string.rb +63 -0
- data/lib/geo_ruby/simple_features/multi_point.rb +58 -0
- data/lib/geo_ruby/simple_features/multi_polygon.rb +64 -0
- data/lib/geo_ruby/simple_features/point.rb +381 -0
- data/lib/geo_ruby/simple_features/polygon.rb +175 -0
- data/nofxx-georuby.gemspec +149 -0
- data/spec/data/geojson/feature_collection.json +34 -0
- data/spec/data/georss/atom.xml +21 -0
- data/spec/data/georss/gml.xml +40 -0
- data/spec/data/georss/w3c.xml +22 -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/geojson_spec.rb +147 -0
- data/spec/geo_ruby/georss.rb +218 -0
- data/spec/geo_ruby/georss_spec.rb +14 -0
- data/spec/geo_ruby/gpx4r/gpx_spec.rb +106 -0
- data/spec/geo_ruby/shp4r/shp_spec.rb +239 -0
- data/spec/geo_ruby/simple_features/envelope_spec.rb +47 -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/line_string_spec.rb +259 -0
- data/spec/geo_ruby/simple_features/linear_ring_spec.rb +24 -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 +122 -0
- data/spec/geo_ruby_spec.rb +27 -0
- data/spec/spec_helper.rb +73 -0
- metadata +228 -0
Binary file
|
Binary file
|
Binary file
|
data/spec/data/point.dbf
ADDED
Binary file
|
data/spec/data/point.shp
ADDED
Binary file
|
data/spec/data/point.shx
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,147 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
DATA_DIR = File.dirname(__FILE__) + '/../data/geojson/'
|
4
|
+
|
5
|
+
# All geojson test examples are from the GeoJSON spec unless otherwise
|
6
|
+
# specified
|
7
|
+
#
|
8
|
+
# TODO Refactor comon test approaches into methods
|
9
|
+
# TODO Add use of contexts?
|
10
|
+
describe GeojsonParser do
|
11
|
+
|
12
|
+
it "should create a specified Point" do
|
13
|
+
point_json = %{ { "type": "Point", "coordinates": [100.0, 0.0] } }
|
14
|
+
point = Geometry.from_geojson(point_json)
|
15
|
+
point.class.should eql(Point)
|
16
|
+
point_hash = JSON.parse(point_json)
|
17
|
+
point.to_coordinates.should eql(point_hash['coordinates'])
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should create a specified LineString" do
|
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)
|
24
|
+
ls_hash = JSON.parse(ls_json)
|
25
|
+
line_string.to_coordinates.should eql(ls_hash['coordinates'])
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should create a specified Polygon" do
|
29
|
+
poly_json = <<-EOJ
|
30
|
+
{ "type": "Polygon",
|
31
|
+
"coordinates": [
|
32
|
+
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ],
|
33
|
+
[ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ]
|
34
|
+
]
|
35
|
+
}
|
36
|
+
EOJ
|
37
|
+
polygon = Geometry.from_geojson(poly_json)
|
38
|
+
polygon.class.should eql(Polygon)
|
39
|
+
polygon.rings.size.should eql(2)
|
40
|
+
poly_hash = JSON.parse(poly_json)
|
41
|
+
polygon.to_coordinates.should eql(poly_hash['coordinates'])
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should create a specified MultiPoint" do
|
45
|
+
mp_json = <<-EOJ
|
46
|
+
{ "type": "MultiPoint",
|
47
|
+
"coordinates": [ [100.0, 0.0], [101.0, 1.0] ]
|
48
|
+
}
|
49
|
+
EOJ
|
50
|
+
multi_point = Geometry.from_geojson(mp_json)
|
51
|
+
multi_point.class.should eql(MultiPoint)
|
52
|
+
mp_hash = JSON.parse(mp_json)
|
53
|
+
multi_point.to_coordinates.should eql(mp_hash['coordinates'])
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should create a specified MultiLineString" do
|
57
|
+
mls_json = <<-EOJ
|
58
|
+
{ "type": "MultiLineString",
|
59
|
+
"coordinates": [
|
60
|
+
[ [100.0, 0.0], [101.0, 1.0] ],
|
61
|
+
[ [102.0, 2.0], [103.0, 3.0] ]
|
62
|
+
]
|
63
|
+
}
|
64
|
+
EOJ
|
65
|
+
multi_ls = Geometry.from_geojson(mls_json)
|
66
|
+
multi_ls.class.should eql(MultiLineString)
|
67
|
+
mls_hash = JSON.parse(mls_json)
|
68
|
+
multi_ls.to_coordinates.should eql(mls_hash['coordinates'])
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should create a specifiead MultiPolygon" do
|
72
|
+
mpoly_json = <<-EOJ
|
73
|
+
{ "type": "MultiPolygon",
|
74
|
+
"coordinates": [
|
75
|
+
[[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],
|
76
|
+
[[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],
|
77
|
+
[[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]]
|
78
|
+
]
|
79
|
+
}
|
80
|
+
EOJ
|
81
|
+
mpoly = Geometry.from_geojson(mpoly_json)
|
82
|
+
mpoly.class.should eql(MultiPolygon)
|
83
|
+
mpoly_hash = JSON.parse(mpoly_json)
|
84
|
+
mpoly.to_coordinates.should eql(mpoly_hash['coordinates'])
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should create a specified GeometryCollection" do
|
88
|
+
gcol_json = <<-EOJ
|
89
|
+
{ "type": "GeometryCollection",
|
90
|
+
"geometries": [
|
91
|
+
{ "type": "Point",
|
92
|
+
"coordinates": [100.0, 0.0]
|
93
|
+
},
|
94
|
+
{ "type": "LineString",
|
95
|
+
"coordinates": [ [101.0, 0.0], [102.0, 1.0] ]
|
96
|
+
}
|
97
|
+
]
|
98
|
+
}
|
99
|
+
EOJ
|
100
|
+
gcol = Geometry.from_geojson(gcol_json)
|
101
|
+
gcol.class.should eql(GeometryCollection)
|
102
|
+
gcol_hash = JSON.parse(gcol_json)
|
103
|
+
gcol.geometries.each_with_index do |g,i|
|
104
|
+
gh = gcol_hash['geometries'][i]
|
105
|
+
g.class.should eql(GeoRuby::SimpleFeatures.const_get(gh['type']))
|
106
|
+
g.to_coordinates.should eql(gh['coordinates'])
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# Feature GeoJSON test example from wikipedia entry
|
111
|
+
it "should create a specified Feature" do
|
112
|
+
feature_json = <<-EOJ
|
113
|
+
{
|
114
|
+
"type":"Feature",
|
115
|
+
"id":"OpenLayers.Feature.Vector_314",
|
116
|
+
"properties":{"prop0": "value0"},
|
117
|
+
"geometry":{
|
118
|
+
"type":"Point",
|
119
|
+
"coordinates":[97.03125, 39.7265625]
|
120
|
+
}
|
121
|
+
}
|
122
|
+
EOJ
|
123
|
+
f = Geometry.from_geojson(feature_json)
|
124
|
+
f.class.should eql(GeojsonFeature)
|
125
|
+
feature_hash = JSON.parse(feature_json)
|
126
|
+
f.id.should eql(feature_hash['id'])
|
127
|
+
f.properties.should eql(feature_hash['properties'])
|
128
|
+
f.geometry.class.should eql(GeoRuby::SimpleFeatures.const_get(feature_hash['geometry']['type']))
|
129
|
+
f.geometry.to_coordinates.should eql(feature_hash['geometry']['coordinates'])
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should create a specified FeatureCollection" do
|
133
|
+
fcol_json = File.read(DATA_DIR + 'feature_collection.json')
|
134
|
+
fcol = Geometry.from_geojson(fcol_json)
|
135
|
+
fcol.class.should eql(GeojsonFeatureCollection)
|
136
|
+
fcol_hash = JSON.parse(fcol_json)
|
137
|
+
fcol.features.each_with_index do |f,i|
|
138
|
+
fgh = fcol_hash['features'][i]['geometry']
|
139
|
+
fg = f.geometry
|
140
|
+
f.properties.should eql(fcol_hash['features'][i]['properties'])
|
141
|
+
fg.class.should eql(GeoRuby::SimpleFeatures.const_get(fgh['type']))
|
142
|
+
fg.to_coordinates.should eql(fgh['coordinates'])
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
@@ -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,-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
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
RSS_DATA_DIR = File.dirname(__FILE__) + '/../data/georss/'
|
4
|
+
|
5
|
+
describe GeorssParser do
|
6
|
+
|
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
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
include GeoRuby::Gpx4r
|
4
|
+
include GeoRuby::SimpleFeatures
|
5
|
+
|
6
|
+
describe Gpx4r do
|
7
|
+
|
8
|
+
it "should add gpx extension and raise if doesn't exists" do
|
9
|
+
lambda do
|
10
|
+
File.should_receive(:exists?).with("short.gpx").and_return(false)
|
11
|
+
GpxFile.open('short').should be_true
|
12
|
+
end.should raise_error MalformedGpxException
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "Waypoints" do
|
16
|
+
|
17
|
+
before(:all) do
|
18
|
+
@gpxfile = GpxFile.open(File.dirname(__FILE__) + '/../../data/gpx/short.gpx', :with_z => true, :with_m => true)
|
19
|
+
@gpxfile2 = GpxFile.open(File.dirname(__FILE__) + '/../../data/gpx/fells_loop', :with_z => true, :with_m => true)
|
20
|
+
@gpxfile3 = GpxFile.open(File.dirname(__FILE__) + '/../../data/gpx/tracktreks.gpx', :with_z => true)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should open and parse" do
|
24
|
+
@gpxfile.record_count.should eql(2724)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should open and parse no trkpt one" do
|
28
|
+
@gpxfile2.record_count.should eql(86)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should open and parse 3" do
|
32
|
+
@gpxfile3.record_count.should eql(225)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should read X and Y" do
|
36
|
+
@gpxfile[0].x.should be_within(0.0001).of(9.093942)
|
37
|
+
@gpxfile[0].y.should be_within(0.0001).of(48.731813)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should read Z and M" do
|
41
|
+
@gpxfile[0].z.should eql(468.0)
|
42
|
+
@gpxfile[0].m.should eql("2008-09-07T17:36:57Z")
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should read X and Y 2" do
|
46
|
+
@gpxfile2[0].x.should be_within(0.0001).of(-71.119277)
|
47
|
+
@gpxfile2[0].y.should be_within(0.0001).of(42.438878)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should read Z and M 2" do
|
51
|
+
@gpxfile2[0].z.should eql(44.586548)
|
52
|
+
@gpxfile2[0].m.should eql("2001-11-28T21:05:28Z")
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should read X and Y 3" do
|
56
|
+
@gpxfile3[0].x.should be_within(0.0001).of(-149.8358011)
|
57
|
+
@gpxfile3[0].y.should be_within(0.0001).of(-17.5326508)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should read Z and M 3" do
|
61
|
+
@gpxfile3[0].z.should eql(88.5787354)
|
62
|
+
@gpxfile3[0].m.should eql(0.0)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should return it as a linestring" do
|
66
|
+
@gpxfile.as_line_string.should be_instance_of LineString
|
67
|
+
@gpxfile.as_polyline.should be_instance_of LineString
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should return it as a linestring 3" do
|
71
|
+
@gpxfile3.as_line_string.should be_instance_of LineString
|
72
|
+
@gpxfile3.as_polyline.should be_instance_of LineString
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should return a envelope" do
|
76
|
+
@gpxfile.envelope.should be_instance_of Envelope
|
77
|
+
@gpxfile.envelope.lower_corner.x.should be_within(0.001).of(9.08128)
|
78
|
+
@gpxfile.envelope.lower_corner.y.should be_within(0.001).of(48.7169)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should return a envelope 3" do
|
82
|
+
@gpxfile3.envelope.should be_instance_of Envelope
|
83
|
+
@gpxfile3.envelope.lower_corner.x.should be_within(0.001).of(-149.8422613)
|
84
|
+
@gpxfile3.envelope.lower_corner.y.should be_within(0.001).of(-17.547636)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should return it as a polygon" do
|
88
|
+
[@gpxfile, @gpxfile2, @gpxfile3].each do |g|
|
89
|
+
g.as_polygon.should be_instance_of Polygon
|
90
|
+
g.as_polygon[0].should be_instance_of LinearRing
|
91
|
+
g.as_polygon[0].should be_closed
|
92
|
+
g.as_polygon[1].should be_nil
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should close the polygon" do
|
97
|
+
se = Point.from_x_y(-44, -23)
|
98
|
+
sw = Point.from_x_y(-42, -22)
|
99
|
+
nw = Point.from_x_y(-42, -25)
|
100
|
+
ne = Point.from_x_y(-44, -21)
|
101
|
+
@gpxfile.instance_variable_set(:@points, [se,sw,nw,ne])
|
102
|
+
@gpxfile.as_polygon.should == Polygon.from_points([[se,sw,nw,ne,se]])
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|