georuby 2.2.1 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -8
- data/lib/geo_ruby/geojson.rb +8 -6
- data/lib/geo_ruby/simple_features/geometry.rb +11 -0
- data/lib/geo_ruby/simple_features/geometry_collection.rb +1 -9
- data/lib/geo_ruby/simple_features/line_string.rb +8 -13
- data/lib/geo_ruby/simple_features/multi_line_string.rb +2 -10
- data/lib/geo_ruby/simple_features/multi_point.rb +1 -9
- data/lib/geo_ruby/simple_features/multi_polygon.rb +0 -7
- data/lib/geo_ruby/simple_features/point.rb +11 -14
- data/lib/geo_ruby/simple_features/polygon.rb +1 -9
- data/lib/geo_ruby/version.rb +1 -1
- data/spec/geo_ruby/geojson_spec.rb +25 -25
- data/spec/geo_ruby/georss_spec.rb +63 -63
- data/spec/geo_ruby/gpx4r/gpx_spec.rb +34 -34
- data/spec/geo_ruby/kml_spec.rb +27 -27
- data/spec/geo_ruby/shp4r/shp_spec.rb +46 -46
- data/spec/geo_ruby/simple_features/circle_spec.rb +1 -1
- data/spec/geo_ruby/simple_features/envelope_spec.rb +15 -15
- data/spec/geo_ruby/simple_features/ewkb_parser_spec.rb +56 -56
- data/spec/geo_ruby/simple_features/ewkt_parser_spec.rb +68 -68
- data/spec/geo_ruby/simple_features/geometry_collection_spec.rb +18 -18
- data/spec/geo_ruby/simple_features/geometry_spec.rb +10 -10
- data/spec/geo_ruby/simple_features/line_string_spec.rb +80 -71
- data/spec/geo_ruby/simple_features/linear_ring_spec.rb +3 -3
- data/spec/geo_ruby/simple_features/multi_line_string_spec.rb +15 -15
- data/spec/geo_ruby/simple_features/multi_point_spec.rb +10 -10
- data/spec/geo_ruby/simple_features/multi_polygon_spec.rb +13 -13
- data/spec/geo_ruby/simple_features/point_spec.rb +139 -131
- data/spec/geo_ruby/simple_features/polygon_spec.rb +36 -36
- data/spec/geo_ruby_spec.rb +3 -3
- data/spec/spec_helper.rb +4 -4
- metadata +52 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f642a6426275ec6a200705f9314ac60b783ec66
|
4
|
+
data.tar.gz: ce8ae36da2895144752587caa3c0ddc9ad190a9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eaa948c90a6d82850fd9aa0f571ea947b1cbc77d049faf6db86b855c93eea37e5e8dc3a5730ebcc8d8ee399ed73f81fc92dc20615e5e42e93ca392065969a688
|
7
|
+
data.tar.gz: 013276cf42be227087ae1ef62b54b8d25bddb1d91da560ac617903176482b62f258fcf853f22657facad18e974ccd6317665b34584f3cb47f02efb541fc43730
|
data/README.md
CHANGED
@@ -132,7 +132,7 @@ GeoRuby does not allow the modification of the schema (it will probably be done
|
|
132
132
|
|
133
133
|
Here is an example of how to create a new Shapefile with 2 fields :
|
134
134
|
|
135
|
-
shpfile = ShpFile.create('hello.shp',ShpType::POINT,[
|
135
|
+
shpfile = ShpFile.create('hello.shp',ShpType::POINT,[DBF::Field.new("Hoyoyo","C",10), DBF::Field.new("Boyoul","N",10,0)])
|
136
136
|
|
137
137
|
The file is then open for reading and writing.
|
138
138
|
|
@@ -171,10 +171,11 @@ Basic GeoJSON support has been implemented per v1.0 of the {spec}[http://geojson
|
|
171
171
|
|
172
172
|
USAGE:
|
173
173
|
|
174
|
-
input - GeoRuby::SimpleFeatures::Geometry.from_geojson(geojson_string)
|
175
|
-
output - call
|
174
|
+
input - `GeoRuby::SimpleFeatures::Geometry.from_geojson(geojson_string)`
|
175
|
+
output - call `#as_geojson` or `#to_json` on any SimpleFeature Geometry instance
|
176
176
|
|
177
177
|
TODO:
|
178
|
+
|
178
179
|
* Refactor to support extremely large GeoJSON input streams / files. Currently
|
179
180
|
the entire GeoJSON representation must be loaded into memory as a String
|
180
181
|
* Improve srid/crs support on input and add support on output
|
@@ -184,29 +185,33 @@ TODO:
|
|
184
185
|
GeoJSON support implemented by {Marcus Mateus}[http://github.com/marcusmateus] and released courtesy {SimpliTex}[http://simplitex.com].
|
185
186
|
|
186
187
|
|
187
|
-
|
188
|
+
### Extra Features
|
188
189
|
|
189
190
|
- Writing of ESRI shapefiles
|
190
191
|
- Reading of ESRI shapefiles
|
191
192
|
- Tool to import spatial features in MySQL and PostGIS from a SHP file
|
192
193
|
|
193
194
|
|
194
|
-
|
195
|
+
### Acknowledgement
|
195
196
|
|
196
197
|
The SHP reading part uses the DBF library (http://rubyforge.org/projects/dbf/) by Keith Morrison (http://infused.org).
|
197
198
|
Thanks also to Pramukta Kumar and Pete Schwamb for their contributions.
|
198
199
|
|
199
200
|
|
200
|
-
|
201
|
+
## Support (Original GeoRuby gem)
|
201
202
|
|
202
203
|
Any questions, enhancement proposals, bug notifications or corrections
|
203
|
-
can be sent to
|
204
|
+
can be sent to guilhem.vellut@gmail.com.
|
204
205
|
|
205
206
|
|
206
|
-
|
207
|
+
### Coming in the next versions
|
207
208
|
|
208
209
|
- Schema modification of existing shapefiles
|
209
210
|
- More error reporting when writing shapefiles
|
210
211
|
- More tests on writing shapefiles ; tests on real-world shapefiles
|
211
212
|
- Better shp2sql import tool
|
212
213
|
- Documentation
|
214
|
+
|
215
|
+
|
216
|
+
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/nofxx/georuby/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
|
217
|
+
|
data/lib/geo_ruby/geojson.rb
CHANGED
@@ -8,7 +8,7 @@ rescue LoadError
|
|
8
8
|
end
|
9
9
|
|
10
10
|
module GeoRuby
|
11
|
-
|
11
|
+
|
12
12
|
#Raised when an error in the GeoJSON string is detected
|
13
13
|
class GeojsonFormatError < StandardError
|
14
14
|
end
|
@@ -37,7 +37,7 @@ module GeoRuby
|
|
37
37
|
output[:geometry] = geometry
|
38
38
|
output[:properties] = properties
|
39
39
|
output[:id] = id unless id.nil?
|
40
|
-
output.
|
40
|
+
output.to_json(options)
|
41
41
|
end
|
42
42
|
|
43
43
|
def to_json(options = {})
|
@@ -65,11 +65,11 @@ module GeoRuby
|
|
65
65
|
true
|
66
66
|
end
|
67
67
|
|
68
|
-
def
|
68
|
+
def as_json(options = {})
|
69
69
|
{:type => 'FeatureCollection',
|
70
70
|
:features => features}.to_json(options)
|
71
71
|
end
|
72
|
-
alias :as_geojson :
|
72
|
+
alias :as_geojson :as_json
|
73
73
|
end
|
74
74
|
|
75
75
|
|
@@ -138,5 +138,7 @@ module GeoRuby
|
|
138
138
|
end
|
139
139
|
return nil
|
140
140
|
end
|
141
|
-
|
142
|
-
end
|
141
|
+
|
142
|
+
end #GeojsonParser
|
143
|
+
|
144
|
+
end #GeoRuby
|
@@ -155,6 +155,17 @@ module GeoRuby#:nodoc:
|
|
155
155
|
kml_representation(options.merge(:id_attr => id_attr, :geom_data => geom_data, :allow_z => allow_z, :fixed_z => fixed_z))
|
156
156
|
end
|
157
157
|
|
158
|
+
# simple geojson representation
|
159
|
+
# TODO add CRS / SRID support?
|
160
|
+
def to_json(options = {})
|
161
|
+
as_json(options).to_json(options)
|
162
|
+
end
|
163
|
+
|
164
|
+
def as_json(options = {})
|
165
|
+
# Implemented by each class
|
166
|
+
end
|
167
|
+
alias :as_geojson :as_json
|
168
|
+
|
158
169
|
# Creates a geometry based on a EWKB string. The actual class returned depends of the content of the string passed as argument. Since WKB strings are a subset of EWKB, they are also valid.
|
159
170
|
def self.from_ewkb(ewkb)
|
160
171
|
factory = GeometryFactory::new
|
@@ -103,17 +103,9 @@ module GeoRuby
|
|
103
103
|
end
|
104
104
|
|
105
105
|
def as_json(options = {})
|
106
|
-
{:type => 'GeometryCollection',
|
107
|
-
:geometries => self.geometries}
|
106
|
+
{:type => 'GeometryCollection', :geometries => self.geometries}
|
108
107
|
end
|
109
108
|
|
110
|
-
# simple geojson representation
|
111
|
-
# TODO add CRS / SRID support?
|
112
|
-
def to_json(options = {})
|
113
|
-
as_json(options).to_json(options)
|
114
|
-
end
|
115
|
-
alias :as_geojson :to_json
|
116
|
-
|
117
109
|
#georss simple representation : outputs only the first geometry of the collection
|
118
110
|
def georss_simple_representation(options)#:nodoc:
|
119
111
|
self[0].georss_simple_representation(options)
|
@@ -199,21 +199,13 @@ module GeoRuby
|
|
199
199
|
end
|
200
200
|
|
201
201
|
def to_coordinates
|
202
|
-
points.map{|p| p.to_coordinates }
|
202
|
+
points.map { |p| p.to_coordinates }
|
203
203
|
end
|
204
204
|
|
205
205
|
def as_json(options = {})
|
206
|
-
{:type => 'LineString',
|
207
|
-
:coordinates => self.to_coordinates}
|
206
|
+
{:type => 'LineString', :coordinates => self.to_coordinates}
|
208
207
|
end
|
209
208
|
|
210
|
-
# simple geojson representation
|
211
|
-
# TODO add CRS / SRID support?
|
212
|
-
def to_json(options = {})
|
213
|
-
as_json(options).to_json(options)
|
214
|
-
end
|
215
|
-
alias :as_geojson :to_json
|
216
|
-
|
217
209
|
#Creates a new line string. Accept an array of points as argument
|
218
210
|
def self.from_points(points,srid=DEFAULT_SRID,with_z=false,with_m=false)
|
219
211
|
line_string = new(srid,with_z,with_m)
|
@@ -227,6 +219,9 @@ module GeoRuby
|
|
227
219
|
line_string.concat( points.map {|p| Point.from_coordinates(p,srid,with_z,with_m) } )
|
228
220
|
line_string
|
229
221
|
end
|
230
|
-
|
231
|
-
|
232
|
-
|
222
|
+
|
223
|
+
end #LineString
|
224
|
+
|
225
|
+
end #SimpleFeatures
|
226
|
+
|
227
|
+
end #GeoRuby
|
@@ -32,23 +32,15 @@ module GeoRuby
|
|
32
32
|
def to_line_string(join = true)
|
33
33
|
LineString.from_points(points)
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def to_coordinates
|
37
37
|
geometries.map{|ls| ls.to_coordinates}
|
38
38
|
end
|
39
39
|
|
40
40
|
def as_json(options = {})
|
41
|
-
{:type => 'MultiLineString',
|
42
|
-
:coordinates => self.to_coordinates}
|
41
|
+
{:type => 'MultiLineString', :coordinates => self.to_coordinates}
|
43
42
|
end
|
44
43
|
|
45
|
-
# simple geojson representation
|
46
|
-
# TODO add CRS / SRID support?
|
47
|
-
def to_json(options = {})
|
48
|
-
as_json(options).to_json(options)
|
49
|
-
end
|
50
|
-
alias :as_geojson :to_json
|
51
|
-
|
52
44
|
#Creates a new multi line string from an array of line strings
|
53
45
|
def self.from_line_strings(line_strings,srid=DEFAULT_SRID,with_z=false,with_m=false)
|
54
46
|
multi_line_string = new(srid,with_z,with_m)
|
@@ -32,17 +32,9 @@ module GeoRuby
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def as_json(options = {})
|
35
|
-
{:type => 'MultiPoint',
|
36
|
-
:coordinates => self.to_coordinates}
|
35
|
+
{:type => 'MultiPoint', :coordinates => self.to_coordinates}
|
37
36
|
end
|
38
37
|
|
39
|
-
# simple geojson representation
|
40
|
-
# TODO add CRS / SRID support?
|
41
|
-
def to_json(options = {})
|
42
|
-
as_json(options).to_json(options)
|
43
|
-
end
|
44
|
-
alias :as_geojson :to_json
|
45
|
-
|
46
38
|
#Creates a new multi point from an array of points
|
47
39
|
def self.from_points(points,srid= DEFAULT_SRID,with_z=false,with_m=false)
|
48
40
|
multi_point= new(srid,with_z,with_m)
|
@@ -40,13 +40,6 @@ module GeoRuby
|
|
40
40
|
:coordinates => self.to_coordinates}
|
41
41
|
end
|
42
42
|
|
43
|
-
# simple geojson representation
|
44
|
-
# TODO add CRS / SRID support?
|
45
|
-
def to_json(options = {})
|
46
|
-
as_json(options).to_json(options)
|
47
|
-
end
|
48
|
-
alias :as_geojson :to_json
|
49
|
-
|
50
43
|
#Creates a multi polygon from an array of polygons
|
51
44
|
def self.from_polygons(polygons,srid=DEFAULT_SRID,with_z=false,with_m=false)
|
52
45
|
multi_polygon = new(srid,with_z,with_m)
|
@@ -332,6 +332,11 @@ module GeoRuby
|
|
332
332
|
[r, t]
|
333
333
|
end
|
334
334
|
|
335
|
+
# Outputs the point in json format
|
336
|
+
def as_json(options = {})
|
337
|
+
{:type => 'Point', :coordinates => self.to_coordinates }
|
338
|
+
end
|
339
|
+
|
335
340
|
# Invert signal of all coordinates
|
336
341
|
def -@
|
337
342
|
set_x_y_z(-@x, -@y, -@z)
|
@@ -356,17 +361,6 @@ module GeoRuby
|
|
356
361
|
[x, y, z]
|
357
362
|
end
|
358
363
|
|
359
|
-
def as_json(options = {})
|
360
|
-
{ :type => 'Point', :coordinates => self.to_coordinates }
|
361
|
-
end
|
362
|
-
|
363
|
-
# Simple geojson representation
|
364
|
-
# TODO add CRS / SRID support?
|
365
|
-
def to_json(options = {})
|
366
|
-
as_json(options).to_json(options)
|
367
|
-
end
|
368
|
-
alias :as_geojson :to_json
|
369
|
-
|
370
364
|
# Creates a point from an array of coordinates
|
371
365
|
def self.from_coordinates(coords, srid = DEFAULT_SRID, with_z = false, with_m = false)
|
372
366
|
if ! (with_z || with_m)
|
@@ -441,6 +435,9 @@ module GeoRuby
|
|
441
435
|
alias :from_lon_lat_z_m :from_x_y_z_m
|
442
436
|
alias :from_rad_tet :from_r_t
|
443
437
|
end
|
444
|
-
|
445
|
-
|
446
|
-
|
438
|
+
|
439
|
+
end #Point
|
440
|
+
|
441
|
+
end #SimpleFeatures
|
442
|
+
|
443
|
+
end #GeoRuby
|
@@ -140,17 +140,9 @@ module GeoRuby
|
|
140
140
|
end
|
141
141
|
|
142
142
|
def as_json(options = {})
|
143
|
-
{:type => 'Polygon',
|
144
|
-
:coordinates => self.to_coordinates}
|
143
|
+
{:type => 'Polygon', :coordinates => self.to_coordinates }
|
145
144
|
end
|
146
145
|
|
147
|
-
# simple geojson representation
|
148
|
-
# TODO add CRS / SRID support?
|
149
|
-
def to_json(options = {})
|
150
|
-
as_json(options).to_json(options)
|
151
|
-
end
|
152
|
-
alias :as_geojson :to_json
|
153
|
-
|
154
146
|
#creates a new polygon. Accepts an array of linear strings as argument
|
155
147
|
def self.from_linear_rings(linear_rings,srid = DEFAULT_SRID,with_z=false,with_m=false)
|
156
148
|
polygon = new(srid,with_z,with_m)
|
data/lib/geo_ruby/version.rb
CHANGED
@@ -12,17 +12,17 @@ describe GeoRuby::GeojsonParser do
|
|
12
12
|
it "should create a specified GeoRuby::SimpleFeatures::Point" do
|
13
13
|
point_json = %{ { "type": "Point", "coordinates": [100.0, 0.0] } }
|
14
14
|
point = GeoRuby::SimpleFeatures::Geometry.from_geojson(point_json)
|
15
|
-
point.class.
|
15
|
+
expect(point.class).to eql(GeoRuby::SimpleFeatures::Point)
|
16
16
|
point_hash = JSON.parse(point_json)
|
17
|
-
point.to_coordinates.
|
17
|
+
expect(point.to_coordinates).to eql(point_hash['coordinates'])
|
18
18
|
end
|
19
19
|
|
20
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
22
|
line_string = GeoRuby::SimpleFeatures::Geometry.from_geojson(ls_json)
|
23
|
-
line_string.class.
|
23
|
+
expect(line_string.class).to eql(GeoRuby::SimpleFeatures::LineString)
|
24
24
|
ls_hash = JSON.parse(ls_json)
|
25
|
-
line_string.to_coordinates.
|
25
|
+
expect(line_string.to_coordinates).to eql(ls_hash['coordinates'])
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should create a specified GeoRuby::SimpleFeatures::Polygon" do
|
@@ -35,10 +35,10 @@ describe GeoRuby::GeojsonParser do
|
|
35
35
|
}
|
36
36
|
EOJ
|
37
37
|
polygon = GeoRuby::SimpleFeatures::Geometry.from_geojson(poly_json)
|
38
|
-
polygon.class.
|
39
|
-
polygon.rings.size.
|
38
|
+
expect(polygon.class).to eql(GeoRuby::SimpleFeatures::Polygon)
|
39
|
+
expect(polygon.rings.size).to eql(2)
|
40
40
|
poly_hash = JSON.parse(poly_json)
|
41
|
-
polygon.to_coordinates.
|
41
|
+
expect(polygon.to_coordinates).to eql(poly_hash['coordinates'])
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should create a specified GeoRuby::SimpleFeatures::MultiPoint" do
|
@@ -48,9 +48,9 @@ describe GeoRuby::GeojsonParser do
|
|
48
48
|
}
|
49
49
|
EOJ
|
50
50
|
multi_point = GeoRuby::SimpleFeatures::Geometry.from_geojson(mp_json)
|
51
|
-
multi_point.class.
|
51
|
+
expect(multi_point.class).to eql(GeoRuby::SimpleFeatures::MultiPoint)
|
52
52
|
mp_hash = JSON.parse(mp_json)
|
53
|
-
multi_point.to_coordinates.
|
53
|
+
expect(multi_point.to_coordinates).to eql(mp_hash['coordinates'])
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should create a specified GeoRuby::SimpleFeatures::MultiLineString" do
|
@@ -63,9 +63,9 @@ describe GeoRuby::GeojsonParser do
|
|
63
63
|
}
|
64
64
|
EOJ
|
65
65
|
multi_ls = GeoRuby::SimpleFeatures::Geometry.from_geojson(mls_json)
|
66
|
-
multi_ls.class.
|
66
|
+
expect(multi_ls.class).to eql(GeoRuby::SimpleFeatures::MultiLineString)
|
67
67
|
mls_hash = JSON.parse(mls_json)
|
68
|
-
multi_ls.to_coordinates.
|
68
|
+
expect(multi_ls.to_coordinates).to eql(mls_hash['coordinates'])
|
69
69
|
end
|
70
70
|
|
71
71
|
it "should create a specifiead GeoRuby::SimpleFeatures::MultiPolygon" do
|
@@ -79,9 +79,9 @@ describe GeoRuby::GeojsonParser do
|
|
79
79
|
}
|
80
80
|
EOJ
|
81
81
|
mpoly = GeoRuby::SimpleFeatures::Geometry.from_geojson(mpoly_json)
|
82
|
-
mpoly.class.
|
82
|
+
expect(mpoly.class).to eql(GeoRuby::SimpleFeatures::MultiPolygon)
|
83
83
|
mpoly_hash = JSON.parse(mpoly_json)
|
84
|
-
mpoly.to_coordinates.
|
84
|
+
expect(mpoly.to_coordinates).to eql(mpoly_hash['coordinates'])
|
85
85
|
end
|
86
86
|
|
87
87
|
it "should create a specified GeoRuby::SimpleFeatures::GeometryCollection" do
|
@@ -98,12 +98,12 @@ describe GeoRuby::GeojsonParser do
|
|
98
98
|
}
|
99
99
|
EOJ
|
100
100
|
gcol = GeoRuby::SimpleFeatures::Geometry.from_geojson(gcol_json)
|
101
|
-
gcol.class.
|
101
|
+
expect(gcol.class).to 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]
|
105
|
-
g.class.
|
106
|
-
g.to_coordinates.
|
105
|
+
expect(g.class).to eql(GeoRuby::SimpleFeatures.const_get(gh['type']))
|
106
|
+
expect(g.to_coordinates).to eql(gh['coordinates'])
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
@@ -121,25 +121,25 @@ describe GeoRuby::GeojsonParser do
|
|
121
121
|
}
|
122
122
|
EOJ
|
123
123
|
f = GeoRuby::SimpleFeatures::Geometry.from_geojson(feature_json)
|
124
|
-
f.class.
|
124
|
+
expect(f.class).to eql(GeoRuby::GeojsonFeature)
|
125
125
|
feature_hash = JSON.parse(feature_json)
|
126
|
-
f.id.
|
127
|
-
f.properties.
|
128
|
-
f.geometry.class.
|
129
|
-
f.geometry.to_coordinates.
|
126
|
+
expect(f.id).to eql(feature_hash['id'])
|
127
|
+
expect(f.properties).to eql(feature_hash['properties'])
|
128
|
+
expect(f.geometry.class).to eql(GeoRuby::SimpleFeatures.const_get(feature_hash['geometry']['type']))
|
129
|
+
expect(f.geometry.to_coordinates).to eql(feature_hash['geometry']['coordinates'])
|
130
130
|
end
|
131
131
|
|
132
132
|
it "should create a specified FeatureCollection" do
|
133
133
|
fcol_json = File.read(DATA_DIR + 'feature_collection.json')
|
134
134
|
fcol = GeoRuby::SimpleFeatures::Geometry.from_geojson(fcol_json)
|
135
|
-
fcol.class.
|
135
|
+
expect(fcol.class).to 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']
|
139
139
|
fg = f.geometry
|
140
|
-
f.properties.
|
141
|
-
fg.class.
|
142
|
-
fg.to_coordinates.
|
140
|
+
expect(f.properties).to eql(fcol_hash['features'][i]['properties'])
|
141
|
+
expect(fg.class).to eql(GeoRuby::SimpleFeatures.const_get(fgh['type']))
|
142
|
+
expect(fg.to_coordinates).to eql(fgh['coordinates'])
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
@@ -6,27 +6,27 @@ describe GeoRuby::GeorssParser do
|
|
6
6
|
|
7
7
|
it "should parse an rss file" do
|
8
8
|
geo = subject.parse(File.read(RSS_DATA_DIR + "/w3c.xml"))
|
9
|
-
geo.
|
9
|
+
expect(geo).to be_a GeoRuby::SimpleFeatures::Point
|
10
10
|
end
|
11
11
|
|
12
12
|
it "test_point_creation" do
|
13
13
|
point = GeoRuby::SimpleFeatures::Point.from_x_y(3,4)
|
14
14
|
|
15
|
-
point.as_georss(:dialect => :simple, :elev => 45.7, :featuretypetag => "hoyoyo").gsub("\n","").
|
16
|
-
point.as_georss(:dialect => :w3cgeo).gsub("\n","").
|
17
|
-
point.as_georss(:dialect => :gml).gsub("\n","").
|
15
|
+
expect(point.as_georss(:dialect => :simple, :elev => 45.7, :featuretypetag => "hoyoyo").gsub("\n","")).to eql("<georss:point featuretypetag=\"hoyoyo\" elev=\"45.7\">4 3</georss:point>")
|
16
|
+
expect(point.as_georss(:dialect => :w3cgeo).gsub("\n","")).to eql("<geo:lat>4</geo:lat><geo:long>3</geo:long>")
|
17
|
+
expect(point.as_georss(:dialect => :gml).gsub("\n","")).to eql("<georss:where><gml:Point><gml:pos>4 3</gml:pos></gml:Point></georss:where>")
|
18
18
|
|
19
|
-
point.as_kml(:id => "HOYOYO-42").gsub("\n","").
|
19
|
+
expect(point.as_kml(:id => "HOYOYO-42").gsub("\n","")).to eql("<Point id=\"HOYOYO-42\"><coordinates>3,4</coordinates></Point>")
|
20
20
|
end
|
21
21
|
|
22
22
|
it "test_line_string" do
|
23
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
24
|
|
25
|
-
ls.as_georss.gsub("\n","").
|
26
|
-
ls.as_georss(:dialect => :w3cgeo).gsub("\n","").
|
27
|
-
ls.as_georss(:dialect => :gml).gsub("\n","").
|
25
|
+
expect(ls.as_georss.gsub("\n","")).to eql("<georss:line>-45.3 12.4 41.6 45.4</georss:line>")
|
26
|
+
expect(ls.as_georss(:dialect => :w3cgeo).gsub("\n","")).to eql("<geo:lat>-45.3</geo:lat><geo:long>12.4</geo:long>")
|
27
|
+
expect(ls.as_georss(:dialect => :gml).gsub("\n","")).to eql("<georss:where><gml:LineString><gml:posList>-45.3 12.4 41.6 45.4</gml:posList></gml:LineString></georss:where>")
|
28
28
|
|
29
|
-
ls.as_kml(:extrude => 1, :altitude_mode => "absolute").gsub("\n","").
|
29
|
+
expect(ls.as_kml(:extrude => 1, :altitude_mode => "absolute").gsub("\n","")).to eql("<LineString><extrude>1</extrude><altitudeMode>absolute</altitudeMode><coordinates>12.4,-45.3,56 45.4,41.6,45</coordinates></LineString>")
|
30
30
|
end
|
31
31
|
|
32
32
|
it "test_polygon" do
|
@@ -34,22 +34,22 @@ describe GeoRuby::GeorssParser do
|
|
34
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
35
|
polygon = GeoRuby::SimpleFeatures::Polygon.from_linear_rings([linear_ring1,linear_ring2],256)
|
36
36
|
|
37
|
-
polygon.as_georss(:georss_ns => "hoyoyo").gsub("\n","").
|
38
|
-
polygon.as_georss(:dialect => :w3cgeo, :w3cgeo_ns => "bouyoul").gsub("\n","").
|
39
|
-
polygon.as_georss(:dialect => :gml).gsub("\n","").
|
37
|
+
expect(polygon.as_georss(:georss_ns => "hoyoyo").gsub("\n","")).to eql("<hoyoyo:polygon>-45.3 12.4 41.6 45.4 1.0698 4.456 -45.3 12.4</hoyoyo:polygon>")
|
38
|
+
expect(polygon.as_georss(:dialect => :w3cgeo, :w3cgeo_ns => "bouyoul").gsub("\n","")).to eql("<bouyoul:lat>-45.3</bouyoul:lat><bouyoul:long>12.4</bouyoul:long>")
|
39
|
+
expect(polygon.as_georss(:dialect => :gml).gsub("\n","")).to 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
40
|
|
41
|
-
polygon.as_kml.gsub("\n","").
|
41
|
+
expect(polygon.as_kml.gsub("\n","")).to 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
42
|
end
|
43
43
|
|
44
44
|
it "test_geometry_collection" do
|
45
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
46
|
|
47
47
|
#only the first geometry is output
|
48
|
-
gc.as_georss(:dialect => :simple,:floor => 4).gsub("\n","").
|
49
|
-
gc.as_georss(:dialect => :w3cgeo).gsub("\n","").
|
50
|
-
gc.as_georss(:dialect => :gml).gsub("\n","").
|
48
|
+
expect(gc.as_georss(:dialect => :simple,:floor => 4).gsub("\n","")).to eql("<georss:point floor=\"4\">45.4 4.67</georss:point>")
|
49
|
+
expect(gc.as_georss(:dialect => :w3cgeo).gsub("\n","")).to eql("<geo:lat>45.4</geo:lat><geo:long>4.67</geo:long>")
|
50
|
+
expect(gc.as_georss(:dialect => :gml).gsub("\n","")).to eql("<georss:where><gml:Point><gml:pos>45.4 4.67</gml:pos></gml:Point></georss:where>")
|
51
51
|
|
52
|
-
gc.as_kml(:id => "HOYOYO-42").gsub("\n","").
|
52
|
+
expect(gc.as_kml(:id => "HOYOYO-42").gsub("\n","")).to 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
53
|
end
|
54
54
|
|
55
55
|
it "test_envelope" do
|
@@ -59,53 +59,53 @@ describe GeoRuby::GeorssParser do
|
|
59
59
|
|
60
60
|
e = polygon.envelope
|
61
61
|
|
62
|
-
e.as_georss(:dialect => :simple).gsub("\n","").
|
62
|
+
expect(e.as_georss(:dialect => :simple).gsub("\n","")).to eql("<georss:box>-45 4 41 45</georss:box>")
|
63
63
|
#center
|
64
|
-
e.as_georss(:dialect => :w3cgeo).gsub("\n","").
|
65
|
-
e.as_georss(:dialect => :gml).gsub("\n","").
|
64
|
+
expect(e.as_georss(:dialect => :w3cgeo).gsub("\n","")).to eql("<geo:lat>-2</geo:lat><geo:long>24</geo:long>")
|
65
|
+
expect(e.as_georss(:dialect => :gml).gsub("\n","")).to eql("<georss:where><gml:Envelope><gml:LowerCorner>-45 4</gml:LowerCorner><gml:UpperCorner>41 45</gml:UpperCorner></gml:Envelope></georss:where>")
|
66
66
|
|
67
|
-
e.as_kml.gsub("\n","").
|
67
|
+
expect(e.as_kml.gsub("\n","")).to eql("<LatLonAltBox><north>41</north><south>-45</south><east>45</east><west>4</west><minAltitude>-5.4</minAltitude><maxAltitude>34</maxAltitude></LatLonAltBox>")
|
68
68
|
end
|
69
69
|
|
70
70
|
it "test_point_georss_read" do
|
71
71
|
#W3CGeo
|
72
72
|
str = " <geo:lat >12.3</geo:lat >\n\t <geo:long> 4.56</geo:long> "
|
73
73
|
geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str)
|
74
|
-
geom.class.
|
75
|
-
geom.lat.
|
76
|
-
geom.lon.
|
74
|
+
expect(geom.class).to eql(GeoRuby::SimpleFeatures::Point)
|
75
|
+
expect(geom.lat).to eql(12.3)
|
76
|
+
expect(geom.lon).to eql(4.56)
|
77
77
|
|
78
78
|
str = " <geo:Point> \n \t <geo:long> 4.56</geo:long> \n\t <geo:lat >12.3</geo:lat > </geo:Point> "
|
79
79
|
geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str)
|
80
|
-
geom.class.
|
81
|
-
geom.lat.
|
82
|
-
geom.lon.
|
80
|
+
expect(geom.class).to eql(GeoRuby::SimpleFeatures::Point)
|
81
|
+
expect(geom.lat).to eql(12.3)
|
82
|
+
expect(geom.lon).to eql(4.56)
|
83
83
|
|
84
84
|
#gml
|
85
85
|
str = " <georss:where> \t\r <gml:Point > \t <gml:pos> 4 \t 3 </gml:pos> </gml:Point> </georss:where>"
|
86
86
|
geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str)
|
87
|
-
geom.class.
|
88
|
-
geom.lat.
|
89
|
-
geom.lon.
|
87
|
+
expect(geom.class).to eql(GeoRuby::SimpleFeatures::Point)
|
88
|
+
expect(geom.lat).to eql(4.0)
|
89
|
+
expect(geom.lon).to eql(3.0)
|
90
90
|
|
91
91
|
#simple
|
92
92
|
str = "<georss:point > 4 \r\t 3 \t</georss:point >"
|
93
93
|
geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str)
|
94
|
-
geom.class.
|
95
|
-
geom.lat.
|
96
|
-
geom.lon.
|
94
|
+
expect(geom.class).to eql(GeoRuby::SimpleFeatures::Point)
|
95
|
+
expect(geom.lat).to eql(4.0)
|
96
|
+
expect(geom.lon).to eql(3.0)
|
97
97
|
|
98
98
|
#simple with tags
|
99
99
|
str = "<georss:point featuretypetag=\"hoyoyo\" elev=\"45.7\" \n floor=\"2\" relationshiptag=\"puyopuyo\" radius=\"42\" > 4 \n 3 \t</georss:point >"
|
100
100
|
geom,tags = GeoRuby::SimpleFeatures::Geometry.from_georss_with_tags(str)
|
101
|
-
geom.class.
|
102
|
-
geom.lat.
|
103
|
-
geom.lon.
|
104
|
-
tags.featuretypetag.
|
105
|
-
tags.elev.
|
106
|
-
tags.relationshiptag.
|
107
|
-
tags.floor.
|
108
|
-
tags.radius.
|
101
|
+
expect(geom.class).to eql(GeoRuby::SimpleFeatures::Point)
|
102
|
+
expect(geom.lat).to eql(4.0)
|
103
|
+
expect(geom.lon).to eql(3.0)
|
104
|
+
expect(tags.featuretypetag).to eql("hoyoyo")
|
105
|
+
expect(tags.elev).to eql(45.7)
|
106
|
+
expect(tags.relationshiptag).to eql("puyopuyo")
|
107
|
+
expect(tags.floor).to eql(2)
|
108
|
+
expect(tags.radius).to eql(42.0)
|
109
109
|
end
|
110
110
|
|
111
111
|
it "test_line_string_georss_read" do
|
@@ -113,13 +113,13 @@ describe GeoRuby::GeorssParser do
|
|
113
113
|
|
114
114
|
str = "<georss:line > -45.3 12.4 \n \r41.6\t 45.4</georss:line>"
|
115
115
|
geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str)
|
116
|
-
geom.class.
|
117
|
-
ls.
|
116
|
+
expect(geom.class).to eql(GeoRuby::SimpleFeatures::LineString)
|
117
|
+
expect(ls).to eq(geom)
|
118
118
|
|
119
119
|
str = "<georss:where><gml:LineString><gml:posList>-45.3 12.4 41.6 45.4</gml:posList></gml:LineString></georss:where>"
|
120
120
|
geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str)
|
121
|
-
geom.class.
|
122
|
-
ls.
|
121
|
+
expect(geom.class).to eql(GeoRuby::SimpleFeatures::LineString)
|
122
|
+
expect(ls).to eq(geom)
|
123
123
|
end
|
124
124
|
|
125
125
|
it "test_polygon_georss_read" do
|
@@ -128,13 +128,13 @@ describe GeoRuby::GeorssParser do
|
|
128
128
|
|
129
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
130
|
geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str)
|
131
|
-
geom.class.
|
132
|
-
polygon.
|
131
|
+
expect(geom.class).to eql(GeoRuby::SimpleFeatures::Polygon)
|
132
|
+
expect(polygon).to eq(geom)
|
133
133
|
|
134
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
135
|
geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str)
|
136
|
-
geom.class.
|
137
|
-
polygon.
|
136
|
+
expect(geom.class).to eql(GeoRuby::SimpleFeatures::Polygon)
|
137
|
+
expect(polygon).to eq(geom)
|
138
138
|
end
|
139
139
|
|
140
140
|
it "test_envelope_georss_read" do
|
@@ -142,19 +142,19 @@ describe GeoRuby::GeorssParser do
|
|
142
142
|
|
143
143
|
str = "<georss:box >-45.3 4.456 \n41.6 45.4</georss:box>"
|
144
144
|
geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str)
|
145
|
-
geom.class.
|
146
|
-
geom.
|
145
|
+
expect(geom.class).to eql(GeoRuby::SimpleFeatures::Envelope)
|
146
|
+
expect(geom).to eq(e)
|
147
147
|
|
148
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
149
|
geom = GeoRuby::SimpleFeatures::Geometry.from_georss(str)
|
150
|
-
geom.class.
|
151
|
-
geom.
|
150
|
+
expect(geom.class).to eql(GeoRuby::SimpleFeatures::Envelope)
|
151
|
+
expect(geom).to eq(e)
|
152
152
|
end
|
153
153
|
|
154
154
|
it "reads KML" do
|
155
155
|
g = GeoRuby::SimpleFeatures::Geometry.from_kml("<Point><coordinates>45,12,25</coordinates></Point>")
|
156
|
-
g.
|
157
|
-
g.
|
156
|
+
expect(g).to be_a GeoRuby::SimpleFeatures::Point
|
157
|
+
expect(g).to eq(GeoRuby::SimpleFeatures::Point.from_x_y_z('45','12','25'))
|
158
158
|
|
159
159
|
g = GeoRuby::SimpleFeatures::Geometry.from_kml("<LineString>
|
160
160
|
<extrude>1</extrude>
|
@@ -163,9 +163,9 @@ describe GeoRuby::GeorssParser do
|
|
163
163
|
-122.364383,37.824664,0 -122.364152,37.824322,0
|
164
164
|
</coordinates>
|
165
165
|
</LineString>")
|
166
|
-
g.
|
167
|
-
g.length.
|
168
|
-
g.
|
166
|
+
expect(g).to be_a GeoRuby::SimpleFeatures::LineString
|
167
|
+
expect(g.length).to eql(2)
|
168
|
+
expect(g).to eq(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
169
|
|
170
170
|
g = GeoRuby::SimpleFeatures::Geometry.from_kml("<Polygon>
|
171
171
|
<extrude>1</extrude>
|
@@ -204,23 +204,23 @@ describe GeoRuby::GeorssParser do
|
|
204
204
|
</LinearRing>
|
205
205
|
</innerBoundaryIs>
|
206
206
|
</Polygon>")
|
207
|
-
g.
|
208
|
-
g.length.
|
207
|
+
expect(g).to be_a GeoRuby::SimpleFeatures::Polygon
|
208
|
+
expect(g.length).to eql(3)
|
209
209
|
end
|
210
210
|
|
211
211
|
it "does not raise type error if point geom data not provided" do
|
212
212
|
point = GeoRuby::SimpleFeatures::Point.from_coordinates([1.6,2.8],123)
|
213
|
-
|
213
|
+
expect { point.kml_representation }.not_to raise_error
|
214
214
|
end
|
215
215
|
|
216
216
|
it "does not raise type error if polygon geom data not provided" do
|
217
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
|
-
|
218
|
+
expect { polygon.kml_representation }.not_to raise_error
|
219
219
|
end
|
220
220
|
|
221
221
|
it "does not raise type error if linestring geom data not provided" do
|
222
222
|
ls = GeoRuby::SimpleFeatures::LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)
|
223
|
-
|
223
|
+
expect { ls.kml_representation }.not_to raise_error
|
224
224
|
end
|
225
225
|
|
226
226
|
end
|