charta 0.1.13 → 0.1.18

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: f5026ab204ac67b2187e5a338c178009582401ef
4
- data.tar.gz: 07f73034e6c19c9f307b59aa4aecc359767b7544
2
+ SHA256:
3
+ metadata.gz: 305d47070fc660134d7a4bed344db7efb555c9729a30e771af105a263c6aee01
4
+ data.tar.gz: 4cfab59ae1d9f4034eb066bcf05e3a4c49b117604879e3e1e282a50e2c234f64
5
5
  SHA512:
6
- metadata.gz: 9cb51c59524dfb7c022069d805f936282dc143419ec124bcc7d491ae6fe1b692ab397bd377bee875b663564319ad97111748e9db640df71583470bffbf868963
7
- data.tar.gz: 26e4afcc4e8ec23478883923af1313fe91ef64cc071b3892a7d0963bddb9bc00ad2f79b05782725f99cc9f718fd90f634a9421cdbb97456aa4a838498477ab9f
6
+ metadata.gz: 7cc82941e2062fa2309c294dc02b912528faf4a4893b34ee4a719a62ecd77422a1ff97d7c0255246dc4b9b014b2839bff6f7169e38d4be78cbb883d83352c26d
7
+ data.tar.gz: 2193fbd5aa27ddca33cbd4ef3257168d2c567d1b8e4eb3def8ae2bcaed05e22aaeb82e8f6a17640955a7d92ff38835ab2d41a4f7f1e8dd01193db9fdab8dc31d
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
  /spec/reports/
10
10
  /tmp/
11
11
  .byebug_history
12
+ .ruby-version
@@ -2,7 +2,7 @@ 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
7
  - bundle install --path vendor/bundle
8
8
  cache:
@@ -10,4 +10,4 @@ test:
10
10
  paths:
11
11
  - vendor/bundle
12
12
  script:
13
- - bundle exec rake test
13
+ - bundle exec rake test
@@ -1,5 +1,7 @@
1
1
  # Gathers geomatic calculations
2
2
  # Completes RGeo
3
+ require 'bigdecimal'
4
+ require 'bigdecimal/util'
3
5
  require 'rgeo'
4
6
  require 'charta/coordinates'
5
7
  require 'charta/ewkt_serializer'
@@ -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
@@ -20,7 +20,7 @@ module Charta
20
20
 
21
21
  def normalize_4326_geometry(json)
22
22
  map_coordinates json do |(x, y)|
23
- [((x + 180) % 360) - 180, ((y + 90) % 180) - 90]
23
+ [((x + 180.to_d) % 360.to_d) - 180.to_d, ((y + 90.to_d) % 180.to_d) - 90.to_d]
24
24
  end
25
25
  end
26
26
 
@@ -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
@@ -43,6 +43,7 @@ module Charta
43
43
  def to_text
44
44
  feature.as_text.match(/\ASRID=.*;(.*)/)[1]
45
45
  end
46
+
46
47
  alias as_text to_text
47
48
  alias to_wkt to_text
48
49
 
@@ -50,6 +51,7 @@ module Charta
50
51
  def to_ewkt
51
52
  Charta.generate_ewkt(feature).to_s
52
53
  end
54
+
53
55
  alias to_s to_ewkt
54
56
 
55
57
  def ewkt
@@ -62,6 +64,7 @@ module Charta
62
64
  generator = RGeo::WKRep::WKBGenerator.new(tag_format: :ewkbt, emit_ewkbt_srid: true)
63
65
  generator.generate(feature)
64
66
  end
67
+
65
68
  alias to_ewkb to_binary
66
69
 
67
70
  # Pas bien compris le fonctionnement
@@ -85,6 +88,7 @@ module Charta
85
88
  def to_geojson
86
89
  to_json_object.to_json
87
90
  end
91
+
88
92
  alias to_json to_geojson
89
93
 
90
94
  # Returns object in JSON (Hash)
@@ -110,12 +114,24 @@ module Charta
110
114
 
111
115
  # Returns true if Geometry is a Surface
112
116
  def surface?
113
- [RGeo::Feature::Polygon, RGeo::Feature::MultiPolygon].include? feature.geometry_type
117
+ if collection?
118
+ feature.any? { |geometry| Charta.new_geometry(geometry).surface? }
119
+ else
120
+ [RGeo::Feature::Polygon, RGeo::Feature::MultiPolygon].include? feature.geometry_type
121
+ end
114
122
  end
115
123
 
116
124
  # Returns area in unit corresponding to the SRS
117
125
  def area
118
- surface? ? feature.area : 0
126
+ if surface?
127
+ if collection?
128
+ feature.sum { |geometry| Charta.new_geometry(geometry).area }
129
+ else
130
+ feature.area
131
+ end
132
+ else
133
+ 0
134
+ end
119
135
  end
120
136
 
121
137
  # Returns true if this Geometry is an empty geometrycollection, polygon,
@@ -123,6 +139,7 @@ module Charta
123
139
  def empty?
124
140
  feature.is_empty?
125
141
  end
142
+
126
143
  alias blank? empty?
127
144
 
128
145
  # Computes the geometric center of a geometry, or equivalently, the center
@@ -142,10 +159,16 @@ module Charta
142
159
 
143
160
  def convert_to(new_type)
144
161
  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)
162
+ when type then
163
+ self
164
+ when :multi_point then
165
+ flatten_multi(:point)
166
+ when :multi_line_string then
167
+ flatten_multi(:line_string)
168
+ when :multi_polygon then
169
+ flatten_multi(:polygon)
170
+ else
171
+ self
149
172
  end
150
173
  end
151
174
 
@@ -196,17 +219,25 @@ module Charta
196
219
  other_geometry = Charta.new_geometry(other).transform(srid)
197
220
  feature.union(other_geometry.feature)
198
221
  end
222
+
199
223
  alias + merge
200
224
 
201
225
  def intersection(other)
202
226
  other_geometry = Charta.new_geometry(other).transform(srid)
203
- feature.intersection(other_geometry.feature)
227
+
228
+ Charta.new_geometry(feature.intersection(other_geometry.feature))
229
+ end
230
+
231
+ def intersects?(other)
232
+ other_geometry = Charta.new_geometry(other).transform(srid)
233
+ feature.intersects?(other_geometry.feature)
204
234
  end
205
235
 
206
236
  def difference(other)
207
237
  other_geometry = Charta.new_geometry(other).transform(srid)
208
238
  feature.difference(other_geometry.feature)
209
239
  end
240
+
210
241
  alias - difference
211
242
 
212
243
  def bounding_box
@@ -288,52 +319,52 @@ module Charta
288
319
 
289
320
  private
290
321
 
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
322
+ def geos_factory(srid)
323
+ RGeo::Geos.factory(
324
+ srid: srid,
325
+ wkt_generator: {
326
+ type_format: :ewkt,
327
+ emit_ewkt_srid: true,
328
+ convert_case: :upper
329
+ },
330
+ wkt_parser: {
331
+ support_ewkt: true
332
+ },
333
+ wkb_generator: {
334
+ type_format: :ewkb,
335
+ emit_ewkb_srid: true,
336
+ hex_format: true
337
+ },
338
+ wkb_parser: {
339
+ support_ewkb: true
340
+ }
341
+ )
342
+ end
312
343
 
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
344
+ def projected_factory(srid)
345
+ proj4 = '+proj=cea +lon_0=0 +lat_ts=30 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs'
346
+ RGeo::Geographic.projected_factory(
347
+ srid: srid,
348
+ wkt_generator: {
349
+ type_format: :ewkt,
350
+ emit_ewkt_srid: true,
351
+ convert_case: :upper
352
+ },
353
+ wkt_parser: {
354
+ support_ewkt: true
355
+ },
356
+ wkb_generator: {
357
+ type_format: :ewkb,
358
+ emit_ewkb_srid: true,
359
+ hex_format: true
360
+ },
361
+ wkb_parser: {
362
+ support_ewkb: true
363
+ },
364
+ projection_srid: 6933,
365
+ projection_proj4: proj4
366
+ )
367
+ end
337
368
  end
338
369
  end
339
370
  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.13'.freeze
2
+ VERSION = '0.1.18'.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.13
4
+ version: 0.1.18
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-01 00:00:00.000000000 Z
11
+ date: 2020-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -122,7 +122,7 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
- description:
125
+ description:
126
126
  email:
127
127
  - brice@ekylibre.com
128
128
  executables: []
@@ -159,7 +159,7 @@ homepage: https://github.com/ekylibre/charta
159
159
  licenses:
160
160
  - MIT
161
161
  metadata: {}
162
- post_install_message:
162
+ post_install_message:
163
163
  rdoc_options: []
164
164
  require_paths:
165
165
  - lib
@@ -174,9 +174,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
174
  - !ruby/object:Gem::Version
175
175
  version: '0'
176
176
  requirements: []
177
- rubyforge_project:
178
- rubygems_version: 2.6.14
179
- signing_key:
177
+ rubygems_version: 3.0.3
178
+ signing_key:
180
179
  specification_version: 4
181
180
  summary: Simple tool over geos and co
182
181
  test_files: []