proj4rb 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +5 -5
  2. data/ChangeLog +46 -0
  3. data/Gemfile +4 -0
  4. data/README.rdoc +158 -148
  5. data/Rakefile +26 -41
  6. data/lib/area.rb +32 -0
  7. data/lib/config.rb +70 -0
  8. data/lib/context.rb +103 -0
  9. data/lib/coordinate.rb +197 -0
  10. data/lib/crs.rb +206 -0
  11. data/lib/ellipsoid.rb +42 -0
  12. data/lib/error.rb +18 -0
  13. data/lib/operation.rb +43 -0
  14. data/lib/pj_object.rb +82 -0
  15. data/lib/point.rb +72 -0
  16. data/lib/prime_meridian.rb +40 -0
  17. data/lib/proj.rb +31 -0
  18. data/lib/proj4.rb +3 -469
  19. data/lib/projection.rb +207 -0
  20. data/lib/transformation.rb +61 -0
  21. data/lib/unit.rb +54 -0
  22. data/proj4rb.gemspec +31 -0
  23. data/test/abstract_test.rb +7 -0
  24. data/test/context_test.rb +82 -0
  25. data/test/coordinate_test.rb +35 -0
  26. data/test/crs_test.rb +373 -0
  27. data/test/ellipsoid_test.rb +34 -0
  28. data/test/operation_test.rb +29 -0
  29. data/test/prime_meridians_test.rb +33 -0
  30. data/test/proj_test.rb +17 -0
  31. data/test/projection_test.rb +224 -0
  32. data/test/transformation_test.rb +68 -0
  33. data/test/unit_test.rb +47 -0
  34. metadata +82 -77
  35. data/data/GL27 +0 -22
  36. data/data/MD +0 -0
  37. data/data/TN +0 -0
  38. data/data/WI +0 -0
  39. data/data/WO +0 -0
  40. data/data/conus +0 -0
  41. data/data/epsg +0 -5443
  42. data/data/epsg-deprecated +0 -2
  43. data/data/esri +0 -5937
  44. data/data/esri.extra +0 -948
  45. data/data/hawaii +0 -0
  46. data/data/nad.lst +0 -142
  47. data/data/nad27 +0 -809
  48. data/data/nad83 +0 -744
  49. data/data/ntv1_can.dat +0 -0
  50. data/data/null +0 -0
  51. data/data/other.extra +0 -49
  52. data/data/proj_def.dat +0 -17
  53. data/data/prvi +0 -0
  54. data/data/stgeorge +0 -0
  55. data/data/stlrnc +0 -0
  56. data/data/stpaul +0 -0
  57. data/data/world +0 -212
  58. data/example/basic.rb +0 -18
  59. data/example/list-datums.rb +0 -17
  60. data/example/list-ellipsoids.rb +0 -17
  61. data/example/list-errors.rb +0 -11
  62. data/example/list-prime-meridians.rb +0 -17
  63. data/example/list-projection-types.rb +0 -17
  64. data/example/list-units.rb +0 -17
  65. data/example/version.rb +0 -8
  66. data/ext/Makefile +0 -238
  67. data/ext/extconf.rb +0 -16
  68. data/ext/mkmf.log +0 -103
  69. data/ext/out.log +0 -0
  70. data/ext/proj4_ruby-x64-mingw32.def +0 -2
  71. data/ext/proj4_ruby.so +0 -0
  72. data/ext/projrb.c +0 -566
  73. data/ext/projrb.o +0 -0
  74. data/ext/vc/proj4_ruby.sln +0 -19
  75. data/ext/vc/proj4_ruby.vcproj +0 -208
  76. data/test/test_constants.rb +0 -18
  77. data/test/test_create_projection.rb +0 -63
  78. data/test/test_datums.rb +0 -45
  79. data/test/test_ellipsoids.rb +0 -46
  80. data/test/test_errors.rb +0 -66
  81. data/test/test_init_projection.rb +0 -109
  82. data/test/test_prime_meridians.rb +0 -45
  83. data/test/test_projection_type.rb +0 -44
  84. data/test/test_simple_projection.rb +0 -58
  85. data/test/test_suite.rb +0 -14
  86. data/test/test_transform.rb +0 -115
  87. data/test/test_units.rb +0 -46
@@ -0,0 +1,42 @@
1
+ module Proj
2
+ class Ellipsoid
3
+ attr_reader :id, :major, :ell, :name
4
+
5
+ def self.list
6
+ pointer_to_array = FFI::Pointer.new(Api::PJ_ELLPS, Api.proj_list_ellps)
7
+ result = Array.new
8
+ 0.step do |i|
9
+ ellipse_info = Api::PJ_ELLPS.new(pointer_to_array[i])
10
+ break result if ellipse_info[:id].nil?
11
+ result << self.new(ellipse_info[:id], ellipse_info[:major], ellipse_info[:ell], ellipse_info[:name])
12
+ end
13
+ end
14
+
15
+ def self.get(id)
16
+ self.list.find {|ellipsoid| ellipsoid.id == id}
17
+ end
18
+
19
+ def initialize(id, major, ell, name)
20
+ @id = id
21
+ @major = major
22
+ @ell = ell
23
+ @name = name
24
+ end
25
+
26
+ def <=>(other)
27
+ self.id <=> other.id
28
+ end
29
+
30
+ def ==(other)
31
+ self.id == other.id
32
+ end
33
+
34
+ def to_s
35
+ self.id
36
+ end
37
+
38
+ def inspect
39
+ "#<#{self.class} id=\"#{id}\", major=\"#{major}\", ell=\"#{ell}\", name=\"#{name}\">"
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,18 @@
1
+ module Proj
2
+ class Error < StandardError
3
+ def self.check(errno=nil)
4
+ unless errno
5
+ errno = Context.current.errno
6
+ end
7
+
8
+ if errno != 0
9
+ message = if Api.method_defined?(:proj_errno_string)
10
+ Api.proj_errno_string(errno)
11
+ else
12
+ Api.pj_strerrno(errno)
13
+ end
14
+ raise(self, message)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,43 @@
1
+ module Proj
2
+ class Operation
3
+ attr_reader :id, :description
4
+
5
+ def self.list
6
+ pointer_to_array = FFI::Pointer.new(Api::PJ_OPERATIONS, Api.proj_list_operations)
7
+ result = Array.new
8
+ 0.step do |i|
9
+ operation_info = Api::PJ_OPERATIONS.new(pointer_to_array[i])
10
+ break result if operation_info[:id].nil?
11
+ id = operation_info[:id]
12
+ description = operation_info[:descr].read_pointer.read_string.force_encoding('UTF-8')
13
+ result << self.new(id, description)
14
+ end
15
+ result
16
+ end
17
+
18
+ def self.get(id)
19
+ self.list.find {|operation| operation.id == id}
20
+ end
21
+
22
+ def initialize(id, description)
23
+ @id = id
24
+ @description = description
25
+ end
26
+
27
+ def <=>(other)
28
+ self.id <=> other.id
29
+ end
30
+
31
+ def ==(other)
32
+ self.id == other.id
33
+ end
34
+
35
+ def to_s
36
+ self.id
37
+ end
38
+
39
+ def inspect
40
+ "#<#{self.class} id=\"#{id}\", major=\"#{major}\", ell=\"#{ell}\", name=\"#{name}\">"
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,82 @@
1
+ # encoding: UTF-8
2
+ module Proj
3
+ class PjObject
4
+ attr_reader :context
5
+
6
+ def self.finalize(pointer)
7
+ proc do
8
+ Api.proj_destroy(pointer)
9
+ end
10
+ end
11
+
12
+ def initialize(pointer, context=nil)
13
+ @pointer = pointer
14
+ @context = context
15
+ ObjectSpace.define_finalizer(self, self.class.finalize(@pointer))
16
+ end
17
+
18
+ def to_ptr
19
+ @pointer
20
+ end
21
+
22
+ def context
23
+ @context || Context.current
24
+ end
25
+
26
+ def proj_type
27
+ Api.proj_get_type(self)
28
+ end
29
+
30
+ def info
31
+ Api.proj_pj_info(self)
32
+ end
33
+
34
+ def id
35
+ self.info[:id]
36
+ end
37
+
38
+ def name
39
+ Api.proj_get_name(self).force_encoding('UTF-8')
40
+ end
41
+
42
+ def auth_name(index=0)
43
+ Api.proj_get_id_auth_name(self, index).force_encoding('UTF-8')
44
+ end
45
+
46
+ def auth_code(index=0)
47
+ Api.proj_get_id_code(self, index)
48
+ end
49
+
50
+ def auth(index=0)
51
+ "#{self.auth_name(index)}:#{self.auth_code(index)}"
52
+ end
53
+
54
+ def description
55
+ self.info[:description] ? self.info[:description].force_encoding('UTF-8') : nil
56
+ end
57
+
58
+ def definition
59
+ self.info[:definition] ? self.info[:definition].force_encoding('UTF-8') : nil
60
+ end
61
+
62
+ def has_inverse?
63
+ self.info[:has_inverse] == 1 ? true : false
64
+ end
65
+
66
+ def accuracy
67
+ self.info[:accuracy]
68
+ end
69
+
70
+ def to_proj_string(string_type=:PJ_PROJ_4)
71
+ Api.proj_as_proj_string(self.context, self, string_type, nil).force_encoding('UTF-8')
72
+ end
73
+
74
+ def to_json
75
+ Api.proj_as_projjson(self.context, self, nil).force_encoding('UTF-8')
76
+ end
77
+
78
+ def to_wkt(wkt_type=:PJ_WKT2_2018)
79
+ Api.proj_as_wkt(self.context, self, wkt_type, nil).force_encoding('UTF-8')
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,72 @@
1
+ # encoding: UTF-8
2
+
3
+ module Proj
4
+ # @deprecated This class is *DEPRECATED.* It will be removed when Proj 7 is released and removes the
5
+ # underlying API's this class uses. Code should be ported to use Coordinate objects.
6
+ class Point
7
+ def self.from_pointer(pointer)
8
+ result = self.allocate
9
+ result.instance_variable_set(:@struct, pointer)
10
+ result
11
+ end
12
+
13
+ # Create new Point object from coordinates.
14
+ def initialize(x, y)
15
+ @struct = Api::ProjUV.new
16
+ @struct[:u] = x
17
+ @struct[:v] = y
18
+ end
19
+
20
+ def to_ptr
21
+ @struct.to_ptr
22
+ end
23
+
24
+ def to_radians
25
+ self.class.new(Api.proj_torad(self.x), Api.proj_torad(self.y))
26
+ end
27
+
28
+ def to_degrees
29
+ self.class.new(Api.proj_todeg(self.x), Api.proj_todeg(self.y))
30
+ end
31
+
32
+ # Get x coordinate.
33
+ def x
34
+ @struct[:u]
35
+ end
36
+
37
+ # Set x coordinate.
38
+ def x=(value)
39
+ @struct[:u] = value
40
+ end
41
+
42
+ # Get y coordinate.
43
+ def y
44
+ @struct[:v]
45
+ end
46
+
47
+ # Set y coordinate.
48
+ def y=(value)
49
+ @struct[:v] = value
50
+ end
51
+
52
+ # Get longitude/x coordinate.
53
+ def lon
54
+ @struct[:u]
55
+ end
56
+
57
+ # Set longitude/x coordinate.
58
+ def lon=(value)
59
+ @struct[:u] = value
60
+ end
61
+
62
+ # Get latitude/y coordinate.
63
+ def lat
64
+ @struct[:v]
65
+ end
66
+
67
+ # Set latitude/y coordinate.
68
+ def lat=(value)
69
+ @struct[:v] = value
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,40 @@
1
+ module Proj
2
+ class PrimeMeridian
3
+ attr_reader :id, :defn
4
+
5
+ def self.list
6
+ pointer_to_array = FFI::Pointer.new(Api::PJ_PRIME_MERIDIANS, Api.proj_list_prime_meridians)
7
+ result = Array.new
8
+ 0.step do |i|
9
+ prime_meridian_info = Api::PJ_PRIME_MERIDIANS.new(pointer_to_array[i])
10
+ break result if prime_meridian_info[:id].nil?
11
+ result << self.new(prime_meridian_info[:id], prime_meridian_info[:defn])
12
+ end
13
+ end
14
+
15
+ def self.get(id)
16
+ self.list.find {|ellipsoid| ellipsoid.id == id}
17
+ end
18
+
19
+ def initialize(id, defn)
20
+ @id = id
21
+ @defn = defn
22
+ end
23
+
24
+ def <=>(other)
25
+ self.id <=> other.id
26
+ end
27
+
28
+ def ==(other)
29
+ self.id == other.id
30
+ end
31
+
32
+ def to_s
33
+ self.id
34
+ end
35
+
36
+ def inspect
37
+ "#<#{self.class} id=\"#{id}\", defn=\"#{defn}\">"
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: UTF-8
2
+
3
+ require_relative 'api/api'
4
+ require_relative './config'
5
+
6
+ require_relative './area'
7
+ require_relative './context'
8
+ require_relative './coordinate'
9
+ require_relative './ellipsoid'
10
+ require_relative './error'
11
+ require_relative './point'
12
+ require_relative './prime_meridian'
13
+ require_relative './unit'
14
+
15
+ require_relative './pj_object'
16
+ require_relative './operation'
17
+ require_relative './crs'
18
+ require_relative './projection'
19
+ require_relative './transformation'
20
+
21
+ module Proj
22
+ def self.info
23
+ Api.proj_info
24
+ end
25
+
26
+ def self.version
27
+ self.info[:version]
28
+ end
29
+ end
30
+
31
+ Proj::Config.instance.set_search_paths
@@ -1,472 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- if File.exists?(File.dirname(__FILE__ + '/../data'))
4
- ENV['PROJ_LIB'] = File.dirname(__FILE__) + '/../data'
5
- end
6
-
7
- # Load the C-based binding.
8
- begin
9
- require 'proj4_ruby'
10
- rescue LoadError
11
- require '../ext/proj4_ruby'
12
- end
13
-
14
- # Ruby bindings for the Proj.4 cartographic projection library (http://trac.osgeo.org/proj/).
15
- module Proj4
16
-
17
- # Base class for all Proj.4 exceptions. Subclasses with the name <errorname>Error are available for each exception.
18
- class Error < StandardError
19
-
20
- # List of all Proj.4 errors.
21
- #--
22
- # (This list is created from the one in pj_strerrno.c in the Proj.4 distribution.)
23
- #++
24
- ERRORS = %w{Unknown NoArgsInInitList NoOptionsInInitFile NoColonInInitString ProjectionNotNamed UnknownProjectionId EffectiveEccentricityEq1 UnknownUnitConversionId InvalidBooleanParamArgument UnknownEllipticalParameterName ReciprocalFlatteningIsZero RadiusReferenceLatitudeGt90 SquaredEccentricityLessThanZero MajorAxisOrRadiusIsZeroOrNotGiven LatitudeOrLongitudeExceededLimits InvalidXOrY ImproperlyFormedDMSValue NonConvergentInverseMeridinalDist NonConvergentInversePhi2 AcosOrAsinArgTooBig ToleranceCondition ConicLat1EqMinusLat2 Lat1GreaterThan90 Lat1IsZero LatTsGreater90 NoDistanceBetweenControlPoints ProjectionNotSelectedToBeRotated WSmallerZeroOrMSmallerZero LsatNotInRange PathNotInRange HSmallerZero KSmallerZero Lat0IsZeroOr90OrAlphaIsZero Lat1EqLat2OrLat1IsZeroOrLat2Is90 EllipticalUsageRequired InvalidUTMZoneNumber ArgsOutOfRangeForTchebyEval NoProjectionToBeRotated FailedToLoadNAD2783CorrectionFile BothNAndMMustBeSpecdAndGreaterZero NSmallerZeroOrNGreaterOneOrNotSpecified Lat1OrLat2NotSpecified AbsoluteLat1EqLat2 Lat0IsHalfPiFromMeanLat UnparseableCoordinateSystemDefinition GeocentricTransformationMissingZOrEllps UnknownPrimeMeridianConversionId}
25
-
26
- # Return list of all errors.
27
- #
28
- # call-seq: list -> Array
29
- #
30
- def self.list
31
- ERRORS
32
- end
33
-
34
- # Return name of error with given number.
35
- #
36
- # call-seq: error(errnum) -> String
37
- #
38
- def self.error(errnum)
39
- ERRORS[errnum.abs] || 'Unknown'
40
- end
41
-
42
- # Raise an error with error number +errnum+.
43
- def self.raise_error(errnum)
44
- raise eval("#{error(errnum.abs)}Error"), message(-(errnum.abs)), caller[0..-1]
45
- end
46
-
47
- # Return error number of this error.
48
- def errnum
49
- self.class.errnum
50
- end
51
-
52
- end
53
-
54
- Error.list.each_with_index do |err, index|
55
- eval "class #{err}Error < Error;
56
- def self.errnum;
57
- #{index};
58
- end;
59
- end"
60
- end
61
-
62
- # The Projection class represents a geographical projection.
63
- #
64
- # = Creating a new projection object
65
- #
66
- # Projection objects are created through the new method as usual. Depending on the kind of projection, many
67
- # different parameters are needed. Please consult the documentation of the Proj.4 C library at http://trac.osgeo.org/proj/
68
- # for details.
69
- #
70
- # There are several ways of specifying the parameters:
71
- #
72
- # [<b>as a String:</b>] A string with the parameters in '[+]key=value' format concatenated together. This is the format used by the <tt>proj</tt> and <tt>cs2cs</tt> command line tool.
73
- #
74
- # proj = Projection.new "+proj=utm +zone=21 +units=m"
75
- #
76
- # [<b>as an Array:</b>] An array with each parameter as a member in the array in '[+]key=value' format.
77
- #
78
- # proj = Projection.new [ "proj=utm", "zone=21", "units=m" ]
79
- #
80
- # [<b>as a Hash:</b>] A hash with strings or symbols as keys.
81
- #
82
- # proj = Projection.new( "proj" => "utm", "zone" => "21", "units" => "m" )
83
- # proj = Projection.new( :proj => "utm", :zone => "21", :units => "m" )
84
- #
85
- # With all variants the plus sign in front of the keys is optional.
86
- #
87
- # = Using a projection object to project points
88
- #
89
- # There are two ways a projection can be used: Through the +forward+ and +inverse+ methods (with all their variants)
90
- # you can do projection from longitudes and latitudes into the coordinate system used by the projection and back.
91
- # These projections are always 2D, i.e. you need and get lon/lat or x/y coordinates.
92
- #
93
- # The alternative is the +transform+ method (with all its variants) which is used to transform 3D points from one
94
- # projection and datum to another. In addition to the x/y coordinates the transform method also reads and returns
95
- # a z coordinate.
96
- #
97
- # = Versions of the projection methods
98
- #
99
- # All three projection methods (+forward+, +inverse+, and +transform+) work on points. Every method has an in-place
100
- # version (with a name ending in !) which changes the given point and a normal version which first creates a copy of
101
- # the point object and changes and returns that. All methods use radians when reading or returning points. For
102
- # convenience there are also +forwardDeg+ and +inverseDeg+ methods (and in-place versions <tt>forwardDeg!</tt>
103
- # and <tt>inverseDeg!</tt>) that will work with degrees.
104
- #
105
- # = Points
106
- #
107
- # All projection method project points to other points. You can use objects of the Proj4::Point class for this or
108
- # any other object which supports the x, y, z read and write accessor methods. (In fact you don't even need the
109
- # z accessor methods, 0 is assumed if they don't exist.)
110
- #
111
- # Some projection methods act on the given point in-place, other return a copy of the point object. But in any case
112
- # all other attributes of the point object are retained.
113
- #
114
- # = Projection collections
115
- #
116
- # The methods forward_all, inverse_all, and transform_all (and their in-place versions forward_all!,
117
- # inverse_all!, and transform_all! work just like their simple counterparts, but instead of a single
118
- # point they convert a collection of points in one go.
119
- #
120
- # These methods all take an array as an argument or any object responding to the +each+ method (for the in-place versions)
121
- # or +each+, +clear+, and <tt><<</tt> methods (for the normal version).
122
- #
123
- # Some projection methods act on the given collection in-place, i.e. the collection is not touched and all points
124
- # in the collection will be projected in-place. The other methods act on a copy of the collection and on copies
125
- # of each point in the collection. So you'll get back a brand new copy of the collection with new copies of the
126
- # points with the projected coordinates. In any case all other attributes of the collection and points are retained.
127
- #
128
- class Projection
129
-
130
- private
131
-
132
- def self._parse_init_parameters(args)
133
- case args
134
- when Array
135
- args.collect{ |a| a.sub(/^\+/, '') }
136
- when String
137
- args.strip.split(' ').collect{ |a| a.sub(/^\+/, '')}
138
- when Hash
139
- array = []
140
- args.each_pair{ | key, value | array << (value.nil? ? key.to_s : "#{key}=#{value}") }
141
- array
142
- when Proj4::Projection
143
- args.getDef.strip.split(' ').collect{ |a| a.sub(/^\+/, '')}
144
- else
145
- raise ArgumentError, "Unknown type #{args.class} for projection definition"
146
- end
147
- end
148
-
149
- public
150
-
151
- # Get the ID of this projection.
152
- #
153
- # call-seq: projection -> String
154
- #
155
- def projection
156
- getDef =~ /\+proj=(.+?) / ? $1 : nil
157
- end
158
-
159
- # Get the ID of the datum used in this projection.
160
- #
161
- # call-seq: datum -> String
162
- #
163
- def datum
164
- getDef =~ /\+datum=(.+?) / ? $1 : nil
165
- end
166
-
167
- # Get definition of projection in typical inspect format (#<Proj4::Projection +init=... +proj=... ...>).
168
- #
169
- # call-seq: to_s -> String
170
- #
171
- def to_s
172
- "#<Proj4::Projection#{ getDef }>"
173
- end
174
-
175
- # Forward projection of a point. Returns a copy of the point object with coordinates projected.
176
- #
177
- # call-seq: forward(point) -> point
178
- #
179
- def forward(point)
180
- forward!(point.dup)
181
- end
182
-
183
- # Convenience function for calculating a forward projection with degrees instead of radians.
184
- #
185
- # call-seq: forwardDeg(point) -> point
186
- #
187
- def forwardDeg(point)
188
- forwardDeg!(point.dup)
189
- end
190
-
191
- # Convenience function for calculating a forward projection with degrees instead of radians.
192
- # This version works in-place, i.e. the point objects content is overwritten.
193
- #
194
- # call-seq: forwardDeg!(point) -> point
195
- #
196
- def forwardDeg!(point)
197
- point.x *= Proj4::DEG_TO_RAD
198
- point.y *= Proj4::DEG_TO_RAD
199
- forward!(point)
200
- end
201
-
202
- # Project all points in a collection 'in place'.
203
- # The +collection+ object must implement the +each+
204
- # method for this to work.
205
- #
206
- # call-seq: forward_all!(collection) -> collection
207
- #
208
- def forward_all!(collection)
209
- collection.each do |point|
210
- forward!(point)
211
- end
212
- collection
213
- end
214
-
215
- # Projects all points in a collection.
216
- # The +collection+ object must implement the +each+,
217
- # +clear+, and << methods (just like an Array) for this to work.
218
- #
219
- # call-seq: forward_all(collection) -> collection
220
- #
221
- def forward_all(collection)
222
- newcollection = collection.dup.clear
223
- collection.each do |point|
224
- newcollection << forward(point)
225
- end
226
- newcollection
227
- end
228
-
229
- # Inverse projection of a point. Returns a copy of the point object with coordinates projected.
230
- #
231
- # call-seq: inverse(point) -> point
232
- #
233
- def inverse(point)
234
- inverse!(point.dup)
235
- end
236
-
237
- # Convenience function for calculating an inverse projection with the result in degrees instead of radians.
238
- #
239
- # call-seq: inverseDeg(point) -> point
240
- #
241
- def inverseDeg(point)
242
- inverseDeg!(point.dup)
243
- end
244
-
245
- # Convenience function for calculating an inverse projection with the result in degrees instead of radians.
246
- # This version works in-place, i.e. the point objects content is overwritten.
247
- #
248
- # call-seq: inverseDeg!(point) -> point
249
- #
250
- def inverseDeg!(point)
251
- inverse!(point)
252
- point.x *= Proj4::RAD_TO_DEG
253
- point.y *= Proj4::RAD_TO_DEG
254
- point
255
- end
256
-
257
- # Project all points in a collection 'in place'.
258
- # The +collection+ object must implement the +each+
259
- # method for this to work.
260
- #
261
- # call-seq: inverse_all!(collection) -> collection
262
- #
263
- def inverse_all!(collection)
264
- collection.each do |point|
265
- inverse!(point)
266
- end
267
- collection
268
- end
269
-
270
- # Projects all points in a collection.
271
- # The +collection+ object must implement the +each+,
272
- # +clear+, and << methods (just like an Array) for this to work.
273
- #
274
- # call-seq: inverse_all(collection) -> collection
275
- #
276
- def inverse_all(collection)
277
- newcollection = collection.dup.clear
278
- collection.each do |point|
279
- newcollection << inverse(point)
280
- end
281
- newcollection
282
- end
283
-
284
- # Transforms a point from one projection to another.
285
- #
286
- # call-seq: transform(destinationProjection, point) -> point
287
- #
288
- def transform(otherProjection, point)
289
- transform!(otherProjection, point.dup)
290
- end
291
-
292
- # Transforms all points in a collection 'in place' from one projection
293
- # to another. The +collection+ object must implement the +each+
294
- # method for this to work.
295
- #
296
- # call-seq: transform_all!(destinationProjection, collection) -> collection
297
- #
298
- def transform_all!(otherProjection, collection)
299
- collection.each do |point|
300
- transform!(otherProjection, point)
301
- end
302
- collection
303
- end
304
-
305
- # Transforms all points in a collection from one projection to
306
- # another. The +collection+ object must implement the +each+,
307
- # +clear+, and << methods (just like an Array) for this to work.
308
- #
309
- # call-seq: transform_all(destinationProjection, collection) -> collection
310
- #
311
- def transform_all(otherProjection, collection)
312
- newcollection = collection.dup.clear
313
- collection.each do |point|
314
- newcollection << transform(otherProjection, point)
315
- end
316
- newcollection
317
- end
318
-
319
- end
320
-
321
- # This class represents a point in either lon/lat or projected x/y coordinates.
322
- class Point
323
-
324
- # X coordinate or longitude
325
- attr_accessor :x
326
-
327
- # Y coordinate or latitude
328
- attr_accessor :y
329
-
330
- # Z coordinate (height)
331
- attr_accessor :z
332
-
333
- # Create new Proj4::Point object from coordinates.
334
- def initialize(x, y, z=0)
335
- @x = x
336
- @y = y
337
- @z = z
338
- end
339
-
340
- # Get longitude/x coordinate.
341
- def lon
342
- x
343
- end
344
-
345
- # Get latitude/y coordinate.
346
- def lat
347
- y
348
- end
349
-
350
- # Set longitude/x coordinate.
351
- def lon=(lon)
352
- @x = lon
353
- end
354
-
355
- # Set latitude/y coordinate.
356
- def lat=(lat)
357
- @y = lat
358
- end
359
-
360
- end
361
-
362
- # Abstract base class for several types of definitions: Proj4::Datum, Proj4::Ellipsoid, Proj4::PrimeMeridian, Proj4::ProjectionType, Proj4::Unit.
363
- #
364
- # Note that these classes only work if the version of the Proj.4 C library used is at least 449.
365
- class Def
366
-
367
- # Initialize function raises error. Definitions are always defined by the underlying Proj.4 library, you can't create them yourself.
368
- def initialize # :nodoc:
369
- raise TypeError, "You can't created objects of this type yourself."
370
- end
371
-
372
- # Get the definition with given id.
373
- def self.get(id)
374
- self.list.select{ |u| u.id == id }.first
375
- end
376
-
377
- # Compares definitions by comparing ids.
378
- #
379
- # call-seq: one == other -> true or false
380
- #
381
- def ==(other)
382
- self.id == other.id
383
- end
384
-
385
- # Compares definitions by comparing ids.
386
- #
387
- # call-seq: one <=> other -> -1, 0, 1
388
- #
389
- def <=>(other)
390
- self.id <=> other.id
391
- end
392
-
393
- # Stringify definition. Returns ID of this definition.
394
- #
395
- # call-seq: to_s -> String
396
- #
397
- def to_s
398
- id
399
- end
400
-
401
- end
402
-
403
- class Datum < Def
404
-
405
- # Returns datum definition as string in format '#<Proj4::Datum id="...", ellipse_id="...", defn="...", comments="...">'.
406
- #
407
- # call-seq: inspect -> String
408
- #
409
- def inspect
410
- "#<Proj4::Datum id=\"#{id}\", ellipse_id=\"#{ellipse_id}\", defn=\"#{defn}\", comments=\"#{comments}\">"
411
- end
412
-
413
- end
414
-
415
- class Ellipsoid < Def
416
-
417
- # Returns ellipsoid definition as string in format '#<Proj4::Ellipsoid id="...", major="...", ell="...", name="...">'.
418
- #
419
- # call-seq: inspect -> String
420
- #
421
- def inspect
422
- "#<Proj4::Ellipsoid id=\"#{id}\", major=\"#{major}\", ell=\"#{ell}\", name=\"#{name}\">"
423
- end
424
-
425
- end
426
-
427
- class PrimeMeridian < Def
428
-
429
- # Returns a prime meridian definition as string in format '#<Proj4::PrimeMeridian id="...", defn="...">'.
430
- #
431
- # call-seq: inspect -> String
432
- #
433
- def inspect
434
- "#<Proj4::PrimeMeridian id=\"#{id}\", defn=\"#{defn}\">"
435
- end
436
-
437
- end
438
-
439
- class ProjectionType < Def
440
-
441
- # Returns a projection type as string in format '#<Proj4::PrimeMeridian id="...", name="...">'.
442
- #
443
- # call-seq: inspect -> String
444
- #
445
- def inspect
446
- "#<Proj4::ProjectionType id=\"#{id}\", name=\"#{name}\">"
447
- end
448
-
449
- # Gets name of this projection type.
450
- #
451
- # call-seq: name -> String
452
- #
453
- def name
454
- descr.sub(/\n.*/m, '')
455
- end
456
-
457
- end
458
-
459
- class Unit < Def
460
-
461
- # Returns unit definition as string in format '#<Proj4::Unit id="...", to_meter="...", name="...">'.
462
- #
463
- # call-seq: inspect -> String
464
- #
465
- def inspect
466
- "#<Proj4::Unit id=\"#{id}\", to_meter=\"#{to_meter}\", name=\"#{name}\">"
467
- end
468
-
469
- end
470
-
471
- end
3
+ # This file is for backwards compatibility to the Proj4 namespace
4
+ require_relative './proj'
472
5
 
6
+ Proj4 = Proj