rgeo-proj4 3.1.0 → 3.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9135e04b9e8911c2ce6c1c0f39be9edbe80d8adcbfa661dc57116320c616ff2d
4
- data.tar.gz: da0f069d9d7314c35a396fa0a2d2797944cc830a8f408b5ebdf577bba8c6a7c2
3
+ metadata.gz: b578b226ebc3b376a92f58cf080d34f237b5929751e6b856e493d9b6a6daa1ae
4
+ data.tar.gz: 84f4953ac2aea3783e7a807542c7aaf102b265dc454a9de97c340d70f04685c1
5
5
  SHA512:
6
- metadata.gz: a9e9d80f1df22a9fb3f1564ed622f008a53cacad669af211766c6b43e1654e7b589bce9b95ba0c2018e501b2625a43208f2195b47dda472e7daee45faa21bd5c
7
- data.tar.gz: d26e2e71aa7fab5737a70463f5a4689507707a9910eb874ae44e74df90899d4b3c52b88bef81b5d66298c28e0a22f6602c45fbcfa6c02633074e0351ee4e68e5
6
+ metadata.gz: bb2bddfdc101da5c0a4b2af5d5445ce7e57f8d49505b5bb2f53376e81b5ed392d4d2183c11e6cc1e0d86fc5b2fc83cc1afe1d6a3c72fcf8924d779fbd04fdffb
7
+ data.tar.gz: 3f21328f3beff54191cf496f784a432185f9999d4b71ddeab91d772627f26bbc97deb1882cab9d9f997d16432993d2c742c3d2638005d2f372959428201f4e05
@@ -7,15 +7,77 @@ module RGeo
7
7
  # A crs_to_crs transformation object is a pipeline between two known coordinate reference systems.
8
8
  # https://proj.org/development/reference/functions.html#c.proj_create_crs_to_crs
9
9
  class CRSToCRS
10
+ attr_writer :from, :to
11
+
12
+ class << self
13
+ def create(from, to)
14
+ crs_to_crs = _create(from, to)
15
+ crs_to_crs.from = from
16
+ crs_to_crs.to = to
17
+ crs_to_crs
18
+ end
19
+ end
10
20
  # transform the coordinates from the initial CRS to the destination CRS
11
21
  def transform_coords(x, y, z)
12
- _transform_coords(x, y, z)
22
+ if @from._radians? && @from._geographic?
23
+ x *= ImplHelper::Math::DEGREES_PER_RADIAN
24
+ y *= ImplHelper::Math::DEGREES_PER_RADIAN
25
+ end
26
+ result = _transform_coords(x, y, z)
27
+ if result && @to._radians? && @to._geographic?
28
+ result[0] *= ImplHelper::Math::RADIANS_PER_DEGREE
29
+ result[1] *= ImplHelper::Math::RADIANS_PER_DEGREE
30
+ end
31
+ result
13
32
  end
14
33
 
15
- class << self
16
- def create(from, to)
17
- _create(from, to)
34
+ def transform(from_geometry, to_factory)
35
+ case from_geometry
36
+ when Feature::Point
37
+ transform_point(from_geometry, to_factory)
38
+ when Feature::Line
39
+ to_factory.line(from_geometry.points.map { |p| transform_point(p, to_factory) })
40
+ when Feature::LinearRing
41
+ transform_linear_ring(from_geometry, to_factory)
42
+ when Feature::LineString
43
+ to_factory.line_string(from_geometry.points.map { |p_| transform_point(p_, to_factory) })
44
+ when Feature::Polygon
45
+ transform_polygon(from_geometry, to_factory)
46
+ when Feature::MultiPoint
47
+ to_factory.multi_point(from_geometry.map { |p| transform_point(p, to_factory) })
48
+ when Feature::MultiLineString
49
+ to_factory.multi_line_string(from_geometry.map { |g| transform(g, to_factory) })
50
+ when Feature::MultiPolygon
51
+ to_factory.multi_polygon(from_geometry.map { |p| transform_polygon(p, to_factory) })
52
+ when Feature::GeometryCollection
53
+ to_factory.collection(from_geometry.map { |g| transform(g, to_factory) })
54
+ end
55
+ end
56
+
57
+ def transform_point(from_point, to_factory)
58
+ from_factory_ = from_point.factory
59
+ from_has_z_ = from_factory_.property(:has_z_coordinate)
60
+ from_has_m_ = from_factory_.property(:has_m_coordinate)
61
+ to_has_z_ = to_factory.property(:has_z_coordinate)
62
+ to_has_m_ = to_factory.property(:has_m_coordinate)
63
+ coords_ = transform_coords(from_point.x, from_point.y, from_has_z_ ? from_point.z : nil)
64
+ return unless coords_
65
+ extras_ = []
66
+ extras_ << coords_[2].to_f if to_has_z_
67
+ if to_has_m_
68
+ extras_ << from_has_m_ ? from_point.m : 0.0
18
69
  end
70
+ to_factory.point(coords_[0], coords_[1], *extras_)
71
+ end
72
+
73
+ def transform_linear_ring(from_ring_, to_factory_)
74
+ to_factory_.linear_ring(from_ring_.points[0..-2].map { |p_| transform_point(p_, to_factory_) })
75
+ end
76
+
77
+ def transform_polygon(from_polygon_, to_factory_)
78
+ ext_ = transform_linear_ring(from_polygon_.exterior_ring, to_factory_)
79
+ int_ = from_polygon_.interior_rings.map { |r_| transform_linear_ring(r_, to_factory_) }
80
+ to_factory_.polygon(ext_, int_)
19
81
  end
20
82
  end
21
83
 
@@ -222,18 +222,8 @@ module RGeo
222
222
  # coordinate system to another. Returns an array with either two
223
223
  # or three elements.
224
224
  def transform_coords(from_proj_, to_proj_, x_, y_, z_ = nil)
225
- if from_proj_._radians? && from_proj_._geographic?
226
- x_ *= ImplHelper::Math::DEGREES_PER_RADIAN
227
- y_ *= ImplHelper::Math::DEGREES_PER_RADIAN
228
- end
229
-
230
225
  crs_to_crs = CRSStore.get(from_proj_, to_proj_)
231
- result_ = crs_to_crs.transform_coords(x_, y_, z_)
232
- if result_ && to_proj_._radians? && to_proj_._geographic?
233
- result_[0] *= ImplHelper::Math::RADIANS_PER_DEGREE
234
- result_[1] *= ImplHelper::Math::RADIANS_PER_DEGREE
235
- end
236
- result_
226
+ crs_to_crs.transform_coords(x_, y_, z_)
237
227
  end
238
228
 
239
229
  # Low-level geometry transform method.
@@ -241,56 +231,9 @@ module RGeo
241
231
  # The resulting geometry is constructed using the to_factory.
242
232
  # Any projections associated with the factories themselves are
243
233
  # ignored.
244
-
245
234
  def transform(from_proj_, from_geometry_, to_proj_, to_factory_)
246
- case from_geometry_
247
- when Feature::Point
248
- transform_point(from_proj_, from_geometry_, to_proj_, to_factory_)
249
- when Feature::Line
250
- to_factory_.line(from_geometry_.points.map { |p_| transform_point(from_proj_, p_, to_proj_, to_factory_) })
251
- when Feature::LinearRing
252
- transform_linear_ring(from_proj_, from_geometry_, to_proj_, to_factory_)
253
- when Feature::LineString
254
- to_factory_.line_string(from_geometry_.points.map { |p_| transform_point(from_proj_, p_, to_proj_, to_factory_) })
255
- when Feature::Polygon
256
- transform_polygon(from_proj_, from_geometry_, to_proj_, to_factory_)
257
- when Feature::MultiPoint
258
- to_factory_.multi_point(from_geometry_.map { |p_| transform_point(from_proj_, p_, to_proj_, to_factory_) })
259
- when Feature::MultiLineString
260
- to_factory_.multi_line_string(from_geometry_.map { |g_| transform(from_proj_, g_, to_proj_, to_factory_) })
261
- when Feature::MultiPolygon
262
- to_factory_.multi_polygon(from_geometry_.map { |p_| transform_polygon(from_proj_, p_, to_proj_, to_factory_) })
263
- when Feature::GeometryCollection
264
- to_factory_.collection(from_geometry_.map { |g_| transform(from_proj_, g_, to_proj_, to_factory_) })
265
- end
266
- end
267
-
268
- private
269
-
270
- def transform_point(from_proj_, from_point_, to_proj_, to_factory_)
271
- from_factory_ = from_point_.factory
272
- from_has_z_ = from_factory_.property(:has_z_coordinate)
273
- from_has_m_ = from_factory_.property(:has_m_coordinate)
274
- to_has_z_ = to_factory_.property(:has_z_coordinate)
275
- to_has_m_ = to_factory_.property(:has_m_coordinate)
276
- coords_ = transform_coords(from_proj_, to_proj_, from_point_.x, from_point_.y, from_has_z_ ? from_point_.z : nil)
277
- return unless coords_
278
- extras_ = []
279
- extras_ << coords_[2].to_f if to_has_z_
280
- if to_has_m_
281
- extras_ << from_has_m_ ? from_point_.m : 0.0
282
- end
283
- to_factory_.point(coords_[0], coords_[1], *extras_)
284
- end
285
-
286
- def transform_linear_ring(from_proj_, from_ring_, to_proj_, to_factory_)
287
- to_factory_.linear_ring(from_ring_.points[0..-2].map { |p_| transform_point(from_proj_, p_, to_proj_, to_factory_) })
288
- end
289
-
290
- def transform_polygon(from_proj_, from_polygon_, to_proj_, to_factory_)
291
- ext_ = transform_linear_ring(from_proj_, from_polygon_.exterior_ring, to_proj_, to_factory_)
292
- int_ = from_polygon_.interior_rings.map { |r_| transform_linear_ring(from_proj_, r_, to_proj_, to_factory_) }
293
- to_factory_.polygon(ext_, int_)
235
+ crs_to_crs = CRSStore.get(from_proj_, to_proj_)
236
+ crs_to_crs.transform(from_geometry_, to_factory_)
294
237
  end
295
238
  end
296
239
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RGeo
4
4
  module Proj4
5
- VERSION = "3.1.0"
5
+ VERSION = "3.1.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgeo-proj4
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tee Parham, Daniel Azuma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-12 00:00:00.000000000 Z
11
+ date: 2021-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rgeo