rgeo-geojson 0.3.2 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 503714421404cf164fbb61280d4b0fcdc1ed626f
4
- data.tar.gz: bdb19b2bfa801d881f67c2b32399d29750d21ad9
3
+ metadata.gz: 1a486ffc62008cbb9d03e13f7ea93aa229c588de
4
+ data.tar.gz: c3826e787a98ba17b33f81e59c859898a6807ea3
5
5
  SHA512:
6
- metadata.gz: eb72641504799a5d5272c90bd60d170295f7e34cbaab705733abb1a9b80818fadf5bade1425eb6be7e6a6ef6b45c5fad4a3774ec0046323b369d1f90dee0650c
7
- data.tar.gz: 1c073bda74e6ac4b19bba2722ff22feb82f956fd4113b24d55d204ce24b4aa699e686517787f635841e0a68f8918225b723b2065e9000571e5a490f0e4c1fdb6
6
+ metadata.gz: 4ef133754c920d853e2e2a9191e194afdf895bb361692e22d56d2dc160c5dda5b9b8470aad511458d84a35e7ef44f5541346e44ab6750ff1ac7124129f7ccc7f
7
+ data.tar.gz: e6fd873662287d0b7999190469aad4f805259906e2589f043199128bd56848c84c7f14cb082dacabe7eb5b0073288fc40eccfae2818d098aabaafe74d7d9f476
data/History.md CHANGED
@@ -1,3 +1,8 @@
1
+ ### 0.3.3 / 2015-12-23
2
+
3
+ * Rubocop style updates #20
4
+ * Do not distribute test files with gem
5
+
1
6
  ### 0.3.2 / 2015-12-10
2
7
 
3
8
  * Faster coordinates methods (tneems) #18
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
- # RGeo::GeoJSON
1
+ # rgeo-geojson
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/rgeo-geojson.svg)](http://badge.fury.io/rb/rgeo-geojson)
4
4
  [![Build Status](https://travis-ci.org/rgeo/rgeo-geojson.svg?branch=master)](https://travis-ci.org/rgeo/rgeo-geojson)
5
5
 
6
- `RGeo::GeoJSON` is an optional module for [RGeo](http://github.com/rgeo/rgeo)
7
- that provides GeoJSON encoding and decoding services.
6
+ `rgeo-geojson` is an extension to [RGeo](https://github.com/rgeo/rgeo)
7
+ that provides GeoJSON encoding and decoding.
8
8
 
9
9
  ## Summary
10
10
 
@@ -15,10 +15,9 @@ representations of geometric objects such as points, lines, and polygons,
15
15
  along with a set of geometric analysis operations. See the README for the
16
16
  "rgeo" gem for more information.
17
17
 
18
- `RGeo::GeoJSON` is an optional RGeo add-on module that provides GeoJSON encoding
19
- and decoding services. GeoJSON is an emerging standard format used by many web
20
- services that need to communicate geospatial data. See http://www.geojson.org
21
- for more information.
18
+ `RGeo::GeoJSON` is an optional RGeo module that provides GeoJSON encoding
19
+ and decoding. [GeoJSON](http://geojson.org) is a JSON format used for
20
+ geographic data structures.
22
21
 
23
22
  Example:
24
23
 
@@ -26,11 +25,11 @@ Example:
26
25
  require 'rgeo/geo_json'
27
26
 
28
27
  str1 = '{"type":"Point","coordinates":[1,2]}'
29
- geom = RGeo::GeoJSON.decode(str1, :json_parser => :json)
28
+ geom = RGeo::GeoJSON.decode(str1, json_parser: :json)
30
29
  geom.as_text # => "POINT(1.0 2.0)"
31
30
 
32
31
  str2 = '{"type":"Feature","geometry":{"type":"Point","coordinates":[2.5,4.0]},"properties":{"color":"red"}}'
33
- feature = RGeo::GeoJSON.decode(str2, :json_parser => :json)
32
+ feature = RGeo::GeoJSON.decode(str2, json_parser: :json)
34
33
  feature['color'] # => 'red'
35
34
  feature.geometry.as_text # => "POINT(2.5 4.0)"
36
35
 
@@ -43,7 +42,7 @@ hash.to_json == str2 # => true
43
42
  `RGeo::GeoJSON` has the following requirements:
44
43
 
45
44
  * Ruby 1.9.3 or later
46
- * rgeo 0.3.13 or later.
45
+ * rgeo 0.5.0 or later.
47
46
 
48
47
  Include in your bundle:
49
48
 
@@ -51,7 +50,7 @@ Include in your bundle:
51
50
  gem 'rgeo-geojson'
52
51
  ```
53
52
 
54
- Install RGeo::GeoJSON as a gem:
53
+ Install `rgeo-geojson` as a gem:
55
54
 
56
55
  ```sh
57
56
  gem install rgeo-geojson
@@ -59,17 +58,11 @@ gem install rgeo-geojson
59
58
 
60
59
  See the README for the "rgeo" gem, a required dependency, for further installation information.
61
60
 
62
- If you are using Ruby 1.8, use version `0.2.x`.
63
-
64
- ### To-do list
65
-
66
- * Add support for the "bbox" and "crs" elements.
67
-
68
61
  ### Development and support
69
62
 
70
63
  RDoc Documentation is available at http://rdoc.info/gems/rgeo-geojson
71
64
 
72
- Source code is hosted on Github at http://github.com/rgeo/rgeo-geojson
65
+ Source code is hosted on Github at https://github.com/rgeo/rgeo-geojson
73
66
 
74
67
  Contributions are welcome. Fork the project on Github.
75
68
 
@@ -77,17 +70,13 @@ Report bugs on Github issues at http://github.com/rgeo/rgeo-geojson/issues
77
70
 
78
71
  ### Acknowledgments
79
72
 
80
- RGeo is written by Daniel Azuma (http://www.daniel-azuma.com).
73
+ RGeo was created by Daniel Azuma (http://www.daniel-azuma.com).
81
74
 
82
- Development is supported by:
83
-
84
- * [Pirq](http://www.pirq.com)
85
- * [Neighborland](https://neighborland.com)
75
+ Development is supported by [Pirq](http://www.pirq.com) and
76
+ [Neighborland](https://neighborland.com).
86
77
 
87
78
  ### License
88
79
 
89
- Copyright 2014 Daniel Azuma
90
-
91
- Copyright 2014 Tee Parham
80
+ Copyright (c) Daniel Azuma, Tee Parham
92
81
 
93
82
  https://github.com/rgeo/rgeo-geojson/blob/master/LICENSE.txt
@@ -1,21 +1,15 @@
1
1
  module RGeo
2
-
3
2
  module GeoJSON
4
-
5
-
6
3
  # This object encapsulates encoding and decoding settings (principally
7
4
  # the RGeo::Feature::Factory and the RGeo::GeoJSON::EntityFactory to
8
5
  # be used) so that you can encode and decode without specifying those
9
6
  # settings every time.
10
7
 
11
8
  class Coder
12
-
13
-
14
9
  @@json_available = nil
15
10
  @@yajl_available = nil
16
11
  @@activesupport_available = nil
17
12
 
18
-
19
13
  # Create a new coder settings object. The geo factory is passed as
20
14
  # a required argument.
21
15
  #
@@ -42,7 +36,7 @@ module RGeo
42
36
  # If a parser is not specified, then the decode method will not
43
37
  # accept a String or IO object; it will require a Hash.
44
38
 
45
- def initialize(opts_={})
39
+ def initialize(opts_ = {})
46
40
  @geo_factory = opts_[:geo_factory] || ::RGeo::Cartesian.preferred_factory
47
41
  @entity_factory = opts_[:entity_factory] || EntityFactory.instance
48
42
  @json_parser = opts_[:json_parser]
@@ -50,42 +44,42 @@ module RGeo
50
44
  when :json
51
45
  if @@json_available.nil?
52
46
  begin
53
- require 'json'
47
+ require "json"
54
48
  @@json_available = true
55
49
  rescue ::LoadError
56
50
  @@json_available = false
57
51
  end
58
52
  end
59
53
  if @@json_available
60
- @json_parser = ::Proc.new{ |str_| ::JSON.parse(str_) }
54
+ @json_parser = ::Proc.new { |str_| ::JSON.parse(str_) }
61
55
  else
62
56
  raise Error::RGeoError, "JSON library is not available. You may need to install the 'json' gem."
63
57
  end
64
58
  when :yajl
65
59
  if @@yajl_available.nil?
66
60
  begin
67
- require 'yajl'
61
+ require "yajl"
68
62
  @@yajl_available = true
69
63
  rescue ::LoadError
70
64
  @@yajl_available = false
71
65
  end
72
66
  end
73
67
  if @@yajl_available
74
- @json_parser = ::Proc.new{ |str_| ::Yajl::Parser.new.parse(str_) }
68
+ @json_parser = ::Proc.new { |str_| ::Yajl::Parser.new.parse(str_) }
75
69
  else
76
70
  raise Error::RGeoError, "Yajl library is not available. You may need to install the 'yajl' gem."
77
71
  end
78
72
  when :active_support
79
73
  if @@activesupport_available.nil?
80
74
  begin
81
- require 'active_support/json'
75
+ require "active_support/json"
82
76
  @@activesupport_available = true
83
77
  rescue ::LoadError
84
78
  @@activesupport_available = false
85
79
  end
86
80
  end
87
81
  if @@activesupport_available
88
- @json_parser = ::Proc.new{ |str_| ::ActiveSupport::JSON.decode(str_) }
82
+ @json_parser = ::Proc.new { |str_| ::ActiveSupport::JSON.decode(str_) }
89
83
  else
90
84
  raise Error::RGeoError, "ActiveSupport::JSON library is not available. You may need to install the 'activesupport' gem."
91
85
  end
@@ -99,7 +93,6 @@ module RGeo
99
93
  @num_coordinates += 1 if @geo_factory.property(:has_m_coordinate)
100
94
  end
101
95
 
102
-
103
96
  # Encode the given object as GeoJSON. The object may be one of the
104
97
  # geometry objects specified in RGeo::Feature, or an appropriate
105
98
  # GeoJSON wrapper entity supported by this coder's entity factory.
@@ -115,8 +108,8 @@ module RGeo
115
108
  def encode(object_)
116
109
  if @entity_factory.is_feature_collection?(object_)
117
110
  {
118
- 'type' => 'FeatureCollection',
119
- 'features' => @entity_factory.map_feature_collection(object_){ |f_| _encode_feature(f_) },
111
+ "type" => "FeatureCollection",
112
+ "features" => @entity_factory.map_feature_collection(object_) { |f_| _encode_feature(f_) },
120
113
  }
121
114
  elsif @entity_factory.is_feature?(object_)
122
115
  _encode_feature(object_)
@@ -127,7 +120,6 @@ module RGeo
127
120
  end
128
121
  end
129
122
 
130
-
131
123
  # Decode an object from GeoJSON. The input may be a JSON hash, a
132
124
  # String, or an IO object from which to read the JSON string.
133
125
  # If an error occurs, nil is returned.
@@ -142,144 +134,133 @@ module RGeo
142
134
  unless input_.kind_of?(::Hash)
143
135
  return nil
144
136
  end
145
- case input_['type']
146
- when 'FeatureCollection'
147
- features_ = input_['features']
137
+ case input_["type"]
138
+ when "FeatureCollection"
139
+ features_ = input_["features"]
148
140
  features_ = [] unless features_.kind_of?(::Array)
149
141
  decoded_features_ = []
150
142
  features_.each do |f_|
151
- if f_['type'] == 'Feature'
143
+ if f_["type"] == "Feature"
152
144
  decoded_features_ << _decode_feature(f_)
153
145
  end
154
146
  end
155
147
  @entity_factory.feature_collection(decoded_features_)
156
- when 'Feature'
148
+ when "Feature"
157
149
  _decode_feature(input_)
158
150
  else
159
151
  _decode_geometry(input_)
160
152
  end
161
153
  end
162
154
 
163
-
164
155
  # Returns the RGeo::Feature::Factory used to generate geometry objects.
165
156
 
166
- def geo_factory
167
- @geo_factory
168
- end
169
-
157
+ attr_reader :geo_factory
170
158
 
171
159
  # Returns the RGeo::GeoJSON::EntityFactory used to generate GeoJSON
172
160
  # wrapper entities.
173
161
 
174
- def entity_factory
175
- @entity_factory
176
- end
177
-
162
+ attr_reader :entity_factory
178
163
 
179
- def _encode_feature(object_) # :nodoc:
164
+ def _encode_feature(object_) # :nodoc:
180
165
  json_ = {
181
- 'type' => 'Feature',
182
- 'geometry' => _encode_geometry(@entity_factory.get_feature_geometry(object_)),
183
- 'properties' => @entity_factory.get_feature_properties(object_).dup,
166
+ "type" => "Feature",
167
+ "geometry" => _encode_geometry(@entity_factory.get_feature_geometry(object_)),
168
+ "properties" => @entity_factory.get_feature_properties(object_).dup,
184
169
  }
185
170
  id_ = @entity_factory.get_feature_id(object_)
186
- json_['id'] = id_ if id_
171
+ json_["id"] = id_ if id_
187
172
  json_
188
173
  end
189
174
 
190
-
191
- def _encode_geometry(object_, point_encoder_=nil) # :nodoc:
175
+ def _encode_geometry(object_, point_encoder_ = nil) # :nodoc:
192
176
  unless point_encoder_
193
177
  if object_.factory.property(:has_z_coordinate)
194
178
  if object_.factory.property(:has_m_coordinate)
195
- point_encoder_ = ::Proc.new{ |p_| [p_.x, p_.y, p_.z, p_.m] }
179
+ point_encoder_ = ::Proc.new { |p_| [p_.x, p_.y, p_.z, p_.m] }
196
180
  else
197
- point_encoder_ = ::Proc.new{ |p_| [p_.x, p_.y, p_.z] }
181
+ point_encoder_ = ::Proc.new { |p_| [p_.x, p_.y, p_.z] }
198
182
  end
199
183
  else
200
184
  if object_.factory.property(:has_m_coordinate)
201
- point_encoder_ = ::Proc.new{ |p_| [p_.x, p_.y, p_.m] }
185
+ point_encoder_ = ::Proc.new { |p_| [p_.x, p_.y, p_.m] }
202
186
  else
203
- point_encoder_ = ::Proc.new{ |p_| [p_.x, p_.y] }
187
+ point_encoder_ = ::Proc.new { |p_| [p_.x, p_.y] }
204
188
  end
205
189
  end
206
190
  end
207
191
  case object_
208
192
  when ::RGeo::Feature::Point
209
193
  {
210
- 'type' => 'Point',
211
- 'coordinates' => object_.coordinates
194
+ "type" => "Point",
195
+ "coordinates" => object_.coordinates
212
196
  }
213
197
  when ::RGeo::Feature::LineString
214
198
  {
215
- 'type' => 'LineString',
216
- 'coordinates' => object_.coordinates
199
+ "type" => "LineString",
200
+ "coordinates" => object_.coordinates
217
201
  }
218
202
  when ::RGeo::Feature::Polygon
219
203
  {
220
- 'type' => 'Polygon',
221
- 'coordinates' => object_.coordinates
204
+ "type" => "Polygon",
205
+ "coordinates" => object_.coordinates
222
206
  }
223
207
  when ::RGeo::Feature::MultiPoint
224
208
  {
225
- 'type' => 'MultiPoint',
226
- 'coordinates' => object_.coordinates
209
+ "type" => "MultiPoint",
210
+ "coordinates" => object_.coordinates
227
211
  }
228
212
  when ::RGeo::Feature::MultiLineString
229
213
  {
230
- 'type' => 'MultiLineString',
231
- 'coordinates' => object_.coordinates
214
+ "type" => "MultiLineString",
215
+ "coordinates" => object_.coordinates
232
216
  }
233
217
  when ::RGeo::Feature::MultiPolygon
234
218
  {
235
- 'type' => 'MultiPolygon',
236
- 'coordinates' => object_.coordinates
219
+ "type" => "MultiPolygon",
220
+ "coordinates" => object_.coordinates
237
221
  }
238
222
  when ::RGeo::Feature::GeometryCollection
239
223
  {
240
- 'type' => 'GeometryCollection',
241
- 'geometries' => object_.map{ |geom_| _encode_geometry(geom_, point_encoder_) },
224
+ "type" => "GeometryCollection",
225
+ "geometries" => object_.map { |geom_| _encode_geometry(geom_, point_encoder_) },
242
226
  }
243
227
  else
244
228
  nil
245
229
  end
246
230
  end
247
231
 
248
-
249
- def _decode_feature(input_) # :nodoc:
250
- geometry_ = input_['geometry']
232
+ def _decode_feature(input_) # :nodoc:
233
+ geometry_ = input_["geometry"]
251
234
  if geometry_
252
235
  geometry_ = _decode_geometry(geometry_)
253
236
  return nil unless geometry_
254
237
  end
255
- @entity_factory.feature(geometry_, input_['id'], input_['properties'])
238
+ @entity_factory.feature(geometry_, input_["id"], input_["properties"])
256
239
  end
257
240
 
258
-
259
- def _decode_geometry(input_) # :nodoc:
260
- case input_['type']
261
- when 'GeometryCollection'
241
+ def _decode_geometry(input_) # :nodoc:
242
+ case input_["type"]
243
+ when "GeometryCollection"
262
244
  _decode_geometry_collection(input_)
263
- when 'Point'
264
- _decode_point_coords(input_['coordinates'])
265
- when 'LineString'
266
- _decode_line_string_coords(input_['coordinates'])
267
- when 'Polygon'
268
- _decode_polygon_coords(input_['coordinates'])
269
- when 'MultiPoint'
270
- _decode_multi_point_coords(input_['coordinates'])
271
- when 'MultiLineString'
272
- _decode_multi_line_string_coords(input_['coordinates'])
273
- when 'MultiPolygon'
274
- _decode_multi_polygon_coords(input_['coordinates'])
245
+ when "Point"
246
+ _decode_point_coords(input_["coordinates"])
247
+ when "LineString"
248
+ _decode_line_string_coords(input_["coordinates"])
249
+ when "Polygon"
250
+ _decode_polygon_coords(input_["coordinates"])
251
+ when "MultiPoint"
252
+ _decode_multi_point_coords(input_["coordinates"])
253
+ when "MultiLineString"
254
+ _decode_multi_line_string_coords(input_["coordinates"])
255
+ when "MultiPolygon"
256
+ _decode_multi_polygon_coords(input_["coordinates"])
275
257
  else
276
258
  nil
277
259
  end
278
260
  end
279
261
 
280
-
281
262
  def _decode_geometry_collection(input_) # :nodoc:
282
- geometries_ = input_['geometries']
263
+ geometries_ = input_["geometries"]
283
264
  geometries_ = [] unless geometries_.kind_of?(::Array)
284
265
  decoded_geometries_ = []
285
266
  geometries_.each do |g_|
@@ -289,14 +270,12 @@ module RGeo
289
270
  @geo_factory.collection(decoded_geometries_)
290
271
  end
291
272
 
292
-
293
273
  def _decode_point_coords(point_coords_) # :nodoc:
294
274
  return nil unless point_coords_.kind_of?(::Array)
295
- @geo_factory.point(*(point_coords_[0...@num_coordinates].map{ |c_| c_.to_f })) rescue nil
275
+ @geo_factory.point(*(point_coords_[0...@num_coordinates].map(&:to_f))) rescue nil
296
276
  end
297
277
 
298
-
299
- def _decode_line_string_coords(line_coords_) # :nodoc:
278
+ def _decode_line_string_coords(line_coords_) # :nodoc:
300
279
  return nil unless line_coords_.kind_of?(::Array)
301
280
  points_ = []
302
281
  line_coords_.each do |point_coords_|
@@ -306,8 +285,7 @@ module RGeo
306
285
  @geo_factory.line_string(points_)
307
286
  end
308
287
 
309
-
310
- def _decode_polygon_coords(poly_coords_) # :nodoc:
288
+ def _decode_polygon_coords(poly_coords_) # :nodoc:
311
289
  return nil unless poly_coords_.kind_of?(::Array)
312
290
  rings_ = []
313
291
  poly_coords_.each do |ring_coords_|
@@ -327,8 +305,7 @@ module RGeo
327
305
  end
328
306
  end
329
307
 
330
-
331
- def _decode_multi_point_coords(multi_point_coords_) # :nodoc:
308
+ def _decode_multi_point_coords(multi_point_coords_) # :nodoc:
332
309
  return nil unless multi_point_coords_.kind_of?(::Array)
333
310
  points_ = []
334
311
  multi_point_coords_.each do |point_coords_|
@@ -338,8 +315,7 @@ module RGeo
338
315
  @geo_factory.multi_point(points_)
339
316
  end
340
317
 
341
-
342
- def _decode_multi_line_string_coords(multi_line_coords_) # :nodoc:
318
+ def _decode_multi_line_string_coords(multi_line_coords_) # :nodoc:
343
319
  return nil unless multi_line_coords_.kind_of?(::Array)
344
320
  lines_ = []
345
321
  multi_line_coords_.each do |line_coords_|
@@ -349,8 +325,7 @@ module RGeo
349
325
  @geo_factory.multi_line_string(lines_)
350
326
  end
351
327
 
352
-
353
- def _decode_multi_polygon_coords(multi_polygon_coords_) # :nodoc:
328
+ def _decode_multi_polygon_coords(multi_polygon_coords_) # :nodoc:
354
329
  return nil unless multi_polygon_coords_.kind_of?(::Array)
355
330
  polygons_ = []
356
331
  multi_polygon_coords_.each do |poly_coords_|
@@ -359,11 +334,6 @@ module RGeo
359
334
  end
360
335
  @geo_factory.multi_polygon(polygons_)
361
336
  end
362
-
363
-
364
337
  end
365
-
366
-
367
338
  end
368
-
369
339
  end
@@ -1,8 +1,5 @@
1
1
  module RGeo
2
-
3
2
  module GeoJSON
4
-
5
-
6
3
  # This is a GeoJSON wrapper entity that corresponds to the GeoJSON
7
4
  # "Feature" type. It is an immutable type.
8
5
  #
@@ -14,12 +11,10 @@ module RGeo
14
11
  # engine and features.
15
12
 
16
13
  class Feature
17
-
18
-
19
14
  # Create a feature wrapping the given geometry, with the given ID
20
15
  # and properties.
21
16
 
22
- def initialize(geometry_, id_=nil, properties_={})
17
+ def initialize(geometry_, id_ = nil, properties_ = {})
23
18
  @geometry = geometry_
24
19
  @id = id_
25
20
  @properties = {}
@@ -28,8 +23,7 @@ module RGeo
28
23
  end
29
24
  end
30
25
 
31
-
32
- def inspect # :nodoc:
26
+ def inspect # :nodoc:
33
27
  "#<#{self.class}:0x#{object_id.to_s(16)} id=#{@id.inspect} geom=#{@geometry ? @geometry.as_text.inspect : 'nil'}>"
34
28
  end
35
29
 
@@ -41,7 +35,6 @@ module RGeo
41
35
  @geometry.hash + @id.hash + @properties.hash
42
36
  end
43
37
 
44
-
45
38
  # Two features are equal if their geometries, IDs, and properties
46
39
  # are all equal.
47
40
  # This method uses the eql? method to test geometry equality, which
@@ -51,7 +44,6 @@ module RGeo
51
44
  rhs_.kind_of?(Feature) && @geometry.eql?(rhs_.geometry) && @id.eql?(rhs_.feature_id) && @properties.eql?(rhs_.instance_variable_get(:@properties))
52
45
  end
53
46
 
54
-
55
47
  # Two features are equal if their geometries, IDs, and properties
56
48
  # are all equal.
57
49
  # This method uses the == operator to test geometry equality, which
@@ -61,13 +53,9 @@ module RGeo
61
53
  rhs_.kind_of?(Feature) && @geometry == rhs_.geometry && @id == rhs_.feature_id && @properties == rhs_.instance_variable_get(:@properties)
62
54
  end
63
55
 
64
-
65
56
  # Returns the geometry contained in this feature, which may be nil.
66
57
 
67
- def geometry
68
- @geometry
69
- end
70
-
58
+ attr_reader :geometry
71
59
 
72
60
  # Returns the ID for this feature, which may be nil.
73
61
 
@@ -75,14 +63,12 @@ module RGeo
75
63
  @id
76
64
  end
77
65
 
78
-
79
66
  # Returns a copy of the properties for this feature.
80
67
 
81
68
  def properties
82
69
  @properties.dup
83
70
  end
84
71
 
85
-
86
72
  # Gets the value of the given named property.
87
73
  # Returns nil if the given property is not found.
88
74
 
@@ -91,17 +77,13 @@ module RGeo
91
77
  end
92
78
  alias_method :[], :property
93
79
 
94
-
95
80
  # Gets an array of the known property keys in this feature.
96
81
 
97
82
  def keys
98
83
  @properties.keys
99
84
  end
100
-
101
-
102
85
  end
103
86
 
104
-
105
87
  # This is a GeoJSON wrapper entity that corresponds to the GeoJSON
106
88
  # "FeatureCollection" type. It is an immutable type.
107
89
  #
@@ -113,20 +95,17 @@ module RGeo
113
95
  # between the GeoJSON engine and feature collections.
114
96
 
115
97
  class FeatureCollection
116
-
117
98
  include ::Enumerable
118
99
 
119
-
120
100
  # Create a new FeatureCollection with the given features, which must
121
101
  # be provided as an Enumerable.
122
102
 
123
- def initialize(features_=[])
103
+ def initialize(features_ = [])
124
104
  @features = []
125
- features_.each{ |f_| @features << f_ if f_.kind_of?(Feature) }
105
+ features_.each { |f_| @features << f_ if f_.kind_of?(Feature) }
126
106
  end
127
107
 
128
-
129
- def inspect # :nodoc:
108
+ def inspect # :nodoc:
130
109
  "#<#{self.class}:0x#{object_id.to_s(16)}>"
131
110
  end
132
111
 
@@ -138,7 +117,6 @@ module RGeo
138
117
  @features.hash
139
118
  end
140
119
 
141
-
142
120
  # Two feature collections are equal if they contain the same
143
121
  # features in the same order.
144
122
  # This methods uses the eql? method to test geometry equality, which
@@ -148,7 +126,6 @@ module RGeo
148
126
  rhs_.kind_of?(FeatureCollection) && @features.eql?(rhs_.instance_variable_get(:@features))
149
127
  end
150
128
 
151
-
152
129
  # Two feature collections are equal if they contain the same
153
130
  # features in the same order.
154
131
  # This methods uses the == operator to test geometry equality, which
@@ -158,55 +135,45 @@ module RGeo
158
135
  rhs_.kind_of?(FeatureCollection) && @features == rhs_.instance_variable_get(:@features)
159
136
  end
160
137
 
161
-
162
138
  # Iterates or returns an iterator for the features.
163
139
 
164
140
  def each(&block_)
165
141
  @features.each(&block_)
166
142
  end
167
143
 
168
-
169
144
  # Returns the number of features contained in this collection.
170
145
 
171
146
  def size
172
147
  @features.size
173
148
  end
174
149
 
175
-
176
150
  # Access a feature by index.
177
151
 
178
152
  def [](index_)
179
153
  @features[index_]
180
154
  end
181
-
182
-
183
155
  end
184
156
 
185
-
186
157
  # This is the default entity factory. It creates objects of type
187
158
  # RGeo::GeoJSON::Feature and RGeo::GeoJSON::FeatureCollection.
188
159
  # You may create your own entity factory by duck-typing this class.
189
160
 
190
161
  class EntityFactory
191
-
192
-
193
162
  # Create and return a new feature, given geometry, ID, and
194
163
  # properties hash. Note that, per the GeoJSON spec, geometry and/or
195
164
  # properties may be nil.
196
165
 
197
- def feature(geometry_, id_=nil, properties_=nil)
166
+ def feature(geometry_, id_ = nil, properties_ = nil)
198
167
  Feature.new(geometry_, id_, properties_ || {})
199
168
  end
200
169
 
201
-
202
170
  # Create and return a new feature collection, given an enumerable
203
171
  # of feature objects.
204
172
 
205
- def feature_collection(features_=[])
173
+ def feature_collection(features_ = [])
206
174
  FeatureCollection.new(features_)
207
175
  end
208
176
 
209
-
210
177
  # Returns true if the given object is a feature created by this
211
178
  # entity factory.
212
179
 
@@ -214,7 +181,6 @@ module RGeo
214
181
  object_.kind_of?(Feature)
215
182
  end
216
183
 
217
-
218
184
  # Returns true if the given object is a feature collection created
219
185
  # by this entity factory.
220
186
 
@@ -222,7 +188,6 @@ module RGeo
222
188
  object_.kind_of?(FeatureCollection)
223
189
  end
224
190
 
225
-
226
191
  # Run Enumerable#map on the features contained in the given feature
227
192
  # collection.
228
193
 
@@ -230,21 +195,18 @@ module RGeo
230
195
  object_.map(&block_)
231
196
  end
232
197
 
233
-
234
198
  # Returns the geometry associated with the given feature.
235
199
 
236
200
  def get_feature_geometry(object_)
237
201
  object_.geometry
238
202
  end
239
203
 
240
-
241
204
  # Returns the ID of the given feature, or nil for no ID.
242
205
 
243
206
  def get_feature_id(object_)
244
207
  object_.feature_id
245
208
  end
246
209
 
247
-
248
210
  # Returns the properties of the given feature as a hash. Editing
249
211
  # this hash does not change the state of the feature.
250
212
 
@@ -252,17 +214,11 @@ module RGeo
252
214
  object_.properties
253
215
  end
254
216
 
255
-
256
217
  # Return the singleton instance of EntityFactory.
257
218
 
258
219
  def self.instance
259
- @instance ||= self.new
220
+ @instance ||= new
260
221
  end
261
-
262
-
263
222
  end
264
-
265
-
266
223
  end
267
-
268
224
  end
@@ -1,10 +1,6 @@
1
1
  module RGeo
2
-
3
2
  module GeoJSON
4
-
5
3
  class << self
6
-
7
-
8
4
  # High-level convenience routine for encoding an object as GeoJSON.
9
5
  # Pass the object, which may one of the geometry objects specified
10
6
  # in RGeo::Feature, or an appropriate GeoJSON wrapper entity such
@@ -16,11 +12,10 @@ module RGeo
16
12
  # encode supports objects of type RGeo::GeoJSON::Feature and
17
13
  # RGeo::GeoJSON::FeatureCollection.
18
14
 
19
- def encode(object_, opts_={})
15
+ def encode(object_, opts_ = {})
20
16
  Coder.new(opts_).encode(object_)
21
17
  end
22
18
 
23
-
24
19
  # High-level convenience routine for decoding an object from GeoJSON.
25
20
  # The input may be a JSON hash, a String, or an IO object from which
26
21
  # to read the JSON string.
@@ -48,11 +43,10 @@ module RGeo
48
43
  # If a parser is not specified, then the decode method will not
49
44
  # accept a String or IO object; it will require a Hash.
50
45
 
51
- def decode(input_, opts_={})
46
+ def decode(input_, opts_ = {})
52
47
  Coder.new(opts_).decode(input_)
53
48
  end
54
49
 
55
-
56
50
  # Creates and returns a coder object of type RGeo::GeoJSON::Coder
57
51
  # that encapsulates encoding and decoding settings (principally the
58
52
  # RGeo::Feature::Factory and the RGeo::GeoJSON::EntityFactory to be
@@ -81,13 +75,9 @@ module RGeo
81
75
  # If a parser is not specified, then the decode method will not
82
76
  # accept a String or IO object; it will require a Hash.
83
77
 
84
- def coder(opts_={})
78
+ def coder(opts_ = {})
85
79
  Coder.new(opts_)
86
80
  end
87
-
88
-
89
81
  end
90
-
91
82
  end
92
-
93
83
  end
@@ -1,5 +1,5 @@
1
1
  module RGeo
2
2
  module GeoJSON
3
- VERSION = '0.3.2'.freeze
3
+ VERSION = "0.3.3".freeze
4
4
  end
5
5
  end
data/lib/rgeo/geo_json.rb CHANGED
@@ -1,5 +1,4 @@
1
- require 'rgeo'
2
-
1
+ require "rgeo"
3
2
 
4
3
  # RGeo is a spatial data library for Ruby, provided by the "rgeo" gem.
5
4
  #
@@ -7,20 +6,15 @@ require 'rgeo'
7
6
  # encoding and decoding.
8
7
 
9
8
  module RGeo
10
-
11
-
12
9
  # This is a namespace for a set of tools that provide GeoJSON encoding.
13
10
  # See http://geojson.org/ for more information about this specification.
14
11
 
15
12
  module GeoJSON
16
13
  end
17
-
18
-
19
14
  end
20
15
 
21
-
22
16
  # Implementation files
23
- require 'rgeo/geo_json/version'
24
- require 'rgeo/geo_json/entities'
25
- require 'rgeo/geo_json/coder'
26
- require 'rgeo/geo_json/interface'
17
+ require "rgeo/geo_json/version"
18
+ require "rgeo/geo_json/entities"
19
+ require "rgeo/geo_json/coder"
20
+ require "rgeo/geo_json/interface"
data/lib/rgeo-geojson.rb CHANGED
@@ -1 +1 @@
1
- require 'rgeo/geo_json'
1
+ require "rgeo/geo_json"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgeo-geojson
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Azuma
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-12-10 00:00:00.000000000 Z
12
+ date: 2015-12-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rgeo
@@ -67,10 +67,8 @@ dependencies:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
69
  version: '10.4'
70
- description: RGeo is a geospatial data library for Ruby. RGeo::GeoJSON is an optional
71
- RGeo module providing GeoJSON encoding and decoding services. This module can be
72
- used to communicate with location-based web services that understand the GeoJSON
73
- format.
70
+ description: Convert RGeo data to and from GeoJSON. rgeo-geojson is an extension to
71
+ the rgeo gem that converts RGeo data types to and from GeoJSON.
74
72
  email:
75
73
  - dazuma@gmail.com
76
74
  - parhameter@gmail.com
@@ -87,8 +85,7 @@ files:
87
85
  - lib/rgeo/geo_json/entities.rb
88
86
  - lib/rgeo/geo_json/interface.rb
89
87
  - lib/rgeo/geo_json/version.rb
90
- - test/basic_test.rb
91
- homepage: http://github.com/rgeo/rgeo-geojson
88
+ homepage: https://github.com/rgeo/rgeo-geojson
92
89
  licenses:
93
90
  - BSD
94
91
  metadata: {}
@@ -108,9 +105,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
105
  version: '0'
109
106
  requirements: []
110
107
  rubyforge_project:
111
- rubygems_version: 2.5.0
108
+ rubygems_version: 2.5.1
112
109
  signing_key:
113
110
  specification_version: 4
114
- summary: An RGeo module providing GeoJSON encoding and decoding.
115
- test_files:
116
- - test/basic_test.rb
111
+ summary: Convert RGeo data to and from GeoJSON.
112
+ test_files: []
113
+ has_rdoc:
data/test/basic_test.rb DELETED
@@ -1,273 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'rgeo/geo_json'
3
-
4
- module RGeo
5
- module GeoJSON
6
- module Tests # :nodoc:
7
-
8
- class BasicTest < Minitest::Test # :nodoc:
9
-
10
-
11
- def setup
12
- @geo_factory = ::RGeo::Cartesian.simple_factory(:srid => 4326)
13
- @geo_factory_z = ::RGeo::Cartesian.simple_factory(:srid => 4326, :has_z_coordinate => true)
14
- @geo_factory_m = ::RGeo::Cartesian.simple_factory(:srid => 4326, :has_m_coordinate => true)
15
- @geo_factory_zm = ::RGeo::Cartesian.simple_factory(:srid => 4326, :has_z_coordinate => true, :has_m_coordinate => true)
16
- @entity_factory = ::RGeo::GeoJSON::EntityFactory.instance
17
- end
18
-
19
-
20
- def test_has_version
21
- refute_nil(::RGeo::GeoJSON::VERSION)
22
- end
23
-
24
-
25
- def test_nil
26
- assert_nil(::RGeo::GeoJSON.encode(nil))
27
- assert_nil(::RGeo::GeoJSON.decode(nil, :geo_factory => @geo_factory))
28
- end
29
-
30
-
31
- def test_point
32
- object_ = @geo_factory.point(10, 20)
33
- json_ = {
34
- 'type' => 'Point',
35
- 'coordinates' => [10.0, 20.0],
36
- }
37
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
38
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
39
- end
40
-
41
-
42
- def test_point_z
43
- object_ = @geo_factory_z.point(10, 20, -1)
44
- json_ = {
45
- 'type' => 'Point',
46
- 'coordinates' => [10.0, 20.0, -1.0],
47
- }
48
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
49
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory_z).eql?(object_))
50
- end
51
-
52
-
53
- def test_point_m
54
- object_ = @geo_factory_m.point(10, 20, -1)
55
- json_ = {
56
- 'type' => 'Point',
57
- 'coordinates' => [10.0, 20.0, -1.0],
58
- }
59
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
60
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory_m).eql?(object_))
61
- end
62
-
63
-
64
- def test_point_zm
65
- object_ = @geo_factory_zm.point(10, 20, -1, -2)
66
- json_ = {
67
- 'type' => 'Point',
68
- 'coordinates' => [10.0, 20.0, -1.0, -2.0],
69
- }
70
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
71
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory_zm).eql?(object_))
72
- end
73
-
74
-
75
- def test_line_string
76
- object_ = @geo_factory.line_string([@geo_factory.point(10, 20), @geo_factory.point(12, 22), @geo_factory.point(-3, 24)])
77
- json_ = {
78
- 'type' => 'LineString',
79
- 'coordinates' => [[10.0, 20.0], [12.0, 22.0], [-3.0, 24.0]],
80
- }
81
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
82
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
83
- end
84
-
85
-
86
- def test_polygon
87
- object_ = @geo_factory.polygon(@geo_factory.linear_ring([@geo_factory.point(10, 20), @geo_factory.point(12, 22), @geo_factory.point(-3, 24), @geo_factory.point(10, 20)]))
88
- json_ = {
89
- 'type' => 'Polygon',
90
- 'coordinates' => [[[10.0, 20.0], [12.0, 22.0], [-3.0, 24.0], [10.0, 20.0]]],
91
- }
92
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
93
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
94
- end
95
-
96
-
97
- def test_polygon_complex
98
- object_ = @geo_factory.polygon(@geo_factory.linear_ring([@geo_factory.point(0, 0), @geo_factory.point(10, 0), @geo_factory.point(10, 10), @geo_factory.point(0, 10), @geo_factory.point(0, 0)]), [@geo_factory.linear_ring([@geo_factory.point(4, 4), @geo_factory.point(6, 5), @geo_factory.point(4, 6), @geo_factory.point(4, 4)])])
99
- json_ = {
100
- 'type' => 'Polygon',
101
- 'coordinates' => [[[0.0, 0.0], [10.0, 0.0], [10.0, 10.0], [0.0, 10.0], [0.0, 0.0]], [[4.0, 4.0], [6.0, 5.0], [4.0, 6.0], [4.0, 4.0]]],
102
- }
103
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
104
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
105
- end
106
-
107
-
108
- def test_multi_point
109
- object_ = @geo_factory.multi_point([@geo_factory.point(10, 20), @geo_factory.point(12, 22), @geo_factory.point(-3, 24)])
110
- json_ = {
111
- 'type' => 'MultiPoint',
112
- 'coordinates' => [[10.0, 20.0], [12.0, 22.0], [-3.0, 24.0]],
113
- }
114
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
115
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
116
- end
117
-
118
-
119
- def test_multi_line_string
120
- object_ = @geo_factory.multi_line_string([@geo_factory.line_string([@geo_factory.point(10, 20), @geo_factory.point(12, 22), @geo_factory.point(-3, 24)]), @geo_factory.line_string([@geo_factory.point(1, 2), @geo_factory.point(3, 4)])])
121
- json_ = {
122
- 'type' => 'MultiLineString',
123
- 'coordinates' => [[[10.0, 20.0], [12.0, 22.0], [-3.0, 24.0]], [[1.0, 2.0], [3.0, 4.0]]],
124
- }
125
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
126
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
127
- end
128
-
129
-
130
- def test_multi_polygon
131
- object_ = @geo_factory.multi_polygon([@geo_factory.polygon(@geo_factory.linear_ring([@geo_factory.point(0, 0), @geo_factory.point(10, 0), @geo_factory.point(10, 10), @geo_factory.point(0, 10), @geo_factory.point(0, 0)]), [@geo_factory.linear_ring([@geo_factory.point(4, 4), @geo_factory.point(6, 5), @geo_factory.point(4, 6), @geo_factory.point(4, 4)])]), @geo_factory.polygon(@geo_factory.linear_ring([@geo_factory.point(-10,-10), @geo_factory.point(-15, -10), @geo_factory.point(-10, -15), @geo_factory.point(-10, -10)]))])
132
- json_ = {
133
- 'type' => 'MultiPolygon',
134
- 'coordinates' => [[[[0.0, 0.0], [10.0, 0.0], [10.0, 10.0], [0.0, 10.0], [0.0, 0.0]], [[4.0, 4.0], [6.0, 5.0], [4.0, 6.0], [4.0, 4.0]]], [[[-10.0, -10.0], [-15.0, -10.0], [-10.0, -15.0], [-10.0, -10.0]]]]
135
- }
136
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
137
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
138
- end
139
-
140
-
141
- def test_geometry_collection
142
- object_ = @geo_factory.collection([@geo_factory.point(10, 20), @geo_factory.collection([@geo_factory.point(12, 22), @geo_factory.point(-3, 24)])])
143
- json_ = {
144
- 'type' => 'GeometryCollection',
145
- 'geometries' => [
146
- {
147
- 'type' => 'Point',
148
- 'coordinates' => [10.0, 20.0],
149
- },
150
- {
151
- 'type' => 'GeometryCollection',
152
- 'geometries' => [
153
- {
154
- 'type' => 'Point',
155
- 'coordinates' => [12.0, 22.0],
156
- },
157
- {
158
- 'type' => 'Point',
159
- 'coordinates' => [-3.0, 24.0],
160
- },
161
- ],
162
- },
163
- ],
164
- }
165
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
166
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
167
- end
168
-
169
-
170
- def test_feature
171
- object_ = @entity_factory.feature(@geo_factory.point(10, 20))
172
- json_ = {
173
- 'type' => 'Feature',
174
- 'geometry' => {
175
- 'type' => 'Point',
176
- 'coordinates' => [10.0, 20.0],
177
- },
178
- 'properties' => {},
179
- }
180
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
181
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
182
- end
183
-
184
-
185
- def test_feature_nulls
186
- json_ = {
187
- 'type' => 'Feature',
188
- 'geometry' => nil,
189
- 'properties' => nil,
190
- }
191
- obj_ = ::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory)
192
- refute_nil(obj_)
193
- assert_nil(obj_.geometry)
194
- assert_equal({}, obj_.properties)
195
- end
196
-
197
-
198
- def test_feature_complex
199
- object_ = @entity_factory.feature(@geo_factory.point(10, 20), 2, {'prop1' => 'foo', 'prop2' => 'bar'})
200
- json_ = {
201
- 'type' => 'Feature',
202
- 'geometry' => {
203
- 'type' => 'Point',
204
- 'coordinates' => [10.0, 20.0],
205
- },
206
- 'id' => 2,
207
- 'properties' => {'prop1' => 'foo', 'prop2' => 'bar'},
208
- }
209
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
210
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
211
- end
212
-
213
-
214
- def test_feature_with_symbol_prop_keys
215
- object_ = @entity_factory.feature(@geo_factory.point(10, 20), 2, {:prop1 => 'foo', 'prop2' => 'bar'})
216
- json_ = {
217
- 'type' => 'Feature',
218
- 'geometry' => {
219
- 'type' => 'Point',
220
- 'coordinates' => [10.0, 20.0],
221
- },
222
- 'id' => 2,
223
- 'properties' => {'prop1' => 'foo', 'prop2' => 'bar'},
224
- }
225
- assert_equal('foo', object_.property('prop1'))
226
- assert_equal('bar', object_.property(:prop2))
227
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
228
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
229
- end
230
-
231
-
232
- def test_feature_collection
233
- object_ = @entity_factory.feature_collection([@entity_factory.feature(@geo_factory.point(10, 20)), @entity_factory.feature(@geo_factory.point(11, 22)), @entity_factory.feature(@geo_factory.point(10, 20), 8)])
234
- json_ = {
235
- 'type' => 'FeatureCollection',
236
- 'features' => [
237
- {
238
- 'type' => 'Feature',
239
- 'geometry' => {
240
- 'type' => 'Point',
241
- 'coordinates' => [10.0, 20.0],
242
- },
243
- 'properties' => {},
244
- },
245
- {
246
- 'type' => 'Feature',
247
- 'geometry' => {
248
- 'type' => 'Point',
249
- 'coordinates' => [11.0, 22.0],
250
- },
251
- 'properties' => {},
252
- },
253
- {
254
- 'type' => 'Feature',
255
- 'geometry' => {
256
- 'type' => 'Point',
257
- 'coordinates' => [10.0, 20.0],
258
- },
259
- 'id' => 8,
260
- 'properties' => {},
261
- },
262
- ]
263
- }
264
- assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
265
- assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
266
- end
267
-
268
-
269
- end
270
-
271
- end
272
- end
273
- end