rgeo-geojson 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +8 -0
- data/lib/rgeo-geojson.rb +5 -1
- data/lib/rgeo/geo_json/coder.rb +128 -165
- data/lib/rgeo/geo_json/entities.rb +39 -39
- data/lib/rgeo/geo_json/interface.rb +6 -6
- data/lib/rgeo/geo_json/version.rb +1 -1
- metadata +2 -3
- data/lib/rgeo/geo_json.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc3be76c9c38e00c18464bd4fa71abbcc369a9dc
|
4
|
+
data.tar.gz: 508c6d9bf6a22fa8dba63d8aea3a569f6f287331
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21f7f32967c8c92f15ac42375852063c3528fa887f2d1dd728436e7ea26ce157518c5f2dd194c97a3d0c3b7819027aa181cf4a365dd72096085e4637d3b06d3b
|
7
|
+
data.tar.gz: 084e1f589f1a679d10fc15fd1584e94e9a6df76f498a587b9042f93d4a4f35befeacceab8498151e3efe02fadcaf9bd2cc21fa42dd1cee0c28849e2be42c761b
|
data/History.md
CHANGED
@@ -1,8 +1,16 @@
|
|
1
|
+
### 0.4.0 / 2015-12-28
|
2
|
+
|
3
|
+
* Removed error handling for missing parser gems
|
4
|
+
* Removed class variables in Coder
|
5
|
+
* Removed rgeo/geo_json.rb
|
6
|
+
|
7
|
+
|
1
8
|
### 0.3.3 / 2015-12-23
|
2
9
|
|
3
10
|
* Rubocop style updates #20
|
4
11
|
* Do not distribute test files with gem
|
5
12
|
|
13
|
+
|
6
14
|
### 0.3.2 / 2015-12-10
|
7
15
|
|
8
16
|
* Faster coordinates methods (tneems) #18
|
data/lib/rgeo-geojson.rb
CHANGED
data/lib/rgeo/geo_json/coder.rb
CHANGED
@@ -6,10 +6,6 @@ module RGeo
|
|
6
6
|
# settings every time.
|
7
7
|
|
8
8
|
class Coder
|
9
|
-
@@json_available = nil
|
10
|
-
@@yajl_available = nil
|
11
|
-
@@activesupport_available = nil
|
12
|
-
|
13
9
|
# Create a new coder settings object. The geo factory is passed as
|
14
10
|
# a required argument.
|
15
11
|
#
|
@@ -32,58 +28,25 @@ module RGeo
|
|
32
28
|
# <tt>:active_support</tt>. Setting one of those special values
|
33
29
|
# will require the corresponding library to be available. Note
|
34
30
|
# that the <tt>:json</tt> library is present in the standard
|
35
|
-
# library in Ruby 1.9
|
31
|
+
# library in Ruby 1.9.
|
36
32
|
# If a parser is not specified, then the decode method will not
|
37
33
|
# accept a String or IO object; it will require a Hash.
|
38
34
|
|
39
|
-
def initialize(
|
40
|
-
@geo_factory =
|
41
|
-
@entity_factory =
|
42
|
-
@json_parser =
|
35
|
+
def initialize(opts = {})
|
36
|
+
@geo_factory = opts[:geo_factory] || RGeo::Cartesian.preferred_factory
|
37
|
+
@entity_factory = opts[:entity_factory] || EntityFactory.instance
|
38
|
+
@json_parser = opts[:json_parser]
|
43
39
|
case @json_parser
|
44
40
|
when :json
|
45
|
-
|
46
|
-
|
47
|
-
require "json"
|
48
|
-
@@json_available = true
|
49
|
-
rescue ::LoadError
|
50
|
-
@@json_available = false
|
51
|
-
end
|
52
|
-
end
|
53
|
-
if @@json_available
|
54
|
-
@json_parser = ::Proc.new { |str_| ::JSON.parse(str_) }
|
55
|
-
else
|
56
|
-
raise Error::RGeoError, "JSON library is not available. You may need to install the 'json' gem."
|
57
|
-
end
|
41
|
+
require "json" unless defined?(JSON)
|
42
|
+
@json_parser = proc { |str| JSON.parse(str) }
|
58
43
|
when :yajl
|
59
|
-
|
60
|
-
|
61
|
-
require "yajl"
|
62
|
-
@@yajl_available = true
|
63
|
-
rescue ::LoadError
|
64
|
-
@@yajl_available = false
|
65
|
-
end
|
66
|
-
end
|
67
|
-
if @@yajl_available
|
68
|
-
@json_parser = ::Proc.new { |str_| ::Yajl::Parser.new.parse(str_) }
|
69
|
-
else
|
70
|
-
raise Error::RGeoError, "Yajl library is not available. You may need to install the 'yajl' gem."
|
71
|
-
end
|
44
|
+
require "yajl" unless defined?(Yajl)
|
45
|
+
@json_parser = proc { |str| Yajl::Parser.new.parse(str) }
|
72
46
|
when :active_support
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
@@activesupport_available = true
|
77
|
-
rescue ::LoadError
|
78
|
-
@@activesupport_available = false
|
79
|
-
end
|
80
|
-
end
|
81
|
-
if @@activesupport_available
|
82
|
-
@json_parser = ::Proc.new { |str_| ::ActiveSupport::JSON.decode(str_) }
|
83
|
-
else
|
84
|
-
raise Error::RGeoError, "ActiveSupport::JSON library is not available. You may need to install the 'activesupport' gem."
|
85
|
-
end
|
86
|
-
when ::Proc, nil
|
47
|
+
require "active_support/json" unless defined?(ActiveSupport::JSON)
|
48
|
+
@json_parser = proc { |str| ActiveSupport::JSON.decode(str) }
|
49
|
+
when Proc, nil
|
87
50
|
# Leave as is
|
88
51
|
else
|
89
52
|
raise ::ArgumentError, "Unrecognzied json_parser: #{@json_parser.inspect}"
|
@@ -105,18 +68,18 @@ module RGeo
|
|
105
68
|
#
|
106
69
|
# Returns nil if nil is passed in as the object.
|
107
70
|
|
108
|
-
def encode(
|
109
|
-
if @entity_factory.is_feature_collection?(
|
71
|
+
def encode(object)
|
72
|
+
if @entity_factory.is_feature_collection?(object)
|
110
73
|
{
|
111
74
|
"type" => "FeatureCollection",
|
112
|
-
"features" => @entity_factory.map_feature_collection(
|
75
|
+
"features" => @entity_factory.map_feature_collection(object) { |f| _encode_feature(f) },
|
113
76
|
}
|
114
|
-
elsif @entity_factory.is_feature?(
|
115
|
-
_encode_feature(
|
116
|
-
elsif
|
77
|
+
elsif @entity_factory.is_feature?(object)
|
78
|
+
_encode_feature(object)
|
79
|
+
elsif object.nil?
|
117
80
|
nil
|
118
81
|
else
|
119
|
-
_encode_geometry(
|
82
|
+
_encode_geometry(object)
|
120
83
|
end
|
121
84
|
end
|
122
85
|
|
@@ -124,31 +87,31 @@ module RGeo
|
|
124
87
|
# String, or an IO object from which to read the JSON string.
|
125
88
|
# If an error occurs, nil is returned.
|
126
89
|
|
127
|
-
def decode(
|
128
|
-
if
|
129
|
-
|
90
|
+
def decode(input)
|
91
|
+
if input.is_a?(IO)
|
92
|
+
input = input.read rescue nil
|
130
93
|
end
|
131
|
-
if
|
132
|
-
|
94
|
+
if input.is_a?(String)
|
95
|
+
input = @json_parser.call(input) rescue nil
|
133
96
|
end
|
134
|
-
unless
|
97
|
+
unless input.is_a?(Hash)
|
135
98
|
return nil
|
136
99
|
end
|
137
|
-
case
|
100
|
+
case input["type"]
|
138
101
|
when "FeatureCollection"
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
if
|
144
|
-
|
102
|
+
features = input["features"]
|
103
|
+
features = [] unless features.is_a?(Array)
|
104
|
+
decoded_features = []
|
105
|
+
features.each do |f|
|
106
|
+
if f["type"] == "Feature"
|
107
|
+
decoded_features << _decode_feature(f)
|
145
108
|
end
|
146
109
|
end
|
147
|
-
@entity_factory.feature_collection(
|
110
|
+
@entity_factory.feature_collection(decoded_features)
|
148
111
|
when "Feature"
|
149
|
-
_decode_feature(
|
112
|
+
_decode_feature(input)
|
150
113
|
else
|
151
|
-
_decode_geometry(
|
114
|
+
_decode_geometry(input)
|
152
115
|
end
|
153
116
|
end
|
154
117
|
|
@@ -161,107 +124,107 @@ module RGeo
|
|
161
124
|
|
162
125
|
attr_reader :entity_factory
|
163
126
|
|
164
|
-
def _encode_feature(
|
165
|
-
|
127
|
+
def _encode_feature(object) # :nodoc:
|
128
|
+
json = {
|
166
129
|
"type" => "Feature",
|
167
|
-
"geometry" => _encode_geometry(@entity_factory.get_feature_geometry(
|
168
|
-
"properties" => @entity_factory.get_feature_properties(
|
130
|
+
"geometry" => _encode_geometry(@entity_factory.get_feature_geometry(object)),
|
131
|
+
"properties" => @entity_factory.get_feature_properties(object).dup,
|
169
132
|
}
|
170
|
-
|
171
|
-
|
172
|
-
|
133
|
+
id = @entity_factory.get_feature_id(object)
|
134
|
+
json["id"] = id if id
|
135
|
+
json
|
173
136
|
end
|
174
137
|
|
175
|
-
def _encode_geometry(
|
176
|
-
unless
|
177
|
-
if
|
178
|
-
if
|
179
|
-
|
138
|
+
def _encode_geometry(object, point_encoder = nil) # :nodoc:
|
139
|
+
unless point_encoder
|
140
|
+
if object.factory.property(:has_z_coordinate)
|
141
|
+
if object.factory.property(:has_m_coordinate)
|
142
|
+
point_encoder = proc { |p| [p.x, p.y, p.z, p.m] }
|
180
143
|
else
|
181
|
-
|
144
|
+
point_encoder = proc { |p| [p.x, p.y, p.z] }
|
182
145
|
end
|
183
146
|
else
|
184
|
-
if
|
185
|
-
|
147
|
+
if object.factory.property(:has_m_coordinate)
|
148
|
+
point_encoder = proc { |p| [p.x, p.y, p.m] }
|
186
149
|
else
|
187
|
-
|
150
|
+
point_encoder = proc { |p| [p.x, p.y] }
|
188
151
|
end
|
189
152
|
end
|
190
153
|
end
|
191
|
-
case
|
192
|
-
when
|
154
|
+
case object
|
155
|
+
when RGeo::Feature::Point
|
193
156
|
{
|
194
157
|
"type" => "Point",
|
195
|
-
"coordinates" =>
|
158
|
+
"coordinates" => object.coordinates
|
196
159
|
}
|
197
|
-
when
|
160
|
+
when RGeo::Feature::LineString
|
198
161
|
{
|
199
162
|
"type" => "LineString",
|
200
|
-
"coordinates" =>
|
163
|
+
"coordinates" => object.coordinates
|
201
164
|
}
|
202
|
-
when
|
165
|
+
when RGeo::Feature::Polygon
|
203
166
|
{
|
204
167
|
"type" => "Polygon",
|
205
|
-
"coordinates" =>
|
168
|
+
"coordinates" => object.coordinates
|
206
169
|
}
|
207
|
-
when
|
170
|
+
when RGeo::Feature::MultiPoint
|
208
171
|
{
|
209
172
|
"type" => "MultiPoint",
|
210
|
-
"coordinates" =>
|
173
|
+
"coordinates" => object.coordinates
|
211
174
|
}
|
212
|
-
when
|
175
|
+
when RGeo::Feature::MultiLineString
|
213
176
|
{
|
214
177
|
"type" => "MultiLineString",
|
215
|
-
"coordinates" =>
|
178
|
+
"coordinates" => object.coordinates
|
216
179
|
}
|
217
|
-
when
|
180
|
+
when RGeo::Feature::MultiPolygon
|
218
181
|
{
|
219
182
|
"type" => "MultiPolygon",
|
220
|
-
"coordinates" =>
|
183
|
+
"coordinates" => object.coordinates
|
221
184
|
}
|
222
|
-
when
|
185
|
+
when RGeo::Feature::GeometryCollection
|
223
186
|
{
|
224
187
|
"type" => "GeometryCollection",
|
225
|
-
"geometries" =>
|
188
|
+
"geometries" => object.map { |geom| _encode_geometry(geom, point_encoder) },
|
226
189
|
}
|
227
190
|
else
|
228
191
|
nil
|
229
192
|
end
|
230
193
|
end
|
231
194
|
|
232
|
-
def _decode_feature(
|
233
|
-
|
234
|
-
if
|
235
|
-
|
236
|
-
return nil unless
|
195
|
+
def _decode_feature(input) # :nodoc:
|
196
|
+
geometry = input["geometry"]
|
197
|
+
if geometry
|
198
|
+
geometry = _decode_geometry(geometry)
|
199
|
+
return nil unless geometry
|
237
200
|
end
|
238
|
-
@entity_factory.feature(
|
201
|
+
@entity_factory.feature(geometry, input["id"], input["properties"])
|
239
202
|
end
|
240
203
|
|
241
|
-
def _decode_geometry(
|
242
|
-
case
|
204
|
+
def _decode_geometry(input) # :nodoc:
|
205
|
+
case input["type"]
|
243
206
|
when "GeometryCollection"
|
244
|
-
_decode_geometry_collection(
|
207
|
+
_decode_geometry_collection(input)
|
245
208
|
when "Point"
|
246
|
-
_decode_point_coords(
|
209
|
+
_decode_point_coords(input["coordinates"])
|
247
210
|
when "LineString"
|
248
|
-
_decode_line_string_coords(
|
211
|
+
_decode_line_string_coords(input["coordinates"])
|
249
212
|
when "Polygon"
|
250
|
-
_decode_polygon_coords(
|
213
|
+
_decode_polygon_coords(input["coordinates"])
|
251
214
|
when "MultiPoint"
|
252
|
-
_decode_multi_point_coords(
|
215
|
+
_decode_multi_point_coords(input["coordinates"])
|
253
216
|
when "MultiLineString"
|
254
|
-
_decode_multi_line_string_coords(
|
217
|
+
_decode_multi_line_string_coords(input["coordinates"])
|
255
218
|
when "MultiPolygon"
|
256
|
-
_decode_multi_polygon_coords(
|
219
|
+
_decode_multi_polygon_coords(input["coordinates"])
|
257
220
|
else
|
258
221
|
nil
|
259
222
|
end
|
260
223
|
end
|
261
224
|
|
262
|
-
def _decode_geometry_collection(
|
263
|
-
geometries_ =
|
264
|
-
geometries_ = [] unless geometries_.
|
225
|
+
def _decode_geometry_collection(input) # :nodoc:
|
226
|
+
geometries_ = input["geometries"]
|
227
|
+
geometries_ = [] unless geometries_.is_a?(Array)
|
265
228
|
decoded_geometries_ = []
|
266
229
|
geometries_.each do |g_|
|
267
230
|
g_ = _decode_geometry(g_)
|
@@ -270,69 +233,69 @@ module RGeo
|
|
270
233
|
@geo_factory.collection(decoded_geometries_)
|
271
234
|
end
|
272
235
|
|
273
|
-
def _decode_point_coords(
|
274
|
-
return nil unless
|
275
|
-
@geo_factory.point(*(
|
236
|
+
def _decode_point_coords(point_coords) # :nodoc:
|
237
|
+
return nil unless point_coords.is_a?(Array)
|
238
|
+
@geo_factory.point(*(point_coords[0...@num_coordinates].map(&:to_f))) rescue nil
|
276
239
|
end
|
277
240
|
|
278
|
-
def _decode_line_string_coords(
|
279
|
-
return nil unless
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
241
|
+
def _decode_line_string_coords(line_coords) # :nodoc:
|
242
|
+
return nil unless line_coords.is_a?(Array)
|
243
|
+
points = []
|
244
|
+
line_coords.each do |point_coords|
|
245
|
+
point = _decode_point_coords(point_coords)
|
246
|
+
points << point if point
|
284
247
|
end
|
285
|
-
@geo_factory.line_string(
|
248
|
+
@geo_factory.line_string(points)
|
286
249
|
end
|
287
250
|
|
288
|
-
def _decode_polygon_coords(
|
289
|
-
return nil unless
|
290
|
-
|
291
|
-
|
292
|
-
return nil unless
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
251
|
+
def _decode_polygon_coords(poly_coords) # :nodoc:
|
252
|
+
return nil unless poly_coords.is_a?(Array)
|
253
|
+
rings = []
|
254
|
+
poly_coords.each do |ring_coords|
|
255
|
+
return nil unless ring_coords.is_a?(Array)
|
256
|
+
points = []
|
257
|
+
ring_coords.each do |point_coords|
|
258
|
+
point = _decode_point_coords(point_coords)
|
259
|
+
points << point if point
|
297
260
|
end
|
298
|
-
|
299
|
-
|
261
|
+
ring = @geo_factory.linear_ring(points)
|
262
|
+
rings << ring if ring
|
300
263
|
end
|
301
|
-
if
|
264
|
+
if rings.size == 0
|
302
265
|
nil
|
303
266
|
else
|
304
|
-
@geo_factory.polygon(
|
267
|
+
@geo_factory.polygon(rings[0], rings[1..-1])
|
305
268
|
end
|
306
269
|
end
|
307
270
|
|
308
|
-
def _decode_multi_point_coords(
|
309
|
-
return nil unless
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
271
|
+
def _decode_multi_point_coords(multi_point_coords) # :nodoc:
|
272
|
+
return nil unless multi_point_coords.is_a?(Array)
|
273
|
+
points = []
|
274
|
+
multi_point_coords.each do |point_coords|
|
275
|
+
point = _decode_point_coords(point_coords)
|
276
|
+
points << point if point
|
314
277
|
end
|
315
|
-
@geo_factory.multi_point(
|
278
|
+
@geo_factory.multi_point(points)
|
316
279
|
end
|
317
280
|
|
318
|
-
def _decode_multi_line_string_coords(
|
319
|
-
return nil unless
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
281
|
+
def _decode_multi_line_string_coords(multi_line_coords) # :nodoc:
|
282
|
+
return nil unless multi_line_coords.is_a?(Array)
|
283
|
+
lines = []
|
284
|
+
multi_line_coords.each do |line_coords|
|
285
|
+
line = _decode_line_string_coords(line_coords)
|
286
|
+
lines << line if line
|
324
287
|
end
|
325
|
-
@geo_factory.multi_line_string(
|
288
|
+
@geo_factory.multi_line_string(lines)
|
326
289
|
end
|
327
290
|
|
328
|
-
def _decode_multi_polygon_coords(
|
329
|
-
return nil unless
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
291
|
+
def _decode_multi_polygon_coords(multi_polygon_coords) # :nodoc:
|
292
|
+
return nil unless multi_polygon_coords.is_a?(Array)
|
293
|
+
polygons = []
|
294
|
+
multi_polygon_coords.each do |poly_coords|
|
295
|
+
poly = _decode_polygon_coords(poly_coords)
|
296
|
+
polygons << poly if poly
|
334
297
|
end
|
335
|
-
@geo_factory.multi_polygon(
|
298
|
+
@geo_factory.multi_polygon(polygons)
|
336
299
|
end
|
337
300
|
end
|
338
301
|
end
|
@@ -14,17 +14,17 @@ module RGeo
|
|
14
14
|
# Create a feature wrapping the given geometry, with the given ID
|
15
15
|
# and properties.
|
16
16
|
|
17
|
-
def initialize(
|
18
|
-
@geometry =
|
19
|
-
@id =
|
17
|
+
def initialize(geometry, id = nil, properties = {})
|
18
|
+
@geometry = geometry
|
19
|
+
@id = id
|
20
20
|
@properties = {}
|
21
|
-
|
22
|
-
@properties[
|
21
|
+
properties.each do |k, v|
|
22
|
+
@properties[k.to_s] = v
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
def inspect # :nodoc:
|
27
|
-
"#<#{self.class}:0x#{
|
27
|
+
"#<#{self.class}:0x#{objectid.to_s(16)} id=#{@id.inspect} geom=#{@geometry ? @geometry.as_text.inspect : 'nil'}>"
|
28
28
|
end
|
29
29
|
|
30
30
|
def to_s # :nodoc:
|
@@ -40,8 +40,8 @@ module RGeo
|
|
40
40
|
# This method uses the eql? method to test geometry equality, which
|
41
41
|
# may behave differently than the == operator.
|
42
42
|
|
43
|
-
def eql?(
|
44
|
-
|
43
|
+
def eql?(other)
|
44
|
+
other.is_a?(Feature) && @geometry.eql?(other.geometry) && @id.eql?(other.feature_id) && @properties.eql?(other.instance_variable_get(:@properties))
|
45
45
|
end
|
46
46
|
|
47
47
|
# Two features are equal if their geometries, IDs, and properties
|
@@ -49,8 +49,8 @@ module RGeo
|
|
49
49
|
# This method uses the == operator to test geometry equality, which
|
50
50
|
# may behave differently than the eql? method.
|
51
51
|
|
52
|
-
def ==(
|
53
|
-
|
52
|
+
def ==(other)
|
53
|
+
other.is_a?(Feature) && @geometry == other.geometry && @id == other.feature_id && @properties == other.instance_variable_get(:@properties)
|
54
54
|
end
|
55
55
|
|
56
56
|
# Returns the geometry contained in this feature, which may be nil.
|
@@ -72,8 +72,8 @@ module RGeo
|
|
72
72
|
# Gets the value of the given named property.
|
73
73
|
# Returns nil if the given property is not found.
|
74
74
|
|
75
|
-
def property(
|
76
|
-
@properties[
|
75
|
+
def property(key)
|
76
|
+
@properties[key.to_s]
|
77
77
|
end
|
78
78
|
alias_method :[], :property
|
79
79
|
|
@@ -95,14 +95,14 @@ module RGeo
|
|
95
95
|
# between the GeoJSON engine and feature collections.
|
96
96
|
|
97
97
|
class FeatureCollection
|
98
|
-
include
|
98
|
+
include Enumerable
|
99
99
|
|
100
100
|
# Create a new FeatureCollection with the given features, which must
|
101
101
|
# be provided as an Enumerable.
|
102
102
|
|
103
|
-
def initialize(
|
103
|
+
def initialize(features = [])
|
104
104
|
@features = []
|
105
|
-
|
105
|
+
features.each { |f| @features << f if f.is_a?(Feature) }
|
106
106
|
end
|
107
107
|
|
108
108
|
def inspect # :nodoc:
|
@@ -122,8 +122,8 @@ module RGeo
|
|
122
122
|
# This methods uses the eql? method to test geometry equality, which
|
123
123
|
# may behave differently than the == operator.
|
124
124
|
|
125
|
-
def eql?(
|
126
|
-
|
125
|
+
def eql?(other)
|
126
|
+
other.is_a?(FeatureCollection) && @features.eql?(other.instance_variable_get(:@features))
|
127
127
|
end
|
128
128
|
|
129
129
|
# Two feature collections are equal if they contain the same
|
@@ -131,14 +131,14 @@ module RGeo
|
|
131
131
|
# This methods uses the == operator to test geometry equality, which
|
132
132
|
# may behave differently than the eql? method.
|
133
133
|
|
134
|
-
def ==(
|
135
|
-
|
134
|
+
def ==(other)
|
135
|
+
other.is_a?(FeatureCollection) && @features == other.instance_variable_get(:@features)
|
136
136
|
end
|
137
137
|
|
138
138
|
# Iterates or returns an iterator for the features.
|
139
139
|
|
140
|
-
def each(&
|
141
|
-
@features.each(&
|
140
|
+
def each(&block)
|
141
|
+
@features.each(&block)
|
142
142
|
end
|
143
143
|
|
144
144
|
# Returns the number of features contained in this collection.
|
@@ -149,8 +149,8 @@ module RGeo
|
|
149
149
|
|
150
150
|
# Access a feature by index.
|
151
151
|
|
152
|
-
def [](
|
153
|
-
@features[
|
152
|
+
def [](index)
|
153
|
+
@features[index]
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
@@ -163,55 +163,55 @@ module RGeo
|
|
163
163
|
# properties hash. Note that, per the GeoJSON spec, geometry and/or
|
164
164
|
# properties may be nil.
|
165
165
|
|
166
|
-
def feature(
|
167
|
-
Feature.new(
|
166
|
+
def feature(geometry, id = nil, properties = nil)
|
167
|
+
Feature.new(geometry, id, properties || {})
|
168
168
|
end
|
169
169
|
|
170
170
|
# Create and return a new feature collection, given an enumerable
|
171
171
|
# of feature objects.
|
172
172
|
|
173
|
-
def feature_collection(
|
174
|
-
FeatureCollection.new(
|
173
|
+
def feature_collection(features = [])
|
174
|
+
FeatureCollection.new(features)
|
175
175
|
end
|
176
176
|
|
177
177
|
# Returns true if the given object is a feature created by this
|
178
178
|
# entity factory.
|
179
179
|
|
180
|
-
def is_feature?(
|
181
|
-
|
180
|
+
def is_feature?(object)
|
181
|
+
object.is_a?(Feature)
|
182
182
|
end
|
183
183
|
|
184
184
|
# Returns true if the given object is a feature collection created
|
185
185
|
# by this entity factory.
|
186
186
|
|
187
|
-
def is_feature_collection?(
|
188
|
-
|
187
|
+
def is_feature_collection?(object)
|
188
|
+
object.is_a?(FeatureCollection)
|
189
189
|
end
|
190
190
|
|
191
191
|
# Run Enumerable#map on the features contained in the given feature
|
192
192
|
# collection.
|
193
193
|
|
194
|
-
def map_feature_collection(
|
195
|
-
|
194
|
+
def map_feature_collection(object, &block)
|
195
|
+
object.map(&block)
|
196
196
|
end
|
197
197
|
|
198
198
|
# Returns the geometry associated with the given feature.
|
199
199
|
|
200
|
-
def get_feature_geometry(
|
201
|
-
|
200
|
+
def get_feature_geometry(object)
|
201
|
+
object.geometry
|
202
202
|
end
|
203
203
|
|
204
204
|
# Returns the ID of the given feature, or nil for no ID.
|
205
205
|
|
206
|
-
def get_feature_id(
|
207
|
-
|
206
|
+
def get_feature_id(object)
|
207
|
+
object.feature_id
|
208
208
|
end
|
209
209
|
|
210
210
|
# Returns the properties of the given feature as a hash. Editing
|
211
211
|
# this hash does not change the state of the feature.
|
212
212
|
|
213
|
-
def get_feature_properties(
|
214
|
-
|
213
|
+
def get_feature_properties(object)
|
214
|
+
object.properties
|
215
215
|
end
|
216
216
|
|
217
217
|
# Return the singleton instance of EntityFactory.
|
@@ -12,8 +12,8 @@ module RGeo
|
|
12
12
|
# encode supports objects of type RGeo::GeoJSON::Feature and
|
13
13
|
# RGeo::GeoJSON::FeatureCollection.
|
14
14
|
|
15
|
-
def encode(
|
16
|
-
Coder.new(
|
15
|
+
def encode(object, opts = {})
|
16
|
+
Coder.new(opts).encode(object)
|
17
17
|
end
|
18
18
|
|
19
19
|
# High-level convenience routine for decoding an object from GeoJSON.
|
@@ -43,8 +43,8 @@ module RGeo
|
|
43
43
|
# If a parser is not specified, then the decode method will not
|
44
44
|
# accept a String or IO object; it will require a Hash.
|
45
45
|
|
46
|
-
def decode(input_,
|
47
|
-
Coder.new(
|
46
|
+
def decode(input_, opts = {})
|
47
|
+
Coder.new(opts).decode(input_)
|
48
48
|
end
|
49
49
|
|
50
50
|
# Creates and returns a coder object of type RGeo::GeoJSON::Coder
|
@@ -75,8 +75,8 @@ module RGeo
|
|
75
75
|
# If a parser is not specified, then the decode method will not
|
76
76
|
# accept a String or IO object; it will require a Hash.
|
77
77
|
|
78
|
-
def coder(
|
79
|
-
Coder.new(
|
78
|
+
def coder(opts = {})
|
79
|
+
Coder.new(opts)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
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.
|
4
|
+
version: 0.4.0
|
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-
|
12
|
+
date: 2015-12-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rgeo
|
@@ -80,7 +80,6 @@ files:
|
|
80
80
|
- LICENSE.txt
|
81
81
|
- README.md
|
82
82
|
- lib/rgeo-geojson.rb
|
83
|
-
- lib/rgeo/geo_json.rb
|
84
83
|
- lib/rgeo/geo_json/coder.rb
|
85
84
|
- lib/rgeo/geo_json/entities.rb
|
86
85
|
- lib/rgeo/geo_json/interface.rb
|
data/lib/rgeo/geo_json.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require "rgeo"
|
2
|
-
|
3
|
-
# RGeo is a spatial data library for Ruby, provided by the "rgeo" gem.
|
4
|
-
#
|
5
|
-
# The optional RGeo::GeoJSON module provides a set of tools for GeoJSON
|
6
|
-
# encoding and decoding.
|
7
|
-
|
8
|
-
module RGeo
|
9
|
-
# This is a namespace for a set of tools that provide GeoJSON encoding.
|
10
|
-
# See http://geojson.org/ for more information about this specification.
|
11
|
-
|
12
|
-
module GeoJSON
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
# Implementation files
|
17
|
-
require "rgeo/geo_json/version"
|
18
|
-
require "rgeo/geo_json/entities"
|
19
|
-
require "rgeo/geo_json/coder"
|
20
|
-
require "rgeo/geo_json/interface"
|