rgeo-geojson 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ === 0.2.2 / 2012-01-09
2
+
3
+ * Fixed Feature#property(:symbol). (Reported by Andy Allan.)
4
+ * Added an "rgeo-geojson.rb" wrapper so bundler's auto-require will work without modification. (Reported by Mauricio Pasquier Juan.)
5
+
1
6
  === 0.2.1 / 2011-04-11
2
7
 
3
8
  * The gem version is now accessible via an api.
@@ -38,7 +38,7 @@ Example:
38
38
  RGeo::GeoJSON has the following requirements:
39
39
 
40
40
  * Ruby 1.8.7 or later. Ruby 1.9.2 or later preferred.
41
- * \RGeo 0.2.8 or later.
41
+ * rgeo 0.3.3 or later.
42
42
  * If you are using Ruby 1.8, you should install the "json" gem to support
43
43
  parsing JSON strings. Ruby 1.9 has JSON support in its standard library
44
44
  and does not require the gem.
@@ -75,7 +75,7 @@ Development of \RGeo is sponsored by GeoPage, Inc. (http://www.geopage.com).
75
75
 
76
76
  === License
77
77
 
78
- Copyright 2010-2011 Daniel Azuma
78
+ Copyright 2010-2012 Daniel Azuma
79
79
 
80
80
  All rights reserved.
81
81
 
data/Version CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -0,0 +1,36 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # GeoJSON implementation for RGeo
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2010-2012 Daniel Azuma
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Redistribution and use in source and binary forms, with or without
11
+ # modification, are permitted provided that the following conditions are met:
12
+ #
13
+ # * Redistributions of source code must retain the above copyright notice,
14
+ # this list of conditions and the following disclaimer.
15
+ # * Redistributions in binary form must reproduce the above copyright notice,
16
+ # this list of conditions and the following disclaimer in the documentation
17
+ # and/or other materials provided with the distribution.
18
+ # * Neither the name of the copyright holder, nor the names of any other
19
+ # contributors to this software, may be used to endorse or promote products
20
+ # derived from this software without specific prior written permission.
21
+ #
22
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ # POSSIBILITY OF SUCH DAMAGE.
33
+ # -----------------------------------------------------------------------------
34
+ ;
35
+
36
+ require 'rgeo/geo_json'
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # GeoJSON implementation for RGeo
4
- #
4
+ #
5
5
  # -----------------------------------------------------------------------------
6
- # Copyright 2010 Daniel Azuma
7
- #
6
+ # Copyright 2010-2012 Daniel Azuma
7
+ #
8
8
  # All rights reserved.
9
- #
9
+ #
10
10
  # Redistribution and use in source and binary forms, with or without
11
11
  # modification, are permitted provided that the following conditions are met:
12
- #
12
+ #
13
13
  # * Redistributions of source code must retain the above copyright notice,
14
14
  # this list of conditions and the following disclaimer.
15
15
  # * Redistributions in binary form must reproduce the above copyright notice,
@@ -18,7 +18,7 @@
18
18
  # * Neither the name of the copyright holder, nor the names of any other
19
19
  # contributors to this software, may be used to endorse or promote products
20
20
  # derived from this software without specific prior written permission.
21
- #
21
+ #
22
22
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
23
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
24
  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -39,20 +39,20 @@ require 'rgeo'
39
39
 
40
40
 
41
41
  # RGeo is a spatial data library for Ruby, provided by the "rgeo" gem.
42
- #
42
+ #
43
43
  # The optional RGeo::GeoJSON module provides a set of tools for GeoJSON
44
44
  # encoding and decoding.
45
45
 
46
46
  module RGeo
47
-
48
-
47
+
48
+
49
49
  # This is a namespace for a set of tools that provide GeoJSON encoding.
50
50
  # See http://geojson.org/ for more information about this specification.
51
-
51
+
52
52
  module GeoJSON
53
53
  end
54
-
55
-
54
+
55
+
56
56
  end
57
57
 
58
58
 
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # GeoJSON encoder object
4
- #
4
+ #
5
5
  # -----------------------------------------------------------------------------
6
- # Copyright 2010 Daniel Azuma
7
- #
6
+ # Copyright 2010-2012 Daniel Azuma
7
+ #
8
8
  # All rights reserved.
9
- #
9
+ #
10
10
  # Redistribution and use in source and binary forms, with or without
11
11
  # modification, are permitted provided that the following conditions are met:
12
- #
12
+ #
13
13
  # * Redistributions of source code must retain the above copyright notice,
14
14
  # this list of conditions and the following disclaimer.
15
15
  # * Redistributions in binary form must reproduce the above copyright notice,
@@ -18,7 +18,7 @@
18
18
  # * Neither the name of the copyright holder, nor the names of any other
19
19
  # contributors to this software, may be used to endorse or promote products
20
20
  # derived from this software without specific prior written permission.
21
- #
21
+ #
22
22
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
23
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
24
  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -35,28 +35,28 @@
35
35
 
36
36
 
37
37
  module RGeo
38
-
38
+
39
39
  module GeoJSON
40
-
41
-
40
+
41
+
42
42
  # This object encapsulates encoding and decoding settings (principally
43
43
  # the RGeo::Feature::Factory and the RGeo::GeoJSON::EntityFactory to
44
44
  # be used) so that you can encode and decode without specifying those
45
45
  # settings every time.
46
-
46
+
47
47
  class Coder
48
-
49
-
48
+
49
+
50
50
  @@json_available = nil
51
51
  @@yajl_available = nil
52
52
  @@activesupport_available = nil
53
-
54
-
53
+
54
+
55
55
  # Create a new coder settings object. The geo factory is passed as
56
56
  # a required argument.
57
- #
57
+ #
58
58
  # Options include:
59
- #
59
+ #
60
60
  # <tt>:geo_factory</tt>::
61
61
  # Specifies the geo factory to use to create geometry objects.
62
62
  # Defaults to the preferred cartesian factory.
@@ -77,7 +77,7 @@ module RGeo
77
77
  # library in Ruby 1.9, but requires the "json" gem in Ruby 1.8.
78
78
  # If a parser is not specified, then the decode method will not
79
79
  # accept a String or IO object; it will require a Hash.
80
-
80
+
81
81
  def initialize(opts_={})
82
82
  @geo_factory = opts_[:geo_factory] || ::RGeo::Cartesian.preferred_factory
83
83
  @entity_factory = opts_[:entity_factory] || EntityFactory.instance
@@ -134,18 +134,18 @@ module RGeo
134
134
  @num_coordinates += 1 if @geo_factory.property(:has_z_coordinate)
135
135
  @num_coordinates += 1 if @geo_factory.property(:has_m_coordinate)
136
136
  end
137
-
138
-
137
+
138
+
139
139
  # Encode the given object as GeoJSON. The object may be one of the
140
140
  # geometry objects specified in RGeo::Feature, or an appropriate
141
141
  # GeoJSON wrapper entity supported by this coder's entity factory.
142
- #
142
+ #
143
143
  # This method returns a JSON object (i.e. a hash). In order to
144
144
  # generate a string suitable for transmitting to a service, you
145
145
  # will need to JSON-encode it. This is usually accomplished by
146
146
  # calling <tt>to_json</tt> on the hash object, if you have the
147
147
  # appropriate JSON library installed.
148
-
148
+
149
149
  def encode(object_)
150
150
  if @entity_factory.is_feature_collection?(object_)
151
151
  {
@@ -158,12 +158,12 @@ module RGeo
158
158
  _encode_geometry(object_)
159
159
  end
160
160
  end
161
-
162
-
161
+
162
+
163
163
  # Decode an object from GeoJSON. The input may be a JSON hash, a
164
164
  # String, or an IO object from which to read the JSON string.
165
165
  # If an error occurs, nil is returned.
166
-
166
+
167
167
  def decode(input_)
168
168
  if input_.kind_of?(::IO)
169
169
  input_ = input_.read rescue nil
@@ -191,23 +191,23 @@ module RGeo
191
191
  _decode_geometry(input_)
192
192
  end
193
193
  end
194
-
195
-
194
+
195
+
196
196
  # Returns the RGeo::Feature::Factory used to generate geometry objects.
197
-
197
+
198
198
  def geo_factory
199
199
  @geo_factory
200
200
  end
201
-
202
-
201
+
202
+
203
203
  # Returns the RGeo::GeoJSON::EntityFactory used to generate GeoJSON
204
204
  # wrapper entities.
205
-
205
+
206
206
  def entity_factory
207
207
  @entity_factory
208
208
  end
209
-
210
-
209
+
210
+
211
211
  def _encode_feature(object_) # :nodoc:
212
212
  json_ = {
213
213
  'type' => 'Feature',
@@ -218,8 +218,8 @@ module RGeo
218
218
  json_['id'] = id_ if id_
219
219
  json_
220
220
  end
221
-
222
-
221
+
222
+
223
223
  def _encode_geometry(object_, point_encoder_=nil) # :nodoc:
224
224
  unless point_encoder_
225
225
  if object_.factory.property(:has_z_coordinate)
@@ -276,8 +276,8 @@ module RGeo
276
276
  nil
277
277
  end
278
278
  end
279
-
280
-
279
+
280
+
281
281
  def _decode_feature(input_) # :nodoc:
282
282
  geometry_ = input_['geometry']
283
283
  if geometry_
@@ -286,8 +286,8 @@ module RGeo
286
286
  end
287
287
  @entity_factory.feature(geometry_, input_['id'], input_['properties'])
288
288
  end
289
-
290
-
289
+
290
+
291
291
  def _decode_geometry(input_) # :nodoc:
292
292
  case input_['type']
293
293
  when 'GeometryCollection'
@@ -308,8 +308,8 @@ module RGeo
308
308
  nil
309
309
  end
310
310
  end
311
-
312
-
311
+
312
+
313
313
  def _decode_geometry_collection(input_) # :nodoc:
314
314
  geometries_ = input_['geometries']
315
315
  geometries_ = [] unless geometries_.kind_of?(::Array)
@@ -320,14 +320,14 @@ module RGeo
320
320
  end
321
321
  @geo_factory.collection(decoded_geometries_)
322
322
  end
323
-
324
-
323
+
324
+
325
325
  def _decode_point_coords(point_coords_) # :nodoc:
326
326
  return nil unless point_coords_.kind_of?(::Array)
327
327
  @geo_factory.point(*(point_coords_[0...@num_coordinates].map{ |c_| c_.to_f })) rescue nil
328
328
  end
329
-
330
-
329
+
330
+
331
331
  def _decode_line_string_coords(line_coords_) # :nodoc:
332
332
  return nil unless line_coords_.kind_of?(::Array)
333
333
  points_ = []
@@ -337,8 +337,8 @@ module RGeo
337
337
  end
338
338
  @geo_factory.line_string(points_)
339
339
  end
340
-
341
-
340
+
341
+
342
342
  def _decode_polygon_coords(poly_coords_) # :nodoc:
343
343
  return nil unless poly_coords_.kind_of?(::Array)
344
344
  rings_ = []
@@ -358,8 +358,8 @@ module RGeo
358
358
  @geo_factory.polygon(rings_[0], rings_[1..-1])
359
359
  end
360
360
  end
361
-
362
-
361
+
362
+
363
363
  def _decode_multi_point_coords(multi_point_coords_) # :nodoc:
364
364
  return nil unless multi_point_coords_.kind_of?(::Array)
365
365
  points_ = []
@@ -369,8 +369,8 @@ module RGeo
369
369
  end
370
370
  @geo_factory.multi_point(points_)
371
371
  end
372
-
373
-
372
+
373
+
374
374
  def _decode_multi_line_string_coords(multi_line_coords_) # :nodoc:
375
375
  return nil unless multi_line_coords_.kind_of?(::Array)
376
376
  lines_ = []
@@ -380,8 +380,8 @@ module RGeo
380
380
  end
381
381
  @geo_factory.multi_line_string(lines_)
382
382
  end
383
-
384
-
383
+
384
+
385
385
  def _decode_multi_polygon_coords(multi_polygon_coords_) # :nodoc:
386
386
  return nil unless multi_polygon_coords_.kind_of?(::Array)
387
387
  polygons_ = []
@@ -391,11 +391,11 @@ module RGeo
391
391
  end
392
392
  @geo_factory.multi_polygon(polygons_)
393
393
  end
394
-
395
-
394
+
395
+
396
396
  end
397
-
398
-
397
+
398
+
399
399
  end
400
-
400
+
401
401
  end
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # GeoJSON standard entities
4
- #
4
+ #
5
5
  # -----------------------------------------------------------------------------
6
- # Copyright 2010 Daniel Azuma
7
- #
6
+ # Copyright 2010-2012 Daniel Azuma
7
+ #
8
8
  # All rights reserved.
9
- #
9
+ #
10
10
  # Redistribution and use in source and binary forms, with or without
11
11
  # modification, are permitted provided that the following conditions are met:
12
- #
12
+ #
13
13
  # * Redistributions of source code must retain the above copyright notice,
14
14
  # this list of conditions and the following disclaimer.
15
15
  # * Redistributions in binary form must reproduce the above copyright notice,
@@ -18,7 +18,7 @@
18
18
  # * Neither the name of the copyright holder, nor the names of any other
19
19
  # contributors to this software, may be used to endorse or promote products
20
20
  # derived from this software without specific prior written permission.
21
- #
21
+ #
22
22
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
23
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
24
  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -35,267 +35,270 @@
35
35
 
36
36
 
37
37
  module RGeo
38
-
38
+
39
39
  module GeoJSON
40
-
41
-
40
+
41
+
42
42
  # This is a GeoJSON wrapper entity that corresponds to the GeoJSON
43
43
  # "Feature" type. It is an immutable type.
44
- #
44
+ #
45
45
  # This is the default implementation that is generated by
46
46
  # RGeo::GeoJSON::EntityFactory. You may replace this implementation
47
47
  # by writing your own entity factory. Note that an alternate Feature
48
48
  # implementation need not subclass or even duck-type this class.
49
49
  # the entity factory mediates all interaction between the GeoJSON
50
50
  # engine and features.
51
-
51
+
52
52
  class Feature
53
-
54
-
53
+
54
+
55
55
  # Create a feature wrapping the given geometry, with the given ID
56
56
  # and properties.
57
-
57
+
58
58
  def initialize(geometry_, id_=nil, properties_={})
59
59
  @geometry = geometry_
60
60
  @id = id_
61
- @properties = properties_.dup
61
+ @properties = {}
62
+ properties_.each do |k_, v_|
63
+ @properties[k_.to_s] = v_
64
+ end
62
65
  end
63
-
64
-
66
+
67
+
65
68
  def inspect # :nodoc:
66
69
  "#<#{self.class}:0x#{object_id.to_s(16)} id=#{@id.inspect} geom=#{@geometry ? @geometry.as_text.inspect : 'nil'}>"
67
70
  end
68
-
71
+
69
72
  def to_s # :nodoc:
70
73
  inspect
71
74
  end
72
-
75
+
73
76
  def hash # :nodoc:
74
77
  @geometry.hash + @id.hash + @properties.hash
75
78
  end
76
-
77
-
79
+
80
+
78
81
  # Two features are equal if their geometries, IDs, and properties
79
82
  # are all equal.
80
83
  # This method uses the eql? method to test geometry equality, which
81
84
  # may behave differently than the == operator.
82
-
85
+
83
86
  def eql?(rhs_)
84
87
  rhs_.kind_of?(Feature) && @geometry.eql?(rhs_.geometry) && @id.eql?(rhs_.feature_id) && @properties.eql?(rhs_.instance_variable_get(:@properties))
85
88
  end
86
-
87
-
89
+
90
+
88
91
  # Two features are equal if their geometries, IDs, and properties
89
92
  # are all equal.
90
93
  # This method uses the == operator to test geometry equality, which
91
94
  # may behave differently than the eql? method.
92
-
95
+
93
96
  def ==(rhs_)
94
97
  rhs_.kind_of?(Feature) && @geometry == rhs_.geometry && @id == rhs_.feature_id && @properties == rhs_.instance_variable_get(:@properties)
95
98
  end
96
-
97
-
99
+
100
+
98
101
  # Returns the geometry contained in this feature, which may be nil.
99
-
102
+
100
103
  def geometry
101
104
  @geometry
102
105
  end
103
-
104
-
106
+
107
+
105
108
  # Returns the ID for this feature, which may be nil.
106
-
109
+
107
110
  def feature_id
108
111
  @id
109
112
  end
110
-
111
-
113
+
114
+
112
115
  # Returns a copy of the properties for this feature.
113
-
116
+
114
117
  def properties
115
118
  @properties.dup
116
119
  end
117
-
118
-
120
+
121
+
119
122
  # Gets the value of the given named property.
120
123
  # Returns nil if the given property is not found.
121
-
124
+
122
125
  def property(key_)
123
126
  @properties[key_.to_s]
124
127
  end
125
128
  alias_method :[], :property
126
-
127
-
129
+
130
+
128
131
  # Gets an array of the known property keys in this feature.
129
-
132
+
130
133
  def keys
131
134
  @properties.keys
132
135
  end
133
-
134
-
136
+
137
+
135
138
  end
136
-
137
-
139
+
140
+
138
141
  # This is a GeoJSON wrapper entity that corresponds to the GeoJSON
139
142
  # "FeatureCollection" type. It is an immutable type.
140
- #
143
+ #
141
144
  # This is the default implementation that is generated by
142
145
  # RGeo::GeoJSON::EntityFactory. You may replace this implementation
143
146
  # by writing your own entity factory. Note that an alternate
144
147
  # FeatureCollection implementation need not subclass or even
145
148
  # duck-type this class. The entity factory mediates all interaction
146
149
  # between the GeoJSON engine and feature collections.
147
-
150
+
148
151
  class FeatureCollection
149
-
152
+
150
153
  include ::Enumerable
151
-
152
-
154
+
155
+
153
156
  # Create a new FeatureCollection with the given features, which must
154
157
  # be provided as an Enumerable.
155
-
158
+
156
159
  def initialize(features_=[])
157
160
  @features = []
158
161
  features_.each{ |f_| @features << f_ if f_.kind_of?(Feature) }
159
162
  end
160
-
161
-
163
+
164
+
162
165
  def inspect # :nodoc:
163
166
  "#<#{self.class}:0x#{object_id.to_s(16)}>"
164
167
  end
165
-
168
+
166
169
  def to_s # :nodoc:
167
170
  inspect
168
171
  end
169
-
172
+
170
173
  def hash # :nodoc:
171
174
  @features.hash
172
175
  end
173
-
174
-
176
+
177
+
175
178
  # Two feature collections are equal if they contain the same
176
179
  # features in the same order.
177
180
  # This methods uses the eql? method to test geometry equality, which
178
181
  # may behave differently than the == operator.
179
-
182
+
180
183
  def eql?(rhs_)
181
184
  rhs_.kind_of?(FeatureCollection) && @features.eql?(rhs_.instance_variable_get(:@features))
182
185
  end
183
-
184
-
186
+
187
+
185
188
  # Two feature collections are equal if they contain the same
186
189
  # features in the same order.
187
190
  # This methods uses the == operator to test geometry equality, which
188
191
  # may behave differently than the eql? method.
189
-
192
+
190
193
  def ==(rhs_)
191
194
  rhs_.kind_of?(FeatureCollection) && @features == rhs_.instance_variable_get(:@features)
192
195
  end
193
-
194
-
196
+
197
+
195
198
  # Iterates or returns an iterator for the features.
196
-
199
+
197
200
  def each(&block_)
198
201
  @features.each(&block_)
199
202
  end
200
-
201
-
203
+
204
+
202
205
  # Returns the number of features contained in this collection.
203
-
206
+
204
207
  def size
205
208
  @features.size
206
209
  end
207
-
208
-
210
+
211
+
209
212
  # Access a feature by index.
210
-
213
+
211
214
  def [](index_)
212
215
  @features[index_]
213
216
  end
214
-
215
-
217
+
218
+
216
219
  end
217
-
218
-
220
+
221
+
219
222
  # This is the default entity factory. It creates objects of type
220
223
  # RGeo::GeoJSON::Feature and RGeo::GeoJSON::FeatureCollection.
221
224
  # You may create your own entity factory by duck-typing this class.
222
-
225
+
223
226
  class EntityFactory
224
-
225
-
227
+
228
+
226
229
  # Create and return a new feature, given geometry, ID, and
227
230
  # properties hash. Note that, per the GeoJSON spec, geometry and/or
228
231
  # properties may be nil.
229
-
232
+
230
233
  def feature(geometry_, id_=nil, properties_=nil)
231
234
  Feature.new(geometry_, id_, properties_ || {})
232
235
  end
233
-
234
-
236
+
237
+
235
238
  # Create and return a new feature collection, given an enumerable
236
239
  # of feature objects.
237
-
240
+
238
241
  def feature_collection(features_=[])
239
242
  FeatureCollection.new(features_)
240
243
  end
241
-
242
-
244
+
245
+
243
246
  # Returns true if the given object is a feature created by this
244
247
  # entity factory.
245
-
248
+
246
249
  def is_feature?(object_)
247
250
  object_.kind_of?(Feature)
248
251
  end
249
-
250
-
252
+
253
+
251
254
  # Returns true if the given object is a feature collection created
252
255
  # by this entity factory.
253
-
256
+
254
257
  def is_feature_collection?(object_)
255
258
  object_.kind_of?(FeatureCollection)
256
259
  end
257
-
258
-
260
+
261
+
259
262
  # Run Enumerable#map on the features contained in the given feature
260
263
  # collection.
261
-
264
+
262
265
  def map_feature_collection(object_, &block_)
263
266
  object_.map(&block_)
264
267
  end
265
-
266
-
268
+
269
+
267
270
  # Returns the geometry associated with the given feature.
268
-
271
+
269
272
  def get_feature_geometry(object_)
270
273
  object_.geometry
271
274
  end
272
-
273
-
275
+
276
+
274
277
  # Returns the ID of the given feature, or nil for no ID.
275
-
278
+
276
279
  def get_feature_id(object_)
277
280
  object_.feature_id
278
281
  end
279
-
280
-
282
+
283
+
281
284
  # Returns the properties of the given feature as a hash. Editing
282
285
  # this hash does not change the state of the feature.
283
-
286
+
284
287
  def get_feature_properties(object_)
285
288
  object_.properties
286
289
  end
287
-
288
-
290
+
291
+
289
292
  # Return the singleton instance of EntityFactory.
290
-
293
+
291
294
  def self.instance
292
295
  @instance ||= self.new
293
296
  end
294
-
295
-
297
+
298
+
296
299
  end
297
-
298
-
300
+
301
+
299
302
  end
300
-
303
+
301
304
  end
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # GeoJSON toplevel interface
4
- #
4
+ #
5
5
  # -----------------------------------------------------------------------------
6
- # Copyright 2010 Daniel Azuma
7
- #
6
+ # Copyright 2010-2012 Daniel Azuma
7
+ #
8
8
  # All rights reserved.
9
- #
9
+ #
10
10
  # Redistribution and use in source and binary forms, with or without
11
11
  # modification, are permitted provided that the following conditions are met:
12
- #
12
+ #
13
13
  # * Redistributions of source code must retain the above copyright notice,
14
14
  # this list of conditions and the following disclaimer.
15
15
  # * Redistributions in binary form must reproduce the above copyright notice,
@@ -18,7 +18,7 @@
18
18
  # * Neither the name of the copyright holder, nor the names of any other
19
19
  # contributors to this software, may be used to endorse or promote products
20
20
  # derived from this software without specific prior written permission.
21
- #
21
+ #
22
22
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
23
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
24
  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -35,34 +35,34 @@
35
35
 
36
36
 
37
37
  module RGeo
38
-
38
+
39
39
  module GeoJSON
40
-
40
+
41
41
  class << self
42
-
43
-
42
+
43
+
44
44
  # High-level convenience routine for encoding an object as GeoJSON.
45
45
  # Pass the object, which may one of the geometry objects specified
46
46
  # in RGeo::Feature, or an appropriate GeoJSON wrapper entity such
47
47
  # as RGeo::GeoJSON::Feature or RGeo::GeoJSON::FeatureCollection.
48
- #
48
+ #
49
49
  # The only option supported is <tt>:entity_factory</tt>, which lets
50
50
  # you override the types of GeoJSON entities supported. See
51
51
  # RGeo::GeoJSON::EntityFactory for more information. By default,
52
52
  # encode supports objects of type RGeo::GeoJSON::Feature and
53
53
  # RGeo::GeoJSON::FeatureCollection.
54
-
54
+
55
55
  def encode(object_, opts_={})
56
56
  Coder.new(opts_).encode(object_)
57
57
  end
58
-
59
-
58
+
59
+
60
60
  # High-level convenience routine for decoding an object from GeoJSON.
61
61
  # The input may be a JSON hash, a String, or an IO object from which
62
62
  # to read the JSON string.
63
- #
63
+ #
64
64
  # Options include:
65
- #
65
+ #
66
66
  # <tt>:geo_factory</tt>::
67
67
  # Specifies the geo factory to use to create geometry objects.
68
68
  # Defaults to the preferred cartesian factory.
@@ -83,19 +83,19 @@ module RGeo
83
83
  # library in Ruby 1.9, but requires the "json" gem in Ruby 1.8.
84
84
  # If a parser is not specified, then the decode method will not
85
85
  # accept a String or IO object; it will require a Hash.
86
-
86
+
87
87
  def decode(input_, opts_={})
88
88
  Coder.new(opts_).decode(input_)
89
89
  end
90
-
91
-
90
+
91
+
92
92
  # Creates and returns a coder object of type RGeo::GeoJSON::Coder
93
93
  # that encapsulates encoding and decoding settings (principally the
94
94
  # RGeo::Feature::Factory and the RGeo::GeoJSON::EntityFactory to be
95
95
  # used).
96
- #
96
+ #
97
97
  # The geo factory is a required argument. Other options include:
98
- #
98
+ #
99
99
  # <tt>:geo_factory</tt>::
100
100
  # Specifies the geo factory to use to create geometry objects.
101
101
  # Defaults to the preferred cartesian factory.
@@ -116,14 +116,14 @@ module RGeo
116
116
  # library in Ruby 1.9, but requires the "json" gem in Ruby 1.8.
117
117
  # If a parser is not specified, then the decode method will not
118
118
  # accept a String or IO object; it will require a Hash.
119
-
119
+
120
120
  def coder(opts_={})
121
121
  Coder.new(opts_)
122
122
  end
123
-
124
-
123
+
124
+
125
125
  end
126
-
126
+
127
127
  end
128
-
128
+
129
129
  end
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Version of rgeo-geojson
4
- #
4
+ #
5
5
  # -----------------------------------------------------------------------------
6
- # Copyright 2010 Daniel Azuma
7
- #
6
+ # Copyright 2010-2012 Daniel Azuma
7
+ #
8
8
  # All rights reserved.
9
- #
9
+ #
10
10
  # Redistribution and use in source and binary forms, with or without
11
11
  # modification, are permitted provided that the following conditions are met:
12
- #
12
+ #
13
13
  # * Redistributions of source code must retain the above copyright notice,
14
14
  # this list of conditions and the following disclaimer.
15
15
  # * Redistributions in binary form must reproduce the above copyright notice,
@@ -18,7 +18,7 @@
18
18
  # * Neither the name of the copyright holder, nor the names of any other
19
19
  # contributors to this software, may be used to endorse or promote products
20
20
  # derived from this software without specific prior written permission.
21
- #
21
+ #
22
22
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
23
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
24
  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -41,16 +41,16 @@ end
41
41
 
42
42
 
43
43
  module RGeo
44
-
44
+
45
45
  module GeoJSON
46
-
46
+
47
47
  # Current version of RGeo::GeoJSON as a frozen string
48
48
  VERSION_STRING = ::File.read(::File.dirname(__FILE__)+'/../../../Version').strip.freeze
49
-
49
+
50
50
  # Current version of RGeo::GeoJSON as a Versionomy object, if the
51
51
  # Versionomy gem is available; otherwise equal to VERSION_STRING.
52
52
  VERSION = defined?(::Versionomy) ? ::Versionomy.parse(VERSION_STRING) : VERSION_STRING
53
-
53
+
54
54
  end
55
-
55
+
56
56
  end
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Tests for basic GeoJSON usage
4
- #
4
+ #
5
5
  # -----------------------------------------------------------------------------
6
- # Copyright 2010 Daniel Azuma
7
- #
6
+ # Copyright 2010-2012 Daniel Azuma
7
+ #
8
8
  # All rights reserved.
9
- #
9
+ #
10
10
  # Redistribution and use in source and binary forms, with or without
11
11
  # modification, are permitted provided that the following conditions are met:
12
- #
12
+ #
13
13
  # * Redistributions of source code must retain the above copyright notice,
14
14
  # this list of conditions and the following disclaimer.
15
15
  # * Redistributions in binary form must reproduce the above copyright notice,
@@ -18,7 +18,7 @@
18
18
  # * Neither the name of the copyright holder, nor the names of any other
19
19
  # contributors to this software, may be used to endorse or promote products
20
20
  # derived from this software without specific prior written permission.
21
- #
21
+ #
22
22
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
23
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
24
  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -41,10 +41,10 @@ require 'rgeo/geo_json'
41
41
  module RGeo
42
42
  module GeoJSON
43
43
  module Tests # :nodoc:
44
-
44
+
45
45
  class TestGeoJSON < ::Test::Unit::TestCase # :nodoc:
46
-
47
-
46
+
47
+
48
48
  def setup
49
49
  @geo_factory = ::RGeo::Cartesian.simple_factory(:srid => 4326)
50
50
  @geo_factory_z = ::RGeo::Cartesian.simple_factory(:srid => 4326, :has_z_coordinate => true)
@@ -52,13 +52,13 @@ module RGeo
52
52
  @geo_factory_zm = ::RGeo::Cartesian.simple_factory(:srid => 4326, :has_z_coordinate => true, :has_m_coordinate => true)
53
53
  @entity_factory = ::RGeo::GeoJSON::EntityFactory.instance
54
54
  end
55
-
56
-
55
+
56
+
57
57
  def test_has_version
58
58
  assert_not_nil(::RGeo::GeoJSON::VERSION)
59
59
  end
60
-
61
-
60
+
61
+
62
62
  def test_point
63
63
  object_ = @geo_factory.point(10, 20)
64
64
  json_ = {
@@ -68,8 +68,8 @@ module RGeo
68
68
  assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
69
69
  assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
70
70
  end
71
-
72
-
71
+
72
+
73
73
  def test_point_z
74
74
  object_ = @geo_factory_z.point(10, 20, -1)
75
75
  json_ = {
@@ -79,8 +79,8 @@ module RGeo
79
79
  assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
80
80
  assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory_z).eql?(object_))
81
81
  end
82
-
83
-
82
+
83
+
84
84
  def test_point_m
85
85
  object_ = @geo_factory_m.point(10, 20, -1)
86
86
  json_ = {
@@ -90,8 +90,8 @@ module RGeo
90
90
  assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
91
91
  assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory_m).eql?(object_))
92
92
  end
93
-
94
-
93
+
94
+
95
95
  def test_point_zm
96
96
  object_ = @geo_factory_zm.point(10, 20, -1, -2)
97
97
  json_ = {
@@ -101,8 +101,8 @@ module RGeo
101
101
  assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
102
102
  assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory_zm).eql?(object_))
103
103
  end
104
-
105
-
104
+
105
+
106
106
  def test_line_string
107
107
  object_ = @geo_factory.line_string([@geo_factory.point(10, 20), @geo_factory.point(12, 22), @geo_factory.point(-3, 24)])
108
108
  json_ = {
@@ -112,8 +112,8 @@ module RGeo
112
112
  assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
113
113
  assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
114
114
  end
115
-
116
-
115
+
116
+
117
117
  def test_polygon
118
118
  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)]))
119
119
  json_ = {
@@ -123,8 +123,8 @@ module RGeo
123
123
  assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
124
124
  assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
125
125
  end
126
-
127
-
126
+
127
+
128
128
  def test_polygon_complex
129
129
  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)])])
130
130
  json_ = {
@@ -134,8 +134,8 @@ module RGeo
134
134
  assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
135
135
  assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
136
136
  end
137
-
138
-
137
+
138
+
139
139
  def test_multi_point
140
140
  object_ = @geo_factory.multi_point([@geo_factory.point(10, 20), @geo_factory.point(12, 22), @geo_factory.point(-3, 24)])
141
141
  json_ = {
@@ -145,8 +145,8 @@ module RGeo
145
145
  assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
146
146
  assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
147
147
  end
148
-
149
-
148
+
149
+
150
150
  def test_multi_line_string
151
151
  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)])])
152
152
  json_ = {
@@ -156,8 +156,8 @@ module RGeo
156
156
  assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
157
157
  assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
158
158
  end
159
-
160
-
159
+
160
+
161
161
  def test_multi_polygon
162
162
  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)]))])
163
163
  json_ = {
@@ -167,8 +167,8 @@ module RGeo
167
167
  assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
168
168
  assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
169
169
  end
170
-
171
-
170
+
171
+
172
172
  def test_geometry_collection
173
173
  object_ = @geo_factory.collection([@geo_factory.point(10, 20), @geo_factory.collection([@geo_factory.point(12, 22), @geo_factory.point(-3, 24)])])
174
174
  json_ = {
@@ -196,8 +196,8 @@ module RGeo
196
196
  assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
197
197
  assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
198
198
  end
199
-
200
-
199
+
200
+
201
201
  def test_feature
202
202
  object_ = @entity_factory.feature(@geo_factory.point(10, 20))
203
203
  json_ = {
@@ -211,8 +211,8 @@ module RGeo
211
211
  assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
212
212
  assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
213
213
  end
214
-
215
-
214
+
215
+
216
216
  def test_feature_nulls
217
217
  json_ = {
218
218
  'type' => 'Feature',
@@ -224,8 +224,8 @@ module RGeo
224
224
  assert_nil(obj_.geometry)
225
225
  assert_equal({}, obj_.properties)
226
226
  end
227
-
228
-
227
+
228
+
229
229
  def test_feature_complex
230
230
  object_ = @entity_factory.feature(@geo_factory.point(10, 20), 2, {'prop1' => 'foo', 'prop2' => 'bar'})
231
231
  json_ = {
@@ -240,8 +240,26 @@ module RGeo
240
240
  assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
241
241
  assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
242
242
  end
243
-
244
-
243
+
244
+
245
+ def test_feature_with_symbol_prop_keys
246
+ object_ = @entity_factory.feature(@geo_factory.point(10, 20), 2, {:prop1 => 'foo', 'prop2' => 'bar'})
247
+ json_ = {
248
+ 'type' => 'Feature',
249
+ 'geometry' => {
250
+ 'type' => 'Point',
251
+ 'coordinates' => [10.0, 20.0],
252
+ },
253
+ 'id' => 2,
254
+ 'properties' => {'prop1' => 'foo', 'prop2' => 'bar'},
255
+ }
256
+ assert_equal('foo', object_.property('prop1'))
257
+ assert_equal('bar', object_.property(:prop2))
258
+ assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
259
+ assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
260
+ end
261
+
262
+
245
263
  def test_feature_collection
246
264
  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)])
247
265
  json_ = {
@@ -277,10 +295,10 @@ module RGeo
277
295
  assert_equal(json_, ::RGeo::GeoJSON.encode(object_))
278
296
  assert(::RGeo::GeoJSON.decode(json_, :geo_factory => @geo_factory).eql?(object_))
279
297
  end
280
-
281
-
298
+
299
+
282
300
  end
283
-
301
+
284
302
  end
285
303
  end
286
304
  end
metadata CHANGED
@@ -1,73 +1,71 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rgeo-geojson
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
4
5
  prerelease:
5
- version: 0.2.1
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Daniel Azuma
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-04-11 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2012-01-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: rgeo
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2160272120 !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 0.2.8
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.3.3
24
22
  type: :runtime
25
- version_requirements: *id001
26
- description: RGeo is a geospatial data library for Ruby. RGeo::GeoJSON is an optional RGeo module providing GeoJSON encoding and decoding services. This module can be used to communicate with location-based web services that understand the GeoJSON format.
23
+ prerelease: false
24
+ version_requirements: *2160272120
25
+ description: RGeo is a geospatial data library for Ruby. RGeo::GeoJSON is an optional
26
+ RGeo module providing GeoJSON encoding and decoding services. This module can be
27
+ used to communicate with location-based web services that understand the GeoJSON
28
+ format.
27
29
  email: dazuma@gmail.com
28
30
  executables: []
29
-
30
31
  extensions: []
31
-
32
- extra_rdoc_files:
32
+ extra_rdoc_files:
33
33
  - History.rdoc
34
34
  - README.rdoc
35
- files:
35
+ files:
36
36
  - lib/rgeo/geo_json/coder.rb
37
37
  - lib/rgeo/geo_json/entities.rb
38
38
  - lib/rgeo/geo_json/interface.rb
39
39
  - lib/rgeo/geo_json/version.rb
40
40
  - lib/rgeo/geo_json.rb
41
+ - lib/rgeo-geojson.rb
41
42
  - test/tc_basic.rb
42
43
  - History.rdoc
43
44
  - README.rdoc
44
45
  - Version
45
46
  homepage: http://virtuoso.rubyforge.org/rgeo-geojson
46
47
  licenses: []
47
-
48
48
  post_install_message:
49
49
  rdoc_options: []
50
-
51
- require_paths:
50
+ require_paths:
52
51
  - lib
53
- required_ruby_version: !ruby/object:Gem::Requirement
52
+ required_ruby_version: !ruby/object:Gem::Requirement
54
53
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
58
57
  version: 1.8.7
59
- required_rubygems_version: !ruby/object:Gem::Requirement
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
59
  none: false
61
- requirements:
62
- - - ">"
63
- - !ruby/object:Gem::Version
60
+ requirements:
61
+ - - ! '>'
62
+ - !ruby/object:Gem::Version
64
63
  version: 1.3.1
65
64
  requirements: []
66
-
67
65
  rubyforge_project: virtuoso
68
- rubygems_version: 1.7.2
66
+ rubygems_version: 1.8.12
69
67
  signing_key:
70
68
  specification_version: 3
71
69
  summary: An RGeo module providing GeoJSON encoding and decoding.
72
- test_files:
70
+ test_files:
73
71
  - test/tc_basic.rb