charta 0.1.14 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/.gitlab-ci.yml +3 -2
- data/charta.gemspec +5 -3
- data/lib/charta.rb +2 -0
- data/lib/charta/bounding_box.rb +4 -0
- data/lib/charta/coordinates.rb +1 -1
- data/lib/charta/geometry.rb +104 -63
- data/lib/charta/point.rb +5 -0
- data/lib/charta/polygon.rb +5 -0
- data/lib/charta/version.rb +1 -1
- metadata +41 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4fbd9a97d2afc3f7fac4856628353c24a686fad2a416c0d12dbb00b448f6d9a4
|
4
|
+
data.tar.gz: '0267836321e3643033bcd873e7672144a37bf0f0b293cd9440a7f01de84a02dc'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76960df71f7e14223da5c28b93dfad64f6ffd563609408cf04eea019afb23c1f7fbeaf3a49775a251152581ac6650a8d9688e7d96230d3aed687cdcb90390eda
|
7
|
+
data.tar.gz: a987c577129ff328b5b8ae574b28dc83ea0a54a308c6e02c0986db53837f06d62429545c48dac75bd5a96b241f98beaaf6d63a5eab3d51ad56abfc31ffac3de3
|
data/.gitignore
CHANGED
data/.gitlab-ci.yml
CHANGED
@@ -2,12 +2,13 @@ stages:
|
|
2
2
|
- test
|
3
3
|
|
4
4
|
test:
|
5
|
-
image: registry.gitlab.com/ekylibre/docker-base-images/ruby2.3:
|
5
|
+
image: registry.gitlab.com/ekylibre/docker-base-images/ruby2.3:1
|
6
6
|
before_script:
|
7
|
+
- gem install bundler
|
7
8
|
- bundle install --path vendor/bundle
|
8
9
|
cache:
|
9
10
|
key: bundle
|
10
11
|
paths:
|
11
12
|
- vendor/bundle
|
12
13
|
script:
|
13
|
-
- bundle exec rake test
|
14
|
+
- bundle exec rake test
|
data/charta.gemspec
CHANGED
@@ -18,10 +18,12 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.require_paths = ['lib']
|
19
19
|
|
20
20
|
spec.add_dependency 'nokogiri', '>= 1.7.0'
|
21
|
-
spec.add_dependency 'rgeo', '~>
|
21
|
+
spec.add_dependency 'rgeo', '~> 1.0'
|
22
22
|
spec.add_dependency 'json', '>= 1.8.0'
|
23
|
-
spec.add_dependency 'rgeo-geojson', '~> 0
|
24
|
-
spec.
|
23
|
+
spec.add_dependency 'rgeo-geojson', '~> 1.0'
|
24
|
+
spec.add_dependency 'rgeo-proj4', '~> 1.0'
|
25
|
+
spec.add_dependency 'activesupport', '~> 5.0'
|
26
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
25
27
|
spec.add_development_dependency 'rake', '~> 10.0'
|
26
28
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
27
29
|
spec.add_development_dependency 'byebug'
|
data/lib/charta.rb
CHANGED
data/lib/charta/bounding_box.rb
CHANGED
data/lib/charta/coordinates.rb
CHANGED
@@ -58,7 +58,7 @@ module Charta
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def map_geometry_collection_coordinates(hash, &block)
|
61
|
-
hash.merge 'geometries' =>
|
61
|
+
hash.merge 'geometries' => hash['geometries'].map { |geometry| map_geometry_coordinates(geometry, &block) }
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
data/lib/charta/geometry.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'rgeo/geo_json'
|
3
3
|
require 'rgeo/svg' # integrated lib for now
|
4
|
+
require 'active_support/core_ext/module/delegation'
|
4
5
|
|
5
6
|
module Charta
|
6
7
|
# Represents a Geometry with SRID
|
@@ -33,16 +34,12 @@ module Charta
|
|
33
34
|
feature.srid.to_i
|
34
35
|
end
|
35
36
|
|
36
|
-
# Returns the underlaying object managed by Charta: the RGeo feature
|
37
|
-
def to_rgeo
|
38
|
-
feature
|
39
|
-
end
|
40
|
-
|
41
37
|
# Returns the Well-Known Text (WKT) representation of the geometry/geography
|
42
38
|
# without SRID metadata
|
43
39
|
def to_text
|
44
40
|
feature.as_text.match(/\ASRID=.*;(.*)/)[1]
|
45
41
|
end
|
42
|
+
|
46
43
|
alias as_text to_text
|
47
44
|
alias to_wkt to_text
|
48
45
|
|
@@ -50,6 +47,7 @@ module Charta
|
|
50
47
|
def to_ewkt
|
51
48
|
Charta.generate_ewkt(feature).to_s
|
52
49
|
end
|
50
|
+
|
53
51
|
alias to_s to_ewkt
|
54
52
|
|
55
53
|
def ewkt
|
@@ -62,6 +60,7 @@ module Charta
|
|
62
60
|
generator = RGeo::WKRep::WKBGenerator.new(tag_format: :ewkbt, emit_ewkbt_srid: true)
|
63
61
|
generator.generate(feature)
|
64
62
|
end
|
63
|
+
|
65
64
|
alias to_ewkb to_binary
|
66
65
|
|
67
66
|
# Pas bien compris le fonctionnement
|
@@ -85,6 +84,7 @@ module Charta
|
|
85
84
|
def to_geojson
|
86
85
|
to_json_object.to_json
|
87
86
|
end
|
87
|
+
|
88
88
|
alias to_json to_geojson
|
89
89
|
|
90
90
|
# Returns object in JSON (Hash)
|
@@ -110,12 +110,24 @@ module Charta
|
|
110
110
|
|
111
111
|
# Returns true if Geometry is a Surface
|
112
112
|
def surface?
|
113
|
-
|
113
|
+
if collection?
|
114
|
+
feature.any? { |geometry| Charta.new_geometry(geometry).surface? }
|
115
|
+
else
|
116
|
+
[RGeo::Feature::Polygon, RGeo::Feature::MultiPolygon].include? feature.geometry_type
|
117
|
+
end
|
114
118
|
end
|
115
119
|
|
116
120
|
# Returns area in unit corresponding to the SRS
|
117
121
|
def area
|
118
|
-
surface?
|
122
|
+
if surface?
|
123
|
+
if collection?
|
124
|
+
feature.sum { |geometry| Charta.new_geometry(geometry).area }
|
125
|
+
else
|
126
|
+
feature.area
|
127
|
+
end
|
128
|
+
else
|
129
|
+
0
|
130
|
+
end
|
119
131
|
end
|
120
132
|
|
121
133
|
# Returns true if this Geometry is an empty geometrycollection, polygon,
|
@@ -123,6 +135,7 @@ module Charta
|
|
123
135
|
def empty?
|
124
136
|
feature.is_empty?
|
125
137
|
end
|
138
|
+
|
126
139
|
alias blank? empty?
|
127
140
|
|
128
141
|
# Computes the geometric center of a geometry, or equivalently, the center
|
@@ -142,10 +155,16 @@ module Charta
|
|
142
155
|
|
143
156
|
def convert_to(new_type)
|
144
157
|
case new_type
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
158
|
+
when type then
|
159
|
+
self
|
160
|
+
when :multi_point then
|
161
|
+
flatten_multi(:point)
|
162
|
+
when :multi_line_string then
|
163
|
+
flatten_multi(:line_string)
|
164
|
+
when :multi_polygon then
|
165
|
+
flatten_multi(:polygon)
|
166
|
+
else
|
167
|
+
self
|
149
168
|
end
|
150
169
|
end
|
151
170
|
|
@@ -196,6 +215,7 @@ module Charta
|
|
196
215
|
other_geometry = Charta.new_geometry(other).transform(srid)
|
197
216
|
feature.union(other_geometry.feature)
|
198
217
|
end
|
218
|
+
|
199
219
|
alias + merge
|
200
220
|
|
201
221
|
def intersection(other)
|
@@ -203,10 +223,16 @@ module Charta
|
|
203
223
|
feature.intersection(other_geometry.feature)
|
204
224
|
end
|
205
225
|
|
226
|
+
def intersects?(other)
|
227
|
+
other_geometry = Charta.new_geometry(other).transform(srid)
|
228
|
+
feature.intersects?(other_geometry.feature)
|
229
|
+
end
|
230
|
+
|
206
231
|
def difference(other)
|
207
232
|
other_geometry = Charta.new_geometry(other).transform(srid)
|
208
233
|
feature.difference(other_geometry.feature)
|
209
234
|
end
|
235
|
+
|
210
236
|
alias - difference
|
211
237
|
|
212
238
|
def bounding_box
|
@@ -231,20 +257,21 @@ module Charta
|
|
231
257
|
Charta.find_srid(name_or_srid)
|
232
258
|
end
|
233
259
|
|
234
|
-
#
|
235
|
-
# serialization in time.
|
260
|
+
# Returns the underlaying object managed by Charta: the RGeo feature
|
236
261
|
def feature
|
237
|
-
|
238
|
-
if @ewkt
|
239
|
-
raise StandardError, 'Invalid geometry (no feature, no EWKT)'
|
240
|
-
else
|
262
|
+
unless defined? @feature
|
263
|
+
if defined? @ewkt
|
241
264
|
@feature = ::Charta::Geometry.from_ewkt(@ewkt)
|
242
265
|
@properties = @options.dup if @options
|
266
|
+
else
|
267
|
+
raise StandardError, 'Invalid geometry (no feature, no EWKT)'
|
243
268
|
end
|
244
269
|
end
|
245
270
|
@feature.dup
|
246
271
|
end
|
247
272
|
|
273
|
+
alias to_rgeo feature
|
274
|
+
|
248
275
|
def feature=(new_feature)
|
249
276
|
raise ArgumentError, "Feature can't be nil" if new_feature.nil?
|
250
277
|
@feature = new_feature
|
@@ -254,6 +281,20 @@ module Charta
|
|
254
281
|
{ type: 'Feature', properties: properties, geometry: to_json_object }
|
255
282
|
end
|
256
283
|
|
284
|
+
def method_missing(name, *args, &block)
|
285
|
+
target = to_rgeo
|
286
|
+
if target.respond_to? name
|
287
|
+
target.send name, *args
|
288
|
+
else
|
289
|
+
raise StandardError.new("Method #{name} does not exist for #{self.class.name}")
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
def respond_to_missing?(name, include_private = false)
|
294
|
+
return false if name == :init_with
|
295
|
+
super
|
296
|
+
end
|
297
|
+
|
257
298
|
class << self
|
258
299
|
def srs_database
|
259
300
|
@srs_database ||= RGeo::CoordSys::SRSDatabase::Proj4Data.new('epsg', authority: 'EPSG', cache: true)
|
@@ -276,7 +317,7 @@ module Charta
|
|
276
317
|
|
277
318
|
def from_ewkt(ewkt)
|
278
319
|
# Cleans empty geometries
|
279
|
-
ewkt.gsub
|
320
|
+
ewkt = ewkt.gsub(/(GEOMETRYCOLLECTION|GEOMETRY|((MULTI)?(POINT|LINESTRING|POLYGON)))\(\)/, '\1 EMPTY')
|
280
321
|
srs = ewkt.split(/[\=\;]+/)[0..1]
|
281
322
|
srid = nil
|
282
323
|
srid = srs[1] if srs[0] =~ /srid/i
|
@@ -288,52 +329,52 @@ module Charta
|
|
288
329
|
|
289
330
|
private
|
290
331
|
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
332
|
+
def geos_factory(srid)
|
333
|
+
RGeo::Geos.factory(
|
334
|
+
srid: srid,
|
335
|
+
wkt_generator: {
|
336
|
+
type_format: :ewkt,
|
337
|
+
emit_ewkt_srid: true,
|
338
|
+
convert_case: :upper
|
339
|
+
},
|
340
|
+
wkt_parser: {
|
341
|
+
support_ewkt: true
|
342
|
+
},
|
343
|
+
wkb_generator: {
|
344
|
+
type_format: :ewkb,
|
345
|
+
emit_ewkb_srid: true,
|
346
|
+
hex_format: true
|
347
|
+
},
|
348
|
+
wkb_parser: {
|
349
|
+
support_ewkb: true
|
350
|
+
}
|
351
|
+
)
|
352
|
+
end
|
312
353
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
354
|
+
def projected_factory(srid)
|
355
|
+
proj4 = '+proj=cea +lon_0=0 +lat_ts=30 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs'
|
356
|
+
RGeo::Geographic.projected_factory(
|
357
|
+
srid: srid,
|
358
|
+
wkt_generator: {
|
359
|
+
type_format: :ewkt,
|
360
|
+
emit_ewkt_srid: true,
|
361
|
+
convert_case: :upper
|
362
|
+
},
|
363
|
+
wkt_parser: {
|
364
|
+
support_ewkt: true
|
365
|
+
},
|
366
|
+
wkb_generator: {
|
367
|
+
type_format: :ewkb,
|
368
|
+
emit_ewkb_srid: true,
|
369
|
+
hex_format: true
|
370
|
+
},
|
371
|
+
wkb_parser: {
|
372
|
+
support_ewkb: true
|
373
|
+
},
|
374
|
+
projection_srid: 6933,
|
375
|
+
projection_proj4: proj4
|
376
|
+
)
|
377
|
+
end
|
337
378
|
end
|
338
379
|
end
|
339
380
|
end
|
data/lib/charta/point.rb
CHANGED
data/lib/charta/polygon.rb
CHANGED
data/lib/charta/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: charta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brice TEXIER
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '1.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: '1.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: json
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,28 +58,56 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0
|
61
|
+
version: '1.0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0
|
68
|
+
version: '1.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rgeo-proj4
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: activesupport
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '5.0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '5.0'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
98
|
name: bundler
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
72
100
|
requirements:
|
73
101
|
- - "~>"
|
74
102
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
103
|
+
version: '2.0'
|
76
104
|
type: :development
|
77
105
|
prerelease: false
|
78
106
|
version_requirements: !ruby/object:Gem::Requirement
|
79
107
|
requirements:
|
80
108
|
- - "~>"
|
81
109
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
110
|
+
version: '2.0'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: rake
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,7 +150,7 @@ dependencies:
|
|
122
150
|
- - ">="
|
123
151
|
- !ruby/object:Gem::Version
|
124
152
|
version: '0'
|
125
|
-
description:
|
153
|
+
description:
|
126
154
|
email:
|
127
155
|
- brice@ekylibre.com
|
128
156
|
executables: []
|
@@ -159,7 +187,7 @@ homepage: https://github.com/ekylibre/charta
|
|
159
187
|
licenses:
|
160
188
|
- MIT
|
161
189
|
metadata: {}
|
162
|
-
post_install_message:
|
190
|
+
post_install_message:
|
163
191
|
rdoc_options: []
|
164
192
|
require_paths:
|
165
193
|
- lib
|
@@ -174,9 +202,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
202
|
- !ruby/object:Gem::Version
|
175
203
|
version: '0'
|
176
204
|
requirements: []
|
177
|
-
|
178
|
-
|
179
|
-
signing_key:
|
205
|
+
rubygems_version: 3.0.3
|
206
|
+
signing_key:
|
180
207
|
specification_version: 4
|
181
208
|
summary: Simple tool over geos and co
|
182
209
|
test_files: []
|