rgeo-geojson 2.0.0 → 2.1.0
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 +4 -4
- data/History.md +6 -0
- data/lib/rgeo/geo_json/coder.rb +49 -50
- data/lib/rgeo/geo_json/version.rb +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31e3acae0a1cc1b8b417a6e66a03ea7b162cc598f6a48dfaf73a93535d13bbd9
|
4
|
+
data.tar.gz: 31eb694d0d74d5fb8d41b6c6d1b07017ec71aefd080678a27565b60bb037e29b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 181c8f3958610b3df6f6c830af066590b438fd3955cdd9cdfe7c80a00791a7038d9db37c711412380f4fd11a8f56b308c7fb7c50cfbc7b2c8bd3988dc680d90a
|
7
|
+
data.tar.gz: f3d13428ed86ee87c6850626df4cc6146170f89b163d47d3db8226f03b21096fd40badafb178e59205418daf354e1f5d549776a382c22f2145c7a69ae65d1d63
|
data/History.md
CHANGED
data/lib/rgeo/geo_json/coder.rb
CHANGED
@@ -44,14 +44,14 @@ module RGeo
|
|
44
44
|
if @entity_factory.is_feature_collection?(object)
|
45
45
|
{
|
46
46
|
"type" => "FeatureCollection",
|
47
|
-
"features" => @entity_factory.map_feature_collection(object) { |f|
|
47
|
+
"features" => @entity_factory.map_feature_collection(object) { |f| encode_feature(f) },
|
48
48
|
}
|
49
49
|
elsif @entity_factory.is_feature?(object)
|
50
|
-
|
50
|
+
encode_feature(object)
|
51
51
|
elsif object.nil?
|
52
52
|
nil
|
53
53
|
else
|
54
|
-
|
54
|
+
encode_geometry(object)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -66,9 +66,8 @@ module RGeo
|
|
66
66
|
if input.is_a?(String)
|
67
67
|
input = JSON.parse(input)
|
68
68
|
end
|
69
|
-
unless input.is_a?(Hash)
|
70
|
-
|
71
|
-
end
|
69
|
+
return unless input.is_a?(Hash)
|
70
|
+
|
72
71
|
case input["type"]
|
73
72
|
when "FeatureCollection"
|
74
73
|
features = input["features"]
|
@@ -76,14 +75,14 @@ module RGeo
|
|
76
75
|
decoded_features = []
|
77
76
|
features.each do |f|
|
78
77
|
if f["type"] == "Feature"
|
79
|
-
decoded_features <<
|
78
|
+
decoded_features << decode_feature(f)
|
80
79
|
end
|
81
80
|
end
|
82
81
|
@entity_factory.feature_collection(decoded_features)
|
83
82
|
when "Feature"
|
84
|
-
|
83
|
+
decode_feature(input)
|
85
84
|
else
|
86
|
-
|
85
|
+
decode_geometry(input)
|
87
86
|
end
|
88
87
|
end
|
89
88
|
|
@@ -98,10 +97,10 @@ module RGeo
|
|
98
97
|
|
99
98
|
private
|
100
99
|
|
101
|
-
def
|
100
|
+
def encode_feature(object)
|
102
101
|
json = {
|
103
102
|
"type" => "Feature",
|
104
|
-
"geometry" =>
|
103
|
+
"geometry" => encode_geometry(@entity_factory.get_feature_geometry(object)),
|
105
104
|
"properties" => @entity_factory.get_feature_properties(object).dup,
|
106
105
|
}
|
107
106
|
id = @entity_factory.get_feature_id(object)
|
@@ -109,7 +108,7 @@ module RGeo
|
|
109
108
|
json
|
110
109
|
end
|
111
110
|
|
112
|
-
def
|
111
|
+
def encode_geometry(object)
|
113
112
|
case object
|
114
113
|
when RGeo::Feature::Point
|
115
114
|
{
|
@@ -144,77 +143,77 @@ module RGeo
|
|
144
143
|
when RGeo::Feature::GeometryCollection
|
145
144
|
{
|
146
145
|
"type" => "GeometryCollection",
|
147
|
-
"geometries" => object.map { |geom|
|
146
|
+
"geometries" => object.map { |geom| encode_geometry(geom) }
|
148
147
|
}
|
149
148
|
else
|
150
149
|
nil
|
151
150
|
end
|
152
151
|
end
|
153
152
|
|
154
|
-
def
|
153
|
+
def decode_feature(input)
|
155
154
|
geometry = input["geometry"]
|
156
155
|
if geometry
|
157
|
-
geometry =
|
158
|
-
return
|
156
|
+
geometry = decode_geometry(geometry)
|
157
|
+
return unless geometry
|
159
158
|
end
|
160
159
|
@entity_factory.feature(geometry, input["id"], input["properties"])
|
161
160
|
end
|
162
161
|
|
163
|
-
def
|
162
|
+
def decode_geometry(input)
|
164
163
|
case input["type"]
|
165
164
|
when "GeometryCollection"
|
166
|
-
|
165
|
+
decode_geometry_collection(input)
|
167
166
|
when "Point"
|
168
|
-
|
167
|
+
decode_point_coords(input["coordinates"])
|
169
168
|
when "LineString"
|
170
|
-
|
169
|
+
decode_line_string_coords(input["coordinates"])
|
171
170
|
when "Polygon"
|
172
|
-
|
171
|
+
decode_polygon_coords(input["coordinates"])
|
173
172
|
when "MultiPoint"
|
174
|
-
|
173
|
+
decode_multi_point_coords(input["coordinates"])
|
175
174
|
when "MultiLineString"
|
176
|
-
|
175
|
+
decode_multi_line_string_coords(input["coordinates"])
|
177
176
|
when "MultiPolygon"
|
178
|
-
|
177
|
+
decode_multi_polygon_coords(input["coordinates"])
|
179
178
|
else
|
180
179
|
nil
|
181
180
|
end
|
182
181
|
end
|
183
182
|
|
184
|
-
def
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
183
|
+
def decode_geometry_collection(input)
|
184
|
+
geometries = input["geometries"]
|
185
|
+
geometries = [] unless geometries.is_a?(Array)
|
186
|
+
decoded_geometries = []
|
187
|
+
geometries.each do |geometry|
|
188
|
+
geometry = decode_geometry(geometry)
|
189
|
+
decoded_geometries << geometry if geometry
|
191
190
|
end
|
192
|
-
@geo_factory.collection(
|
191
|
+
@geo_factory.collection(decoded_geometries)
|
193
192
|
end
|
194
193
|
|
195
|
-
def
|
196
|
-
return
|
194
|
+
def decode_point_coords(point_coords)
|
195
|
+
return unless point_coords.is_a?(Array)
|
197
196
|
@geo_factory.point(*(point_coords[0...@num_coordinates].map(&:to_f))) rescue nil
|
198
197
|
end
|
199
198
|
|
200
|
-
def
|
201
|
-
return
|
199
|
+
def decode_line_string_coords(line_coords)
|
200
|
+
return unless line_coords.is_a?(Array)
|
202
201
|
points = []
|
203
202
|
line_coords.each do |point_coords|
|
204
|
-
point =
|
203
|
+
point = decode_point_coords(point_coords)
|
205
204
|
points << point if point
|
206
205
|
end
|
207
206
|
@geo_factory.line_string(points)
|
208
207
|
end
|
209
208
|
|
210
|
-
def
|
211
|
-
return
|
209
|
+
def decode_polygon_coords(poly_coords)
|
210
|
+
return unless poly_coords.is_a?(Array)
|
212
211
|
rings = []
|
213
212
|
poly_coords.each do |ring_coords|
|
214
|
-
return
|
213
|
+
return unless ring_coords.is_a?(Array)
|
215
214
|
points = []
|
216
215
|
ring_coords.each do |point_coords|
|
217
|
-
point =
|
216
|
+
point = decode_point_coords(point_coords)
|
218
217
|
points << point if point
|
219
218
|
end
|
220
219
|
ring = @geo_factory.linear_ring(points)
|
@@ -227,31 +226,31 @@ module RGeo
|
|
227
226
|
end
|
228
227
|
end
|
229
228
|
|
230
|
-
def
|
231
|
-
return
|
229
|
+
def decode_multi_point_coords(multi_point_coords)
|
230
|
+
return unless multi_point_coords.is_a?(Array)
|
232
231
|
points = []
|
233
232
|
multi_point_coords.each do |point_coords|
|
234
|
-
point =
|
233
|
+
point = decode_point_coords(point_coords)
|
235
234
|
points << point if point
|
236
235
|
end
|
237
236
|
@geo_factory.multi_point(points)
|
238
237
|
end
|
239
238
|
|
240
|
-
def
|
241
|
-
return
|
239
|
+
def decode_multi_line_string_coords(multi_line_coords)
|
240
|
+
return unless multi_line_coords.is_a?(Array)
|
242
241
|
lines = []
|
243
242
|
multi_line_coords.each do |line_coords|
|
244
|
-
line =
|
243
|
+
line = decode_line_string_coords(line_coords)
|
245
244
|
lines << line if line
|
246
245
|
end
|
247
246
|
@geo_factory.multi_line_string(lines)
|
248
247
|
end
|
249
248
|
|
250
|
-
def
|
251
|
-
return
|
249
|
+
def decode_multi_polygon_coords(multi_polygon_coords)
|
250
|
+
return unless multi_polygon_coords.is_a?(Array)
|
252
251
|
polygons = []
|
253
252
|
multi_polygon_coords.each do |poly_coords|
|
254
|
-
poly =
|
253
|
+
poly = decode_polygon_coords(poly_coords)
|
255
254
|
polygons << poly if poly
|
256
255
|
end
|
257
256
|
@geo_factory.multi_polygon(polygons)
|
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: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Azuma
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-11-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rgeo
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 1.0.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - "
|
25
|
+
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: 1.0.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: bundler
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -97,7 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
97
|
requirements:
|
98
98
|
- - ">="
|
99
99
|
- !ruby/object:Gem::Version
|
100
|
-
version: 2.
|
100
|
+
version: 2.3.0
|
101
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
102
|
requirements:
|
103
103
|
- - ">="
|
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
105
|
version: '0'
|
106
106
|
requirements: []
|
107
107
|
rubyforge_project:
|
108
|
-
rubygems_version: 2.7.
|
108
|
+
rubygems_version: 2.7.8
|
109
109
|
signing_key:
|
110
110
|
specification_version: 4
|
111
111
|
summary: Convert RGeo data to and from GeoJSON.
|