terraformer 0.0.6 → 0.0.7
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/Gemfile +1 -0
- data/lib/terraformer/arcgis.rb +226 -0
- data/lib/terraformer/coordinate.rb +7 -1
- data/lib/terraformer/feature.rb +18 -5
- data/lib/terraformer/geometry.rb +2 -1
- data/lib/terraformer/multi_polygon.rb +9 -3
- data/lib/terraformer/polygon.rb +21 -7
- data/lib/terraformer/version.rb +1 -1
- data/test/arcgis_spec.rb +899 -0
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54582188df43611a0c97f98da5aa5cb4d4536930
|
4
|
+
data.tar.gz: 0980f0f42c63fbc4467f1d6cc8fbcf2d8f05b35a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5179f0a38c1f9be3484033b314b5a9ae9ebee77f887df1ab42473a3249851ff67761039905bb863be4ce8bc914f73fef974a6182ceb29e7c373a3eff526c94e7
|
7
|
+
data.tar.gz: 83a1031d1f5721640184cd5fe0f5bdc6ac88294549622693dd0a747aa84a8081b9d11ade0b07e31a59b04773bcf9763d93f42fcc90c94fa3d776773d264c94c6
|
data/Gemfile
CHANGED
@@ -0,0 +1,226 @@
|
|
1
|
+
module Terraformer
|
2
|
+
module ArcGIS
|
3
|
+
|
4
|
+
COMPRESSED_REGEX = /((\+|\-)[^\+\-]+)/
|
5
|
+
OBJECT_ID = 'OBJECTID'
|
6
|
+
|
7
|
+
class << self
|
8
|
+
|
9
|
+
def require_array a
|
10
|
+
raise ArgumentError.new 'argument is not an Array' unless Array === a
|
11
|
+
end
|
12
|
+
private :require_array
|
13
|
+
|
14
|
+
def decompress_geometry str
|
15
|
+
raise ArgumentError.new 'argument is not a String' unless String === str
|
16
|
+
x_diff_prev, y_diff_prev = 0, 0
|
17
|
+
points = []
|
18
|
+
x,y = nil,nil
|
19
|
+
strings = str.scan(COMPRESSED_REGEX).map {|m| m[0]}
|
20
|
+
coefficient = Integer(strings.shift, 32).to_f
|
21
|
+
strings.each_slice(2) do |m,n|
|
22
|
+
x = Integer(m, 32) + x_diff_prev
|
23
|
+
x_diff_prev = x
|
24
|
+
y = Integer(n, 32) + y_diff_prev
|
25
|
+
y_diff_prev = y
|
26
|
+
points << [x/coefficient, y/coefficient]
|
27
|
+
end
|
28
|
+
points
|
29
|
+
end
|
30
|
+
|
31
|
+
def close_ring cs
|
32
|
+
require_array cs
|
33
|
+
cs << cs.first if cs.first != cs.last
|
34
|
+
cs
|
35
|
+
end
|
36
|
+
|
37
|
+
def clockwise? ring
|
38
|
+
require_array ring
|
39
|
+
total, i = 0, 0
|
40
|
+
r_lim = ring.length - 1
|
41
|
+
ring.each_cons(2) do |a,b|
|
42
|
+
total += (b[0] - a[0]) * (b[1] + a[1])
|
43
|
+
i += 1
|
44
|
+
break if i == r_lim
|
45
|
+
end
|
46
|
+
total >= 0
|
47
|
+
end
|
48
|
+
|
49
|
+
def orient_rings polygon
|
50
|
+
require_array polygon
|
51
|
+
oriented = []
|
52
|
+
outer_ring = close_ring polygon.shift
|
53
|
+
if outer_ring.length >= 4
|
54
|
+
outer_ring.reverse! unless clockwise? outer_ring
|
55
|
+
oriented << outer_ring
|
56
|
+
polygon.each do |hole|
|
57
|
+
hole = close_ring hole
|
58
|
+
if hole.length >= 4
|
59
|
+
hole.reverse if clockwise? hole
|
60
|
+
end
|
61
|
+
oriented << hole
|
62
|
+
end
|
63
|
+
end
|
64
|
+
oriented
|
65
|
+
end
|
66
|
+
|
67
|
+
def convert_rings rings
|
68
|
+
require_array rings
|
69
|
+
outer_rings, holes = [], []
|
70
|
+
|
71
|
+
rings.each do |ring|
|
72
|
+
ring = close_ring ring
|
73
|
+
next if ring.length < 4
|
74
|
+
if clockwise? ring
|
75
|
+
outer_rings << [ring]
|
76
|
+
else
|
77
|
+
holes << ring
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
holes.each do |hole|
|
82
|
+
matched = false
|
83
|
+
outer_rings.each do |oring|
|
84
|
+
if Polygon.new(oring[0]).contains? Polygon.new(hole)
|
85
|
+
oring << hole
|
86
|
+
matched = true
|
87
|
+
break
|
88
|
+
end
|
89
|
+
end
|
90
|
+
outer_rings << [hole.reverse] unless matched
|
91
|
+
end
|
92
|
+
|
93
|
+
if outer_rings.length == 1
|
94
|
+
Polygon.new outer_rings.first
|
95
|
+
else
|
96
|
+
polygons = outer_rings.map {|r| Polygon.new r}
|
97
|
+
MultiPolygon.new *polygons
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def parse arcgis, opts = {}
|
102
|
+
arcgis = JSON.parse arcgis if String === arcgis
|
103
|
+
raise ArgumentError.new 'argument not hash nor json' unless Hash === arcgis
|
104
|
+
|
105
|
+
obj = case
|
106
|
+
when Numeric === arcgis['x'] && Numeric === arcgis['y']
|
107
|
+
Coordinate.new(%w[x y z].map {|k| arcgis[k]}).to_point
|
108
|
+
|
109
|
+
when arcgis['points']
|
110
|
+
require_array arcgis['points']
|
111
|
+
MultiPoint.new arcgis['points']
|
112
|
+
|
113
|
+
when arcgis['paths']
|
114
|
+
require_array arcgis['paths']
|
115
|
+
if arcgis['paths'].length == 1
|
116
|
+
LineString.new arcgis['paths'][0]
|
117
|
+
else
|
118
|
+
MultiLineString.new arcgis['paths']
|
119
|
+
end
|
120
|
+
|
121
|
+
when arcgis['rings']
|
122
|
+
convert_rings arcgis['rings']
|
123
|
+
|
124
|
+
when !(%w[compressedGeometry geometry attributes].map {|k| arcgis[k]}.empty?)
|
125
|
+
|
126
|
+
if arcgis['compressedGeometry']
|
127
|
+
arcgis['geometry'] = {'paths' => [decompress_geometry(arcgis['compressedGeometry'])]}
|
128
|
+
end
|
129
|
+
|
130
|
+
o = Feature.new
|
131
|
+
o.geometry = parse arcgis['geometry'] if arcgis['geometry']
|
132
|
+
if attrs = arcgis['attributes']
|
133
|
+
o.properties = attrs.clone
|
134
|
+
if opts[:id_attribute] and o.properties[opts[:id_attribute]]
|
135
|
+
o.id = o.properties.delete opts[:id_attribute]
|
136
|
+
elsif o.properties[OBJECT_ID]
|
137
|
+
o.id = o.properties.delete OBJECT_ID
|
138
|
+
elsif o.properties['FID']
|
139
|
+
o.id = o.properties.delete 'FID'
|
140
|
+
end
|
141
|
+
end
|
142
|
+
o
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
isr = arcgis['geometry'] ? arcgis['geometry']['spatialReference'] : arcgis['spatialReference']
|
147
|
+
if isr and Integer(isr['wkid']) == 102100
|
148
|
+
if Feature === obj
|
149
|
+
obj.geometry = obj.geometry.to_geographic
|
150
|
+
else
|
151
|
+
obj = obj.to_geographic
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
obj
|
156
|
+
end
|
157
|
+
|
158
|
+
def convert geojson, opts = {}
|
159
|
+
geojson = Terraformer.parse geojson unless Primitive === geojson
|
160
|
+
opts[:id_attribute] ||= OBJECT_ID
|
161
|
+
|
162
|
+
sr = {wkid: opts[:sr] || 4326}
|
163
|
+
geojson_crs = GeometryCollection === geojson ? geojson.geometries.first.crs : geojson.crs
|
164
|
+
sr[:wkid] = 102100 if geojson_crs == Terraformer::MERCATOR_CRS
|
165
|
+
|
166
|
+
arcgis = {}
|
167
|
+
|
168
|
+
case geojson
|
169
|
+
when Point
|
170
|
+
fc = geojson.first_coordinate
|
171
|
+
arcgis[:x] = fc.x
|
172
|
+
arcgis[:y] = fc.y
|
173
|
+
arcgis[:z] = fc.z if fc.z
|
174
|
+
arcgis[:spatialReference] = sr
|
175
|
+
|
176
|
+
when MultiPoint
|
177
|
+
arcgis[:points] = geojson.coordinates.clone
|
178
|
+
arcgis[:spatialReference] = sr
|
179
|
+
|
180
|
+
when LineString
|
181
|
+
arcgis[:paths] = [geojson.coordinates.clone]
|
182
|
+
arcgis[:spatialReference] = sr
|
183
|
+
|
184
|
+
when MultiLineString
|
185
|
+
arcgis[:paths] = geojson.coordinates.clone
|
186
|
+
arcgis[:spatialReference] = sr
|
187
|
+
|
188
|
+
when Polygon
|
189
|
+
arcgis[:rings] = orient_rings geojson.coordinates.clone
|
190
|
+
arcgis[:spatialReference] = sr
|
191
|
+
|
192
|
+
when MultiPolygon
|
193
|
+
arcgis[:rings] = flatten_multi_polygon_rings geojson.coordinates.clone
|
194
|
+
arcgis[:spatialReference] = sr
|
195
|
+
|
196
|
+
when Feature
|
197
|
+
arcgis[:geometry] = convert(geojson.geometry, opts) if geojson.geometry
|
198
|
+
arcgis[:attributes] = geojson.properties ? geojson.properties.clone : {}
|
199
|
+
arcgis[:attributes][opts[:id_attribute]] = geojson.id if geojson.id
|
200
|
+
|
201
|
+
when FeatureCollection
|
202
|
+
arcgis = geojson.features.map {|f| convert f, opts}
|
203
|
+
|
204
|
+
when GeometryCollection
|
205
|
+
arcgis = geojson.geometries.map {|f| convert f, opts}
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
arcgis
|
210
|
+
end
|
211
|
+
|
212
|
+
def flatten_multi_polygon_rings rings
|
213
|
+
out = []
|
214
|
+
rings.each do |r|
|
215
|
+
polygon = orient_rings r
|
216
|
+
polygon.reverse.each do |p|
|
217
|
+
out << p.dup
|
218
|
+
end
|
219
|
+
end
|
220
|
+
out
|
221
|
+
end
|
222
|
+
|
223
|
+
end
|
224
|
+
|
225
|
+
end
|
226
|
+
end
|
@@ -40,10 +40,12 @@ module Terraformer
|
|
40
40
|
raise ArgumentError if _y
|
41
41
|
self.x = _x[0]
|
42
42
|
self.y = _x[1]
|
43
|
+
self.z = _x[2] if _x[2]
|
43
44
|
when Numeric === _x || String === _x
|
44
45
|
raise ArgumentError unless _y
|
45
46
|
self.x = _x
|
46
47
|
self.y = _y
|
48
|
+
self.z = _z if _z
|
47
49
|
else
|
48
50
|
raise ArgumentError.new "invalid argument: #{_x}"
|
49
51
|
end
|
@@ -69,7 +71,11 @@ module Terraformer
|
|
69
71
|
self[2]
|
70
72
|
end
|
71
73
|
|
72
|
-
|
74
|
+
def z= _z
|
75
|
+
self[2] = Coordinate.big_decimal _z
|
76
|
+
end
|
77
|
+
|
78
|
+
[:<<, :*, :&, :|].each do |sym|
|
73
79
|
define_method(sym){|*a| raise NotImplementedError }
|
74
80
|
end
|
75
81
|
|
data/lib/terraformer/feature.rb
CHANGED
@@ -3,7 +3,7 @@ module Terraformer
|
|
3
3
|
class Feature < Primitive
|
4
4
|
extend Forwardable
|
5
5
|
|
6
|
-
attr_accessor :id, :geometry
|
6
|
+
attr_accessor :id, :geometry, :crs
|
7
7
|
attr_writer :properties
|
8
8
|
|
9
9
|
def_delegator :@geometry, :convex_hull
|
@@ -13,7 +13,7 @@ module Terraformer
|
|
13
13
|
super *args do |arg|
|
14
14
|
self.id = arg['id'] if arg.key? 'id'
|
15
15
|
self.properties = arg['properties'] if arg.key? 'properties'
|
16
|
-
self.geometry = Terraformer.parse arg['geometry']
|
16
|
+
self.geometry = Terraformer.parse arg['geometry'] if arg['geometry']
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -26,9 +26,9 @@ module Terraformer
|
|
26
26
|
h = {
|
27
27
|
type: type,
|
28
28
|
properties: properties,
|
29
|
-
geometry: geometry.to_hash
|
30
29
|
}
|
31
|
-
h
|
30
|
+
h[:geometry] = geometry.to_hash if geometry
|
31
|
+
h[:id] = id if id
|
32
32
|
h
|
33
33
|
end
|
34
34
|
|
@@ -41,10 +41,16 @@ module Terraformer
|
|
41
41
|
Terraformer.geojson_io self
|
42
42
|
end
|
43
43
|
|
44
|
+
def == obj
|
45
|
+
return false unless Feature === obj
|
46
|
+
to_hash == obj.to_hash
|
47
|
+
end
|
48
|
+
|
44
49
|
end
|
45
50
|
|
46
51
|
class FeatureCollection < Primitive
|
47
52
|
|
53
|
+
attr_accessor :crs
|
48
54
|
attr_writer :features
|
49
55
|
|
50
56
|
def self.with_features *f
|
@@ -72,10 +78,17 @@ module Terraformer
|
|
72
78
|
end
|
73
79
|
|
74
80
|
def to_hash
|
75
|
-
{
|
81
|
+
h = {
|
76
82
|
type: type,
|
77
83
|
features: features.map(&:to_hash)
|
78
84
|
}
|
85
|
+
h[:crs] = crs if crs
|
86
|
+
h
|
87
|
+
end
|
88
|
+
|
89
|
+
def == obj
|
90
|
+
return false unless FeatureCollection === obj
|
91
|
+
to_hash == obj.to_hash
|
79
92
|
end
|
80
93
|
|
81
94
|
def convex_hull
|
data/lib/terraformer/geometry.rb
CHANGED
@@ -7,7 +7,7 @@ module Terraformer
|
|
7
7
|
|
8
8
|
MULTI_REGEX = /^Multi/
|
9
9
|
|
10
|
-
attr_accessor :coordinates
|
10
|
+
attr_accessor :coordinates, :crs
|
11
11
|
|
12
12
|
def initialize *args
|
13
13
|
case
|
@@ -27,6 +27,7 @@ module Terraformer
|
|
27
27
|
type: type,
|
28
28
|
coordinates: coordinates
|
29
29
|
}
|
30
|
+
h[:crs] = crs if crs
|
30
31
|
h[:bbox] = bbox if Hash === args.last and args.last[:include_bbox]
|
31
32
|
h
|
32
33
|
end
|
@@ -4,12 +4,18 @@ module Terraformer
|
|
4
4
|
|
5
5
|
def initialize *args
|
6
6
|
case
|
7
|
+
|
8
|
+
# arg is an array of arrays of polygon, holes
|
9
|
+
when Array === args[0] && Array === args[0][0] && Array === args[0][0][0] && Array === args[0][0][0][0]
|
10
|
+
self.coordinates = Coordinate.from(*args)
|
11
|
+
|
7
12
|
when Coordinate === args[0] # only one
|
8
13
|
self.coordinates = [[Coordinate.from_array(args)]]
|
9
14
|
when Array === args[0] # multiple?
|
10
15
|
self.coordinates = [Coordinate.from(args)]
|
11
16
|
when Polygon === args[0]
|
12
17
|
self.coordinates = args.map &:coordinates
|
18
|
+
|
13
19
|
else
|
14
20
|
super *args
|
15
21
|
end
|
@@ -26,10 +32,10 @@ module Terraformer
|
|
26
32
|
def == obj
|
27
33
|
super obj do |o|
|
28
34
|
equal = true
|
29
|
-
ps = polygons
|
30
|
-
ops = o.polygons
|
35
|
+
ps = polygons
|
36
|
+
ops = o.polygons
|
31
37
|
ps.each_with_index do |p, i|
|
32
|
-
equal = p == ops[i]
|
38
|
+
equal = p == ops[i] rescue false
|
33
39
|
break unless equal
|
34
40
|
end
|
35
41
|
equal
|
data/lib/terraformer/polygon.rb
CHANGED
@@ -4,10 +4,19 @@ module Terraformer
|
|
4
4
|
|
5
5
|
def initialize *args
|
6
6
|
case
|
7
|
-
|
7
|
+
|
8
|
+
# each arg is a position of the polygon
|
9
|
+
when Coordinate === args[0] || (Array === args[0] && Numeric === args[0][0])
|
8
10
|
self.coordinates = [Coordinate.from_array(args)]
|
9
|
-
|
11
|
+
|
12
|
+
# each arg is an array of positions; first is polygon, rest are "holes"
|
13
|
+
when Array === args[0] && Array === args[0][0] && Numeric === args[0][0][0]
|
10
14
|
self.coordinates = Coordinate.from args
|
15
|
+
|
16
|
+
# arg is an array of polygon, holes
|
17
|
+
when Array === args[0] && Array === args[0][0] && Array === args[0][0][0]
|
18
|
+
self.coordinates = Coordinate.from *args
|
19
|
+
|
11
20
|
else
|
12
21
|
super *args
|
13
22
|
end
|
@@ -33,13 +42,18 @@ module Terraformer
|
|
33
42
|
# first check outer polygon
|
34
43
|
equal = self.coordinates[0].polygonally_equal_to? obj.coordinates[0]
|
35
44
|
|
36
|
-
|
37
45
|
# then inner polygons (holes)
|
38
46
|
#
|
39
|
-
if equal
|
40
|
-
|
41
|
-
|
42
|
-
|
47
|
+
if equal
|
48
|
+
if self.coordinates.length == obj.coordinates.length and obj.coordinates.length > 1
|
49
|
+
|
50
|
+
self_holes = self.coordinates[1..-1].sort
|
51
|
+
obj_holes = obj.coordinates[1..-1].sort
|
52
|
+
|
53
|
+
self_holes.each_with_index do |hole, idx|
|
54
|
+
equal = hole.polygonally_equal_to? obj_holes[idx]
|
55
|
+
break unless equal
|
56
|
+
end
|
43
57
|
end
|
44
58
|
end
|
45
59
|
|
data/lib/terraformer/version.rb
CHANGED
data/test/arcgis_spec.rb
ADDED
@@ -0,0 +1,899 @@
|
|
1
|
+
require_relative './helper'
|
2
|
+
|
3
|
+
describe Terraformer::ArcGIS do
|
4
|
+
|
5
|
+
describe 'geometry decompressor' do
|
6
|
+
|
7
|
+
it 'decompresses geometries' do
|
8
|
+
compressed = "+1m91-6fl6e+202gc+0+0"
|
9
|
+
decompressed_points = [
|
10
|
+
[-122.41946568318791, 37.775011244040655],
|
11
|
+
[-122.41946568318791, 37.775011244040655]
|
12
|
+
]
|
13
|
+
Terraformer::ArcGIS.decompress_geometry(compressed).must_equal decompressed_points
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'close_ring' do
|
19
|
+
|
20
|
+
let(:closed_ring) {[
|
21
|
+
[-107.5341796875,46.195042108660154],
|
22
|
+
[-105.84228515625,46.58906908309182],
|
23
|
+
[-104.7216796875,45.85941212790755],
|
24
|
+
[-104.52392578125,44.213709909702054],
|
25
|
+
[-106.083984375,43.46886761482923],
|
26
|
+
[-107.8857421875,43.77109381775648],
|
27
|
+
[-109.2919921875,44.99588261816546],
|
28
|
+
[-107.5341796875,46.195042108660154]
|
29
|
+
]
|
30
|
+
}
|
31
|
+
let(:open_ring) {[
|
32
|
+
[-107.5341796875,46.195042108660154],
|
33
|
+
[-105.84228515625,46.58906908309182],
|
34
|
+
[-104.7216796875,45.85941212790755],
|
35
|
+
[-104.52392578125,44.213709909702054],
|
36
|
+
[-106.083984375,43.46886761482923],
|
37
|
+
[-107.8857421875,43.77109381775648],
|
38
|
+
[-109.2919921875,44.99588261816546]
|
39
|
+
]
|
40
|
+
}
|
41
|
+
|
42
|
+
it 'closes open rings' do
|
43
|
+
r = Terraformer::ArcGIS.close_ring open_ring
|
44
|
+
r.must_equal closed_ring
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'does nothing with closed rings' do
|
48
|
+
r = Terraformer::ArcGIS.close_ring closed_ring
|
49
|
+
r.must_equal closed_ring
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'clockwise_ring?' do
|
55
|
+
|
56
|
+
let(:cw_ring) {[
|
57
|
+
[-107.5341796875,46.195042108660154],
|
58
|
+
[-105.84228515625,46.58906908309182],
|
59
|
+
[-104.7216796875,45.85941212790755],
|
60
|
+
[-104.52392578125,44.213709909702054],
|
61
|
+
[-106.083984375,43.46886761482923],
|
62
|
+
[-107.8857421875,43.77109381775648],
|
63
|
+
[-109.2919921875,44.99588261816546],
|
64
|
+
[-107.5341796875,46.195042108660154]
|
65
|
+
]
|
66
|
+
}
|
67
|
+
let(:ccw_ring) {[
|
68
|
+
[-107.5341796875,46.195042108660154],
|
69
|
+
[-109.2919921875,44.99588261816546],
|
70
|
+
[-107.8857421875,43.77109381775648],
|
71
|
+
[-106.083984375,43.46886761482923],
|
72
|
+
[-104.52392578125,44.213709909702054],
|
73
|
+
[-104.7216796875,45.85941212790755],
|
74
|
+
[-105.84228515625,46.58906908309182],
|
75
|
+
[-107.5341796875,46.195042108660154]
|
76
|
+
]
|
77
|
+
}
|
78
|
+
|
79
|
+
it 'is true for rings that are clockwise' do
|
80
|
+
assert Terraformer::ArcGIS.clockwise?(cw_ring)
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'is false for rings that are counter-clockwise' do
|
84
|
+
assert !Terraformer::ArcGIS.clockwise?(ccw_ring)
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
describe 'parse' do
|
90
|
+
|
91
|
+
def must_parse json, expected_class, *expected_init_data
|
92
|
+
if block_given?
|
93
|
+
output = if Hash === expected_init_data[0]
|
94
|
+
Terraformer::ArcGIS.parse json, expected_init_data[0]
|
95
|
+
else
|
96
|
+
Terraformer::ArcGIS.parse json
|
97
|
+
end
|
98
|
+
output.must_be_instance_of expected_class
|
99
|
+
output.must_equal yield(output)
|
100
|
+
else
|
101
|
+
output = Terraformer::ArcGIS.parse json
|
102
|
+
output.must_be_instance_of expected_class
|
103
|
+
output.must_equal expected_class.new *expected_init_data
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'parses arcgis points' do
|
108
|
+
must_parse '{
|
109
|
+
"x": -66.796875,
|
110
|
+
"y": 20.0390625,
|
111
|
+
"spatialReference": {
|
112
|
+
"wkid": 4326
|
113
|
+
}
|
114
|
+
}', Terraformer::Point, -66.796875, 20.0390625
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'parses arcgis points with Z' do
|
118
|
+
must_parse '{
|
119
|
+
"x": -66.796875,
|
120
|
+
"y": 20.0390625,
|
121
|
+
"z": 100,
|
122
|
+
"spatialReference": {
|
123
|
+
"wkid": 4326
|
124
|
+
}
|
125
|
+
}', Terraformer::Point, -66.796875, 20.0390625, 100
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'parses null island arcgis' do
|
129
|
+
must_parse '{
|
130
|
+
"x": 0,
|
131
|
+
"y": 0,
|
132
|
+
"spatialReference": {
|
133
|
+
"wkid": 4326
|
134
|
+
}
|
135
|
+
}', Terraformer::Point, 0, 0
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'parses arcgis polyline into linestring' do
|
139
|
+
must_parse '{
|
140
|
+
"paths": [
|
141
|
+
[ [6.6796875,47.8125],[-65.390625,52.3828125],[-52.3828125,42.5390625] ]
|
142
|
+
],
|
143
|
+
"spatialReference": {
|
144
|
+
"wkid": 4326
|
145
|
+
}
|
146
|
+
}', Terraformer::LineString, [
|
147
|
+
[6.6796875,47.8125],[-65.390625,52.3828125],[-52.3828125,42.5390625]
|
148
|
+
]
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'parses arcgis polygon' do
|
152
|
+
must_parse '{
|
153
|
+
"rings": [
|
154
|
+
[ [41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625],[41.8359375,71.015625] ]
|
155
|
+
],
|
156
|
+
"spatialReference": {
|
157
|
+
"wkid": 4326
|
158
|
+
}
|
159
|
+
}', Terraformer::Polygon, [
|
160
|
+
[[41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625],[41.8359375,71.015625]]
|
161
|
+
]
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'closes rings when parsing arcgis polygon' do
|
165
|
+
must_parse '{
|
166
|
+
"rings": [
|
167
|
+
[ [41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625] ]
|
168
|
+
],
|
169
|
+
"spatialReference": {
|
170
|
+
"wkid": 4326
|
171
|
+
}
|
172
|
+
}', Terraformer::Polygon, [
|
173
|
+
[[41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625],[41.8359375,71.015625]]
|
174
|
+
]
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'parses arcgis multipoint' do
|
178
|
+
must_parse '{
|
179
|
+
"points": [ [41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625] ],
|
180
|
+
"spatialReference": {
|
181
|
+
"wkid": 4326
|
182
|
+
}
|
183
|
+
}', Terraformer::MultiPoint, [
|
184
|
+
[41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625]
|
185
|
+
]
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'parses arcgis polyline into multilinestring' do
|
189
|
+
must_parse '{
|
190
|
+
"paths": [
|
191
|
+
[ [41.8359375,71.015625],[56.953125,33.75] ],
|
192
|
+
[ [21.796875,36.5625],[41.8359375,71.015625] ]
|
193
|
+
],
|
194
|
+
"spatialReference": {
|
195
|
+
"wkid": 4326
|
196
|
+
}
|
197
|
+
}', Terraformer::MultiLineString, [
|
198
|
+
[[41.8359375,71.015625],[56.953125,33.75] ],
|
199
|
+
[[21.796875,36.5625],[41.8359375,71.015625]]
|
200
|
+
]
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'parses arcgis polygon into multipolygon' do
|
204
|
+
must_parse '{
|
205
|
+
"rings":[
|
206
|
+
[[-122.63,45.52],[-122.57,45.53],[-122.52,45.50],[-122.49,45.48],[-122.64,45.49],[-122.63,45.52],[-122.63,45.52]],
|
207
|
+
[[-83,35],[-74,35],[-74,41],[-83,41],[-83,35]]
|
208
|
+
],
|
209
|
+
"spatialReference": {
|
210
|
+
"wkid":4326
|
211
|
+
}
|
212
|
+
}', Terraformer::MultiPolygon,[
|
213
|
+
[[[-122.63,45.52],[-122.57,45.53],[-122.52,45.5],[-122.49,45.48],[-122.64,45.49],[-122.63,45.52],[-122.63,45.52]]],
|
214
|
+
[[[-83,35],[-83,41],[-74,41],[-74,35],[-83,35]]]
|
215
|
+
]
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'strips invalid rings when parsing arcgis polygon' do
|
219
|
+
must_parse '{
|
220
|
+
"rings":[
|
221
|
+
[[-122.63,45.52],[-122.57,45.53],[-122.52,45.50],[-122.49,45.48],[-122.64,45.49],
|
222
|
+
[-122.63,45.52],[-122.63,45.52]],
|
223
|
+
[[-83,35],[-74,35],[-83,35]] // closed but too small
|
224
|
+
],
|
225
|
+
"spatialReference": {
|
226
|
+
"wkid":4326
|
227
|
+
}
|
228
|
+
}', Terraformer::Polygon, [[[-122.63,45.52],[-122.57,45.53],[-122.52,45.5],[-122.49,45.48],[-122.64,45.49],[-122.63,45.52],[-122.63,45.52]]]
|
229
|
+
end
|
230
|
+
|
231
|
+
it 'closes rings when parsing arcgis polygon' do
|
232
|
+
must_parse '{
|
233
|
+
"rings":[
|
234
|
+
[[-122.63,45.52],[-122.57,45.53],[-122.52,45.50],[-122.49,45.48],[-122.64,45.49]],
|
235
|
+
[[-83,35],[-74,35],[-74,41],[-83,41]]
|
236
|
+
],
|
237
|
+
"spatialReference": {
|
238
|
+
"wkid":4326
|
239
|
+
}
|
240
|
+
}', Terraformer::MultiPolygon, [
|
241
|
+
[
|
242
|
+
[[-122.63,45.52],[-122.57,45.53],[-122.52,45.5],[-122.49,45.48],[-122.64,45.49],[-122.63,45.52]]
|
243
|
+
],
|
244
|
+
[
|
245
|
+
[[-83,35],[-83,41],[-74,41],[-74,35],[-83,35]]
|
246
|
+
]
|
247
|
+
]
|
248
|
+
end
|
249
|
+
|
250
|
+
it 'parses arcgis multipolygon with holes' do
|
251
|
+
must_parse '{
|
252
|
+
"type":"polygon",
|
253
|
+
"rings":[
|
254
|
+
[
|
255
|
+
[-100.74462180954974,39.95017165502381],
|
256
|
+
[-94.50439384003792,39.91647453608879],
|
257
|
+
[-94.41650267263967,34.89313438177965],
|
258
|
+
[-100.78856739324887,34.85708140996771],
|
259
|
+
[-100.74462180954974,39.95017165502381]
|
260
|
+
],
|
261
|
+
[
|
262
|
+
[-99.68993678392353,39.341088433448896],
|
263
|
+
[-99.68993678392353,38.24507658785885],
|
264
|
+
[-98.67919734199646,37.86444431771113],
|
265
|
+
[-98.06395917020868,38.210554846669694],
|
266
|
+
[-98.06395917020868,39.341088433448896],
|
267
|
+
[-99.68993678392353,39.341088433448896]
|
268
|
+
],
|
269
|
+
[
|
270
|
+
[-96.83349180978595,37.23732027507514],
|
271
|
+
[-97.31689323047635,35.967330282988534],
|
272
|
+
[-96.5698183075912,35.57512048069255],
|
273
|
+
[-95.42724211456674,36.357601429255965],
|
274
|
+
[-96.83349180978595,37.23732027507514]
|
275
|
+
],
|
276
|
+
[
|
277
|
+
[-101.4916967324349,38.24507658785885],
|
278
|
+
[-101.44775114873578,36.073960493943744],
|
279
|
+
[-103.95263145328033,36.03843312329154],
|
280
|
+
[-103.68895795108557,38.03770050767439],
|
281
|
+
[-101.4916967324349,38.24507658785885]
|
282
|
+
]
|
283
|
+
],
|
284
|
+
"spatialReference":{
|
285
|
+
"wkid":4326
|
286
|
+
}
|
287
|
+
}', Terraformer::MultiPolygon, [
|
288
|
+
[
|
289
|
+
[
|
290
|
+
[-100.74462180954974, 39.95017165502381],
|
291
|
+
[-94.50439384003792, 39.91647453608879],
|
292
|
+
[-94.41650267263967, 34.89313438177965],
|
293
|
+
[-100.78856739324887, 34.85708140996771],
|
294
|
+
[-100.74462180954974, 39.95017165502381]
|
295
|
+
],
|
296
|
+
[
|
297
|
+
[-96.83349180978595, 37.23732027507514],
|
298
|
+
[-97.31689323047635, 35.967330282988534],
|
299
|
+
[-96.5698183075912, 35.57512048069255],
|
300
|
+
[-95.42724211456674, 36.357601429255965],
|
301
|
+
[-96.83349180978595, 37.23732027507514]
|
302
|
+
],
|
303
|
+
[
|
304
|
+
[-99.68993678392353, 39.341088433448896],
|
305
|
+
[-99.68993678392353, 38.24507658785885],
|
306
|
+
[-98.67919734199646, 37.86444431771113],
|
307
|
+
[-98.06395917020868, 38.210554846669694],
|
308
|
+
[-98.06395917020868, 39.341088433448896],
|
309
|
+
[-99.68993678392353, 39.341088433448896]
|
310
|
+
]
|
311
|
+
],
|
312
|
+
[
|
313
|
+
[
|
314
|
+
[-101.4916967324349, 38.24507658785885],
|
315
|
+
[-101.44775114873578, 36.073960493943744],
|
316
|
+
[-103.95263145328033, 36.03843312329154],
|
317
|
+
[-103.68895795108557, 38.03770050767439],
|
318
|
+
[-101.4916967324349, 38.24507658785885]
|
319
|
+
]
|
320
|
+
]
|
321
|
+
]
|
322
|
+
end
|
323
|
+
|
324
|
+
it 'parses arcgis features' do
|
325
|
+
must_parse '{
|
326
|
+
"geometry": {
|
327
|
+
"rings": [
|
328
|
+
[ [41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625],[41.8359375,71.015625] ]
|
329
|
+
],
|
330
|
+
"spatialReference": {
|
331
|
+
"wkid": 4326
|
332
|
+
}
|
333
|
+
},
|
334
|
+
"attributes": {
|
335
|
+
"foo": "bar"
|
336
|
+
}
|
337
|
+
}', Terraformer::Feature do |output|
|
338
|
+
p = Terraformer::Polygon.new [[
|
339
|
+
[41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625],[41.8359375,71.015625]
|
340
|
+
]]
|
341
|
+
output.geometry.must_equal p
|
342
|
+
f = p.to_feature
|
343
|
+
f.properties['foo'] = 'bar'
|
344
|
+
f.id = nil
|
345
|
+
f
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
it 'parses arcgis features with objectid' do
|
350
|
+
must_parse '{
|
351
|
+
"geometry": {
|
352
|
+
"rings": [
|
353
|
+
[ [41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625],[41.8359375,71.015625] ]
|
354
|
+
],
|
355
|
+
"spatialReference": {
|
356
|
+
"wkid": 4326
|
357
|
+
}
|
358
|
+
},
|
359
|
+
"attributes": {
|
360
|
+
"OBJECTID": 123
|
361
|
+
}
|
362
|
+
}', Terraformer::Feature do |output|
|
363
|
+
p = Terraformer::Polygon.new [[
|
364
|
+
[41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625],[41.8359375,71.015625]
|
365
|
+
]]
|
366
|
+
output.geometry.must_equal p
|
367
|
+
f = p.to_feature
|
368
|
+
f.id = 123
|
369
|
+
f
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
it 'parses arcgis features with fid' do
|
374
|
+
must_parse '{
|
375
|
+
"geometry": {
|
376
|
+
"rings": [
|
377
|
+
[ [41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625],[41.8359375,71.015625] ]
|
378
|
+
],
|
379
|
+
"spatialReference": {
|
380
|
+
"wkid": 4326
|
381
|
+
}
|
382
|
+
},
|
383
|
+
"attributes": {
|
384
|
+
"FID": 123
|
385
|
+
}
|
386
|
+
}', Terraformer::Feature do |output|
|
387
|
+
p = Terraformer::Polygon.new [[
|
388
|
+
[41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625],[41.8359375,71.015625]
|
389
|
+
]]
|
390
|
+
output.geometry.must_equal p
|
391
|
+
f = p.to_feature
|
392
|
+
f.id = 123
|
393
|
+
f
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
it 'parses arcgis features with custom id' do
|
398
|
+
must_parse '{
|
399
|
+
"geometry": {
|
400
|
+
"rings": [
|
401
|
+
[ [41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625],[41.8359375,71.015625] ]
|
402
|
+
],
|
403
|
+
"spatialReference": {
|
404
|
+
"wkid": 4326
|
405
|
+
}
|
406
|
+
},
|
407
|
+
"attributes": {
|
408
|
+
"FooId": 123
|
409
|
+
}
|
410
|
+
}', Terraformer::Feature, {id_attribute: 'FooId'} do |output|
|
411
|
+
p = Terraformer::Polygon.new [[
|
412
|
+
[41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625],[41.8359375,71.015625]
|
413
|
+
]]
|
414
|
+
output.geometry.must_equal p
|
415
|
+
f = p.to_feature
|
416
|
+
f.id = 123
|
417
|
+
f
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
it 'parses arcgis features with empty attributes' do
|
422
|
+
must_parse '{
|
423
|
+
"geometry": {
|
424
|
+
"rings": [
|
425
|
+
[ [41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625],[41.8359375,71.015625] ]
|
426
|
+
],
|
427
|
+
"spatialReference": {
|
428
|
+
"wkid": 4326
|
429
|
+
}
|
430
|
+
},
|
431
|
+
"attributes": {}
|
432
|
+
}', Terraformer::Feature do |output|
|
433
|
+
p = Terraformer::Polygon.new [[
|
434
|
+
[41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625],[41.8359375,71.015625]
|
435
|
+
]]
|
436
|
+
output.geometry.must_equal p
|
437
|
+
f = p.to_feature
|
438
|
+
f.id = nil
|
439
|
+
f
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
it 'parses arcgis features with no attributes' do
|
444
|
+
must_parse '{
|
445
|
+
"geometry": {
|
446
|
+
"rings": [
|
447
|
+
[ [41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625],[41.8359375,71.015625] ]
|
448
|
+
],
|
449
|
+
"spatialReference": {
|
450
|
+
"wkid": 4326
|
451
|
+
}
|
452
|
+
}
|
453
|
+
}', Terraformer::Feature do |output|
|
454
|
+
p = Terraformer::Polygon.new [[
|
455
|
+
[41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625],[41.8359375,71.015625]
|
456
|
+
]]
|
457
|
+
output.geometry.must_equal p
|
458
|
+
f = p.to_feature
|
459
|
+
f.id = nil
|
460
|
+
f
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
464
|
+
it 'parses arcgis features with no geometry' do
|
465
|
+
must_parse '{
|
466
|
+
"attributes": {
|
467
|
+
"foo": "bar"
|
468
|
+
}
|
469
|
+
}', Terraformer::Feature do |output|
|
470
|
+
f = Terraformer::Feature.new
|
471
|
+
f.properties = {'foo' => 'bar'}
|
472
|
+
f.id = nil
|
473
|
+
f
|
474
|
+
end
|
475
|
+
end
|
476
|
+
|
477
|
+
it 'parses arcgis geometry in web mercator' do
|
478
|
+
must_parse '{
|
479
|
+
"x": -13580977.876779145,
|
480
|
+
"y": 5621521.486191948,
|
481
|
+
"spatialReference": {
|
482
|
+
"wkid": 102100
|
483
|
+
}
|
484
|
+
}', Terraformer::Point, [-121.999999999998, 44.99999999999942]
|
485
|
+
end
|
486
|
+
|
487
|
+
it 'does not modify arcgis data while parsing' do
|
488
|
+
input = {
|
489
|
+
"geometry" => {
|
490
|
+
"rings" => [
|
491
|
+
[ [41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625],[41.8359375,71.015625] ]
|
492
|
+
],
|
493
|
+
"spatialReference" => {
|
494
|
+
"wkid" => 4326
|
495
|
+
}
|
496
|
+
},
|
497
|
+
"attributes" => {
|
498
|
+
"foo" => "bar"
|
499
|
+
}
|
500
|
+
}
|
501
|
+
original = input.clone
|
502
|
+
Terraformer::ArcGIS.parse input
|
503
|
+
original.must_equal input
|
504
|
+
end
|
505
|
+
|
506
|
+
it 'decompresses arcgis compressed geometry' do
|
507
|
+
must_parse '{
|
508
|
+
"compressedGeometry": "+1m91-66os4+1poms+1+91+3+3j"
|
509
|
+
}', Terraformer::Feature do |output|
|
510
|
+
ls = Terraformer::LineString.new [
|
511
|
+
[-117.1816137447153, 34.057461545380946],[-117.18159575425025, 34.06266078978142], [-117.18154178285509, 34.06472969326257]
|
512
|
+
]
|
513
|
+
output.geometry.must_equal ls
|
514
|
+
f = ls.to_feature
|
515
|
+
f
|
516
|
+
end
|
517
|
+
end
|
518
|
+
|
519
|
+
end
|
520
|
+
|
521
|
+
describe 'flatten_multi_polygon_rings' do
|
522
|
+
|
523
|
+
it 'flattens geojson polygons into oriented rings' do
|
524
|
+
Terraformer::ArcGIS.flatten_multi_polygon_rings([
|
525
|
+
[
|
526
|
+
[ [102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0] ]
|
527
|
+
],
|
528
|
+
[
|
529
|
+
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]
|
530
|
+
]
|
531
|
+
]
|
532
|
+
).must_equal [
|
533
|
+
[ [102, 2], [102, 3], [103, 3], [103, 2], [102, 2] ],
|
534
|
+
[ [100, 0], [100, 1], [101, 1], [101, 0], [100, 0] ]
|
535
|
+
]
|
536
|
+
end
|
537
|
+
|
538
|
+
end
|
539
|
+
|
540
|
+
describe 'convert' do
|
541
|
+
|
542
|
+
def must_convert json, expected, opts = {}
|
543
|
+
JSON.parse(Terraformer::ArcGIS.convert(json, opts).to_json).must_equal JSON.parse(expected.to_json)
|
544
|
+
end
|
545
|
+
|
546
|
+
it 'converts geojson point' do
|
547
|
+
must_convert '{
|
548
|
+
"type": "Point",
|
549
|
+
"coordinates": [-58.7109375, 47.4609375]
|
550
|
+
}', {
|
551
|
+
x: -58.7109375,
|
552
|
+
y: 47.4609375,
|
553
|
+
spatialReference: {
|
554
|
+
wkid: 4326
|
555
|
+
}
|
556
|
+
}
|
557
|
+
end
|
558
|
+
|
559
|
+
it 'converts geojson point with z' do
|
560
|
+
must_convert '{
|
561
|
+
"type": "Point",
|
562
|
+
"coordinates": [-58.7109375, 47.4609375, 100]
|
563
|
+
}', {
|
564
|
+
x: -58.7109375,
|
565
|
+
y: 47.4609375,
|
566
|
+
z: 100,
|
567
|
+
spatialReference: {
|
568
|
+
wkid: 4326
|
569
|
+
}
|
570
|
+
}
|
571
|
+
end
|
572
|
+
|
573
|
+
it 'converts geojson point at null island' do
|
574
|
+
must_convert '{
|
575
|
+
"type": "Point",
|
576
|
+
"coordinates": [0, 0]
|
577
|
+
}', {
|
578
|
+
x: 0,
|
579
|
+
y: 0,
|
580
|
+
spatialReference: {
|
581
|
+
wkid: 4326
|
582
|
+
}
|
583
|
+
}
|
584
|
+
end
|
585
|
+
|
586
|
+
it 'converts geojson linestring' do
|
587
|
+
must_convert '{
|
588
|
+
"type": "LineString",
|
589
|
+
"coordinates": [ [21.4453125,-14.0625],[33.3984375,-20.7421875],[38.3203125,-24.609375] ]
|
590
|
+
}', {
|
591
|
+
paths:[
|
592
|
+
[ [21.4453125,-14.0625],[33.3984375,-20.7421875],[38.3203125,-24.609375] ]
|
593
|
+
],
|
594
|
+
spatialReference: {
|
595
|
+
wkid: 4326
|
596
|
+
}
|
597
|
+
}
|
598
|
+
end
|
599
|
+
|
600
|
+
it 'converts geojson polygon' do
|
601
|
+
must_convert '{
|
602
|
+
"type": "Polygon",
|
603
|
+
"coordinates": [
|
604
|
+
[ [41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625],[41.8359375,71.015625] ]
|
605
|
+
]
|
606
|
+
}', {
|
607
|
+
rings:[
|
608
|
+
[ [41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625],[41.8359375,71.015625] ]
|
609
|
+
],
|
610
|
+
spatialReference: {
|
611
|
+
wkid: 4326
|
612
|
+
}
|
613
|
+
}
|
614
|
+
end
|
615
|
+
|
616
|
+
it 'converts geojson polygon with hole' do
|
617
|
+
must_convert '{
|
618
|
+
"type": "Polygon",
|
619
|
+
"coordinates": [
|
620
|
+
[ [100.0,0.0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0] ],
|
621
|
+
[ [100.2,0.2],[100.8,0.2],[100.8,0.8],[100.2,0.8],[100.2,0.2] ]
|
622
|
+
]
|
623
|
+
}', {
|
624
|
+
rings: [
|
625
|
+
[ [100.0, 0.0], [100.0, 1.0], [101.0, 1.0], [101.0, 0.0], [100.0, 0.0] ],
|
626
|
+
[ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ]
|
627
|
+
],
|
628
|
+
spatialReference: {
|
629
|
+
wkid: 4326
|
630
|
+
}
|
631
|
+
}
|
632
|
+
end
|
633
|
+
|
634
|
+
it 'converts geojson multipoint' do
|
635
|
+
must_convert '{
|
636
|
+
"type": "MultiPoint",
|
637
|
+
"coordinates": [ [41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625] ]
|
638
|
+
}', {
|
639
|
+
points: [ [41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625] ],
|
640
|
+
spatialReference: {
|
641
|
+
wkid: 4326
|
642
|
+
}
|
643
|
+
}
|
644
|
+
end
|
645
|
+
|
646
|
+
it 'converts geojson multilinestring' do
|
647
|
+
must_convert '{
|
648
|
+
"type": "MultiLineString",
|
649
|
+
"coordinates": [
|
650
|
+
[ [41.8359375,71.015625],[56.953125,33.75] ],
|
651
|
+
[ [21.796875,36.5625],[47.8359375,71.015625] ]
|
652
|
+
]
|
653
|
+
}', {
|
654
|
+
paths: [
|
655
|
+
[ [41.8359375,71.015625],[56.953125,33.75] ],
|
656
|
+
[ [21.796875,36.5625],[47.8359375,71.015625] ]
|
657
|
+
],
|
658
|
+
spatialReference: {
|
659
|
+
wkid: 4326
|
660
|
+
}
|
661
|
+
}
|
662
|
+
end
|
663
|
+
|
664
|
+
it 'converts geojson multipolygon' do
|
665
|
+
must_convert '{
|
666
|
+
"type": "MultiPolygon",
|
667
|
+
"coordinates": [
|
668
|
+
[
|
669
|
+
[ [102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0] ]
|
670
|
+
],
|
671
|
+
[
|
672
|
+
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]
|
673
|
+
]
|
674
|
+
]
|
675
|
+
}', {
|
676
|
+
rings:[
|
677
|
+
[ [102, 2], [102, 3], [103, 3], [103, 2], [102, 2] ],
|
678
|
+
[ [100, 0], [100, 1], [101, 1], [101, 0], [100, 0] ]
|
679
|
+
],
|
680
|
+
spatialReference: {
|
681
|
+
wkid:4326
|
682
|
+
}
|
683
|
+
}
|
684
|
+
end
|
685
|
+
|
686
|
+
it 'converts geojson multipolygon with holes' do
|
687
|
+
must_convert '{
|
688
|
+
"type": "MultiPolygon",
|
689
|
+
"coordinates": [
|
690
|
+
[
|
691
|
+
[ [102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0] ]
|
692
|
+
],
|
693
|
+
[
|
694
|
+
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ],
|
695
|
+
[ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ]
|
696
|
+
]
|
697
|
+
]
|
698
|
+
}', {
|
699
|
+
rings: [
|
700
|
+
[ [102,2],[102,3],[103,3],[103,2],[102,2] ],
|
701
|
+
[ [100.2,0.2],[100.8,0.2],[100.8,0.8],[100.2,0.8],[100.2,0.2] ],
|
702
|
+
[ [100,0],[100,1],[101,1],[101,0],[100,0] ]
|
703
|
+
],
|
704
|
+
spatialReference: {
|
705
|
+
wkid: 4326
|
706
|
+
}
|
707
|
+
}
|
708
|
+
end
|
709
|
+
|
710
|
+
it 'converts geojson feature' do
|
711
|
+
must_convert '{
|
712
|
+
"type":"Feature",
|
713
|
+
"id": "foo",
|
714
|
+
"geometry": {
|
715
|
+
"type": "Polygon",
|
716
|
+
"coordinates": [
|
717
|
+
[ [41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625],[41.8359375,71.015625] ]
|
718
|
+
]
|
719
|
+
},
|
720
|
+
"properties": {
|
721
|
+
"foo":"bar"
|
722
|
+
}
|
723
|
+
}', {
|
724
|
+
geometry:{
|
725
|
+
rings:[
|
726
|
+
[ [41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625],[41.8359375,71.015625] ]
|
727
|
+
],
|
728
|
+
spatialReference:{
|
729
|
+
wkid:4326
|
730
|
+
}
|
731
|
+
},
|
732
|
+
attributes: {
|
733
|
+
foo: "bar",
|
734
|
+
OBJECTID: "foo"
|
735
|
+
}
|
736
|
+
}
|
737
|
+
end
|
738
|
+
|
739
|
+
it 'converts geojson feature with custom id' do
|
740
|
+
must_convert '{
|
741
|
+
"type":"Feature",
|
742
|
+
"id": "foo",
|
743
|
+
"geometry": {
|
744
|
+
"type": "Polygon",
|
745
|
+
"coordinates": [
|
746
|
+
[ [41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625],[41.8359375,71.015625] ]
|
747
|
+
]
|
748
|
+
},
|
749
|
+
"properties": {
|
750
|
+
"foo":"bar"
|
751
|
+
}
|
752
|
+
}', {
|
753
|
+
geometry:{
|
754
|
+
rings:[
|
755
|
+
[ [41.8359375,71.015625],[56.953125,33.75],[21.796875,36.5625],[41.8359375,71.015625] ]
|
756
|
+
],
|
757
|
+
spatialReference:{
|
758
|
+
wkid:4326
|
759
|
+
}
|
760
|
+
},
|
761
|
+
attributes: {
|
762
|
+
foo:"bar",
|
763
|
+
myId: "foo"
|
764
|
+
}
|
765
|
+
|
766
|
+
}, id_attribute: 'myId'
|
767
|
+
end
|
768
|
+
|
769
|
+
it 'converts geojson feature with no geometry or properties' do
|
770
|
+
must_convert '{
|
771
|
+
"type":"Feature",
|
772
|
+
"id": "foo",
|
773
|
+
"geometry": null,
|
774
|
+
"properties": null
|
775
|
+
}', {
|
776
|
+
attributes: {
|
777
|
+
OBJECTID: "foo"
|
778
|
+
}
|
779
|
+
}
|
780
|
+
end
|
781
|
+
|
782
|
+
it 'converts geojson feature collections' do
|
783
|
+
must_convert '{
|
784
|
+
"type": "FeatureCollection",
|
785
|
+
"features": [{
|
786
|
+
"type": "Feature",
|
787
|
+
"geometry": {
|
788
|
+
"type": "Point",
|
789
|
+
"coordinates": [102.0, 0.5]
|
790
|
+
},
|
791
|
+
"properties": {
|
792
|
+
"prop0": "value0"
|
793
|
+
}
|
794
|
+
}, {
|
795
|
+
"type": "Feature",
|
796
|
+
"geometry": {
|
797
|
+
"type": "LineString",
|
798
|
+
"coordinates": [
|
799
|
+
[102.0, 0.0],[103.0, 1.0],[104.0, 0.0],[105.0, 1.0]
|
800
|
+
]
|
801
|
+
},
|
802
|
+
"properties": {
|
803
|
+
"prop0": "value0"
|
804
|
+
}
|
805
|
+
}, {
|
806
|
+
"type": "Feature",
|
807
|
+
"geometry": {
|
808
|
+
"type": "Polygon",
|
809
|
+
"coordinates": [
|
810
|
+
[ [100.0, 0.0],[101.0, 0.0],[101.0, 1.0],[100.0, 1.0],[100.0, 0.0] ]
|
811
|
+
]
|
812
|
+
},
|
813
|
+
"properties": {
|
814
|
+
"prop0": "value0"
|
815
|
+
}
|
816
|
+
}]
|
817
|
+
}', [
|
818
|
+
{
|
819
|
+
geometry: {
|
820
|
+
x: 102.0,
|
821
|
+
y: 0.5,
|
822
|
+
spatialReference: {
|
823
|
+
wkid: 4326
|
824
|
+
}
|
825
|
+
},
|
826
|
+
attributes: {
|
827
|
+
prop0: "value0"
|
828
|
+
}
|
829
|
+
},
|
830
|
+
{
|
831
|
+
geometry: {
|
832
|
+
paths: [
|
833
|
+
[[102.0, 0.0],[103.0, 1.0],[104.0, 0.0],[105.0, 1.0]]
|
834
|
+
],
|
835
|
+
spatialReference: {
|
836
|
+
wkid: 4326
|
837
|
+
}
|
838
|
+
},
|
839
|
+
attributes: {
|
840
|
+
prop0: "value0"
|
841
|
+
}
|
842
|
+
},
|
843
|
+
{
|
844
|
+
geometry: {
|
845
|
+
rings: [
|
846
|
+
[ [100.0,0.0],[100.0,1.0],[101.0,1.0],[101.0,0.0],[100.0,0.0] ]
|
847
|
+
],
|
848
|
+
spatialReference: {
|
849
|
+
wkid: 4326
|
850
|
+
}
|
851
|
+
},
|
852
|
+
attributes: {
|
853
|
+
prop0: "value0"
|
854
|
+
}
|
855
|
+
}
|
856
|
+
]
|
857
|
+
end
|
858
|
+
|
859
|
+
it 'converts geojson geometry collections' do
|
860
|
+
must_convert '{
|
861
|
+
"type" : "GeometryCollection",
|
862
|
+
"geometries" : [{
|
863
|
+
"type" : "Polygon",
|
864
|
+
"coordinates" : [[[-95, 43], [-95, 50], [-90, 50], [-91, 42], [-95, 43]]]
|
865
|
+
}, {
|
866
|
+
"type" : "LineString",
|
867
|
+
"coordinates" : [[-89, 42], [-89, 50], [-80, 50], [-80, 42]]
|
868
|
+
}, {
|
869
|
+
"type" : "Point",
|
870
|
+
"coordinates" : [-94, 46]
|
871
|
+
}]
|
872
|
+
}', [
|
873
|
+
{
|
874
|
+
rings: [
|
875
|
+
[[-95.0, 43.0],[-95.0, 50.0],[-90.0, 50.0],[-91.0, 42.0],[-95.0, 43.0]]
|
876
|
+
],
|
877
|
+
spatialReference: {
|
878
|
+
wkid: 4326
|
879
|
+
}
|
880
|
+
}, {
|
881
|
+
paths: [
|
882
|
+
[[-89.0, 42.0],[-89.0, 50.0],[-80.0, 50.0],[-80.0, 42.0]]
|
883
|
+
],
|
884
|
+
spatialReference: {
|
885
|
+
wkid: 4326
|
886
|
+
}
|
887
|
+
}, {
|
888
|
+
x: -94.0,
|
889
|
+
y: 46.0,
|
890
|
+
spatialReference: {
|
891
|
+
wkid: 4326
|
892
|
+
}
|
893
|
+
}
|
894
|
+
]
|
895
|
+
end
|
896
|
+
|
897
|
+
end
|
898
|
+
|
899
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: terraformer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenichi Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ''
|
14
14
|
email:
|
@@ -17,7 +17,7 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
-
- .gitignore
|
20
|
+
- ".gitignore"
|
21
21
|
- Gemfile
|
22
22
|
- README.md
|
23
23
|
- Rakefile
|
@@ -27,6 +27,7 @@ files:
|
|
27
27
|
- lib/ext/enumerable.rb
|
28
28
|
- lib/ext/hash.rb
|
29
29
|
- lib/terraformer.rb
|
30
|
+
- lib/terraformer/arcgis.rb
|
30
31
|
- lib/terraformer/bounds.rb
|
31
32
|
- lib/terraformer/circle.rb
|
32
33
|
- lib/terraformer/convex_hull.rb
|
@@ -43,6 +44,7 @@ files:
|
|
43
44
|
- lib/terraformer/polygon.rb
|
44
45
|
- lib/terraformer/version.rb
|
45
46
|
- terraformer.gemspec
|
47
|
+
- test/arcgis_spec.rb
|
46
48
|
- test/convex_hull_spec.rb
|
47
49
|
- test/examples/circle.geojson
|
48
50
|
- test/examples/geometry_collection.geojson
|
@@ -69,21 +71,22 @@ require_paths:
|
|
69
71
|
- lib
|
70
72
|
required_ruby_version: !ruby/object:Gem::Requirement
|
71
73
|
requirements:
|
72
|
-
- -
|
74
|
+
- - ">="
|
73
75
|
- !ruby/object:Gem::Version
|
74
76
|
version: '0'
|
75
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
78
|
requirements:
|
77
|
-
- -
|
79
|
+
- - ">="
|
78
80
|
- !ruby/object:Gem::Version
|
79
81
|
version: '0'
|
80
82
|
requirements: []
|
81
83
|
rubyforge_project:
|
82
|
-
rubygems_version: 2.
|
84
|
+
rubygems_version: 2.2.2
|
83
85
|
signing_key:
|
84
86
|
specification_version: 4
|
85
87
|
summary: ''
|
86
88
|
test_files:
|
89
|
+
- test/arcgis_spec.rb
|
87
90
|
- test/convex_hull_spec.rb
|
88
91
|
- test/examples/circle.geojson
|
89
92
|
- test/examples/geometry_collection.geojson
|
@@ -100,4 +103,3 @@ test_files:
|
|
100
103
|
- test/helper.rb
|
101
104
|
- test/primitive_spec.rb
|
102
105
|
- test/terraformer_spec.rb
|
103
|
-
has_rdoc:
|