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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3577d17c7733172a8e6d2c13e621872c853b80f4
4
- data.tar.gz: 9c87811e1f18b4a03c4eee424711b50bca955f5f
2
+ SHA256:
3
+ metadata.gz: 4fbd9a97d2afc3f7fac4856628353c24a686fad2a416c0d12dbb00b448f6d9a4
4
+ data.tar.gz: '0267836321e3643033bcd873e7672144a37bf0f0b293cd9440a7f01de84a02dc'
5
5
  SHA512:
6
- metadata.gz: def555154b7633cd1d6e45a0bd302762bd5d27c0c4b6643dad27967493cfcd3246a666b9b72f057224aa1c061ff9b09176adcac8970b19ae4979c1c76a735551
7
- data.tar.gz: 9d7909aab7f4ec0eee6fbd8a3e40c756edd3e6e54ed205d061609c8cd771f4054a57be9210eb09222d4ff12640fb10c2a305df5c772b6bb44dcaf01151c6caa2
6
+ metadata.gz: 76960df71f7e14223da5c28b93dfad64f6ffd563609408cf04eea019afb23c1f7fbeaf3a49775a251152581ac6650a8d9688e7d96230d3aed687cdcb90390eda
7
+ data.tar.gz: a987c577129ff328b5b8ae574b28dc83ea0a54a308c6e02c0986db53837f06d62429545c48dac75bd5a96b241f98beaaf6d63a5eab3d51ad56abfc31ffac3de3
data/.gitignore CHANGED
@@ -9,3 +9,5 @@
9
9
  /spec/reports/
10
10
  /tmp/
11
11
  .byebug_history
12
+ /.idea/
13
+ .ruby-version
@@ -2,12 +2,13 @@ stages:
2
2
  - test
3
3
 
4
4
  test:
5
- image: registry.gitlab.com/ekylibre/docker-base-images/ruby2.3:master
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
@@ -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', '~> 0.6.0'
21
+ spec.add_dependency 'rgeo', '~> 1.0'
22
22
  spec.add_dependency 'json', '>= 1.8.0'
23
- spec.add_dependency 'rgeo-geojson', '~> 0.4.3'
24
- spec.add_development_dependency 'bundler', '~> 1.14'
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'
@@ -3,6 +3,8 @@
3
3
  require 'bigdecimal'
4
4
  require 'bigdecimal/util'
5
5
  require 'rgeo'
6
+ require 'rgeo/proj4'
7
+
6
8
  require 'charta/coordinates'
7
9
  require 'charta/ewkt_serializer'
8
10
  require 'charta/geometry'
@@ -24,5 +24,9 @@ module Charta
24
24
  def to_a
25
25
  [[@y_min, @x_min], [@y_max, @x_max]]
26
26
  end
27
+
28
+ def to_bbox_string
29
+ "#{@x_min}, #{@y_min}, #{x_max}, #{y_max}"
30
+ end
27
31
  end
28
32
  end
@@ -58,7 +58,7 @@ module Charta
58
58
  end
59
59
 
60
60
  def map_geometry_collection_coordinates(hash, &block)
61
- hash.merge 'geometries' => map_geometry_coordinates(hash['geometries'], &block)
61
+ hash.merge 'geometries' => hash['geometries'].map { |geometry| map_geometry_coordinates(geometry, &block) }
62
62
  end
63
63
  end
64
64
  end
@@ -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
- [RGeo::Feature::Polygon, RGeo::Feature::MultiPolygon].include? feature.geometry_type
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? ? feature.area : 0
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
- when type then self
146
- when :multi_point then flatten_multi(:point)
147
- when :multi_line_string then flatten_multi(:line_string)
148
- when :multi_polygon then flatten_multi(:polygon)
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
- # TODO: Manage YAML domain type to ensure maintainability of YAML
235
- # serialization in time.
260
+ # Returns the underlaying object managed by Charta: the RGeo feature
236
261
  def feature
237
- if @feature.nil?
238
- if @ewkt.nil?
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!(/(GEOMETRYCOLLECTION|GEOMETRY|((MULTI)?(POINT|LINESTRING|POLYGON)))\(\)/, '\1 EMPTY')
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
- def geos_factory(srid)
292
- RGeo::Geos.factory(
293
- srid: srid,
294
- wkt_generator: {
295
- type_format: :ewkt,
296
- emit_ewkt_srid: true,
297
- convert_case: :upper
298
- },
299
- wkt_parser: {
300
- support_ewkt: true
301
- },
302
- wkb_generator: {
303
- type_format: :ewkb,
304
- emit_ewkb_srid: true,
305
- hex_format: true
306
- },
307
- wkb_parser: {
308
- support_ewkb: true
309
- }
310
- )
311
- end
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
- def projected_factory(srid)
314
- proj4 = '+proj=cea +lon_0=0 +lat_ts=30 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs'
315
- RGeo::Geographic.projected_factory(
316
- srid: srid,
317
- wkt_generator: {
318
- type_format: :ewkt,
319
- emit_ewkt_srid: true,
320
- convert_case: :upper
321
- },
322
- wkt_parser: {
323
- support_ewkt: true
324
- },
325
- wkb_generator: {
326
- type_format: :ewkb,
327
- emit_ewkb_srid: true,
328
- hex_format: true
329
- },
330
- wkb_parser: {
331
- support_ewkb: true
332
- },
333
- projection_srid: 6933,
334
- projection_proj4: proj4
335
- )
336
- end
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
@@ -10,5 +10,10 @@ module Charta
10
10
  feature.y
11
11
  end
12
12
  alias latitude y
13
+
14
+ def distance(point)
15
+ raise ArgumentError, "wrong type: Charta::Point required" if point.class.name != "Charta::Point"
16
+ to_rgeo.distance(point.to_rgeo)
17
+ end
13
18
  end
14
19
  end
@@ -8,5 +8,10 @@ module Charta
8
8
  end
9
9
  @exterior_ring
10
10
  end
11
+
12
+ def distance(point)
13
+ polygon_centroid = Charta.new_point(*centroid, 4326)
14
+ polygon_centroid.distance(point)
15
+ end
11
16
  end
12
17
  end
@@ -1,3 +1,3 @@
1
1
  module Charta
2
- VERSION = '0.1.14'.freeze
2
+ VERSION = '0.2.3'.freeze
3
3
  end
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.1.14
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: 2019-07-03 00:00:00.000000000 Z
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: 0.6.0
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: 0.6.0
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.4.3
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.4.3
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: '1.14'
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: '1.14'
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
- rubyforge_project:
178
- rubygems_version: 2.6.14
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: []