proj4rb 0.4.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/MIT-LICENSE +9 -0
  2. data/README.rdoc +163 -0
  3. data/Rakefile +72 -0
  4. data/data/GL27 +22 -0
  5. data/data/MD +0 -0
  6. data/data/TN +0 -0
  7. data/data/WI +0 -0
  8. data/data/WO +0 -0
  9. data/data/conus +0 -0
  10. data/data/epsg +5443 -0
  11. data/data/epsg-deprecated +2 -0
  12. data/data/esri +5937 -0
  13. data/data/esri.extra +948 -0
  14. data/data/hawaii +0 -0
  15. data/data/nad.lst +142 -0
  16. data/data/nad27 +809 -0
  17. data/data/nad83 +744 -0
  18. data/data/ntv1_can.dat +0 -0
  19. data/data/null +0 -0
  20. data/data/other.extra +49 -0
  21. data/data/proj_def.dat +17 -0
  22. data/data/prvi +0 -0
  23. data/data/stgeorge +0 -0
  24. data/data/stlrnc +0 -0
  25. data/data/stpaul +0 -0
  26. data/data/world +212 -0
  27. data/example/basic.rb +18 -0
  28. data/example/list-datums.rb +17 -0
  29. data/example/list-ellipsoids.rb +17 -0
  30. data/example/list-errors.rb +11 -0
  31. data/example/list-prime-meridians.rb +17 -0
  32. data/example/list-projection-types.rb +17 -0
  33. data/example/list-units.rb +17 -0
  34. data/example/version.rb +8 -0
  35. data/ext/Makefile +212 -0
  36. data/ext/extconf.rb +13 -0
  37. data/ext/mkmf.log +25 -0
  38. data/ext/projrb.c +560 -0
  39. data/ext/vc/proj4_ruby.sln +19 -0
  40. data/ext/vc/proj4_ruby.vcproj +208 -0
  41. data/lib/1.8/proj4_ruby.so +0 -0
  42. data/lib/1.9/proj4_ruby.so +0 -0
  43. data/lib/proj4.rb +466 -0
  44. data/test/test_constants.rb +20 -0
  45. data/test/test_create_projection.rb +64 -0
  46. data/test/test_datums.rb +44 -0
  47. data/test/test_ellipsoids.rb +45 -0
  48. data/test/test_errors.rb +70 -0
  49. data/test/test_init_projection.rb +108 -0
  50. data/test/test_prime_meridians.rb +44 -0
  51. data/test/test_projection_type.rb +43 -0
  52. data/test/test_simple_projection.rb +57 -0
  53. data/test/test_transform.rb +114 -0
  54. data/test/test_units.rb +45 -0
  55. metadata +145 -0
@@ -0,0 +1,19 @@
1
+ Microsoft Visual Studio Solution File, Format Version 10.00
2
+ # Visual Studio 2008
3
+ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "proj4_ruby", "proj4_ruby.vcproj", "{DDB3E992-BF4B-4413-B061-288E40AECAD3}"
4
+ EndProject
5
+ Global
6
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
7
+ Debug|Win32 = Debug|Win32
8
+ Release|Win32 = Release|Win32
9
+ EndGlobalSection
10
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
11
+ {DDB3E992-BF4B-4413-B061-288E40AECAD3}.Debug|Win32.ActiveCfg = Debug|Win32
12
+ {DDB3E992-BF4B-4413-B061-288E40AECAD3}.Debug|Win32.Build.0 = Debug|Win32
13
+ {DDB3E992-BF4B-4413-B061-288E40AECAD3}.Release|Win32.ActiveCfg = Release|Win32
14
+ {DDB3E992-BF4B-4413-B061-288E40AECAD3}.Release|Win32.Build.0 = Release|Win32
15
+ EndGlobalSection
16
+ GlobalSection(SolutionProperties) = preSolution
17
+ HideSolutionNode = FALSE
18
+ EndGlobalSection
19
+ EndGlobal
@@ -0,0 +1,208 @@
1
+ <?xml version="1.0" encoding="Windows-1252"?>
2
+ <VisualStudioProject
3
+ ProjectType="Visual C++"
4
+ Version="9.00"
5
+ Name="proj4_ruby"
6
+ ProjectGUID="{DDB3E992-BF4B-4413-B061-288E40AECAD3}"
7
+ RootNamespace="proj4rb"
8
+ Keyword="Win32Proj"
9
+ TargetFrameworkVersion="131072"
10
+ >
11
+ <Platforms>
12
+ <Platform
13
+ Name="Win32"
14
+ />
15
+ </Platforms>
16
+ <ToolFiles>
17
+ </ToolFiles>
18
+ <Configurations>
19
+ <Configuration
20
+ Name="Debug|Win32"
21
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
22
+ IntermediateDirectory="$(ConfigurationName)"
23
+ ConfigurationType="2"
24
+ CharacterSet="1"
25
+ >
26
+ <Tool
27
+ Name="VCPreBuildEventTool"
28
+ />
29
+ <Tool
30
+ Name="VCCustomBuildTool"
31
+ />
32
+ <Tool
33
+ Name="VCXMLDataGeneratorTool"
34
+ />
35
+ <Tool
36
+ Name="VCWebServiceProxyGeneratorTool"
37
+ />
38
+ <Tool
39
+ Name="VCMIDLTool"
40
+ />
41
+ <Tool
42
+ Name="VCCLCompilerTool"
43
+ Optimization="0"
44
+ AdditionalIncludeDirectories="&quot;C:\Development\ruby\lib\ruby\1.8\i386-mswin32&quot;;C:\Development\msys\local\include"
45
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;RUBYPROF_EXPORTS"
46
+ MinimalRebuild="true"
47
+ BasicRuntimeChecks="3"
48
+ RuntimeLibrary="3"
49
+ StructMemberAlignment="0"
50
+ UsePrecompiledHeader="0"
51
+ BrowseInformation="0"
52
+ WarningLevel="3"
53
+ Detect64BitPortabilityProblems="true"
54
+ DebugInformationFormat="4"
55
+ CallingConvention="0"
56
+ />
57
+ <Tool
58
+ Name="VCManagedResourceCompilerTool"
59
+ />
60
+ <Tool
61
+ Name="VCResourceCompilerTool"
62
+ />
63
+ <Tool
64
+ Name="VCPreLinkEventTool"
65
+ />
66
+ <Tool
67
+ Name="VCLinkerTool"
68
+ AdditionalDependencies="msvcrt-ruby18.lib libproj.lib"
69
+ OutputFile="C:\Development\ruby\lib\ruby\gems\1.8\gems\proj4rb-0.3.0-x86-mswin32-60\lib\$(ProjectName).so"
70
+ LinkIncremental="2"
71
+ AdditionalLibraryDirectories="C:\Development\msys\local\lib;C:\Development\ruby\lib"
72
+ ModuleDefinitionFile=""
73
+ GenerateDebugInformation="true"
74
+ SubSystem="2"
75
+ RandomizedBaseAddress="1"
76
+ DataExecutionPrevention="0"
77
+ TargetMachine="1"
78
+ />
79
+ <Tool
80
+ Name="VCALinkTool"
81
+ />
82
+ <Tool
83
+ Name="VCManifestTool"
84
+ />
85
+ <Tool
86
+ Name="VCXDCMakeTool"
87
+ />
88
+ <Tool
89
+ Name="VCBscMakeTool"
90
+ />
91
+ <Tool
92
+ Name="VCFxCopTool"
93
+ />
94
+ <Tool
95
+ Name="VCAppVerifierTool"
96
+ />
97
+ <Tool
98
+ Name="VCPostBuildEventTool"
99
+ />
100
+ </Configuration>
101
+ <Configuration
102
+ Name="Release|Win32"
103
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
104
+ IntermediateDirectory="$(ConfigurationName)"
105
+ ConfigurationType="2"
106
+ CharacterSet="1"
107
+ WholeProgramOptimization="1"
108
+ >
109
+ <Tool
110
+ Name="VCPreBuildEventTool"
111
+ />
112
+ <Tool
113
+ Name="VCCustomBuildTool"
114
+ />
115
+ <Tool
116
+ Name="VCXMLDataGeneratorTool"
117
+ />
118
+ <Tool
119
+ Name="VCWebServiceProxyGeneratorTool"
120
+ />
121
+ <Tool
122
+ Name="VCMIDLTool"
123
+ />
124
+ <Tool
125
+ Name="VCCLCompilerTool"
126
+ AdditionalIncludeDirectories="C:\Development\ruby\lib\ruby\1.8\i386-mswin32"
127
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;RUBYPROF_EXPORTS"
128
+ RuntimeLibrary="2"
129
+ UsePrecompiledHeader="0"
130
+ WarningLevel="3"
131
+ Detect64BitPortabilityProblems="true"
132
+ DebugInformationFormat="3"
133
+ />
134
+ <Tool
135
+ Name="VCManagedResourceCompilerTool"
136
+ />
137
+ <Tool
138
+ Name="VCResourceCompilerTool"
139
+ />
140
+ <Tool
141
+ Name="VCPreLinkEventTool"
142
+ />
143
+ <Tool
144
+ Name="VCLinkerTool"
145
+ AdditionalDependencies="msvcrt-ruby18.lib"
146
+ OutputFile="$(OutDir)\$(ProjectName).so"
147
+ LinkIncremental="1"
148
+ AdditionalLibraryDirectories="C:\Development\ruby\lib"
149
+ GenerateDebugInformation="true"
150
+ SubSystem="2"
151
+ OptimizeReferences="2"
152
+ EnableCOMDATFolding="2"
153
+ RandomizedBaseAddress="1"
154
+ DataExecutionPrevention="0"
155
+ TargetMachine="1"
156
+ />
157
+ <Tool
158
+ Name="VCALinkTool"
159
+ />
160
+ <Tool
161
+ Name="VCManifestTool"
162
+ />
163
+ <Tool
164
+ Name="VCXDCMakeTool"
165
+ />
166
+ <Tool
167
+ Name="VCBscMakeTool"
168
+ />
169
+ <Tool
170
+ Name="VCFxCopTool"
171
+ />
172
+ <Tool
173
+ Name="VCAppVerifierTool"
174
+ />
175
+ <Tool
176
+ Name="VCPostBuildEventTool"
177
+ />
178
+ </Configuration>
179
+ </Configurations>
180
+ <References>
181
+ </References>
182
+ <Files>
183
+ <Filter
184
+ Name="Source Files"
185
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
186
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
187
+ >
188
+ <File
189
+ RelativePath="..\projrb.c"
190
+ >
191
+ </File>
192
+ </Filter>
193
+ <Filter
194
+ Name="Header Files"
195
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
196
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
197
+ >
198
+ </Filter>
199
+ <Filter
200
+ Name="Resource Files"
201
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
202
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
203
+ >
204
+ </Filter>
205
+ </Files>
206
+ <Globals>
207
+ </Globals>
208
+ </VisualStudioProject>
Binary file
Binary file
data/lib/proj4.rb ADDED
@@ -0,0 +1,466 @@
1
+
2
+ if File.exists?(File.dirname(__FILE__ + '/../data'))
3
+ ENV['PROJ_LIB'] = File.dirname(__FILE__) + '/../data'
4
+ end
5
+
6
+ require 'proj4_ruby'
7
+
8
+ # Ruby bindings for the Proj.4 cartographic projection library (http://trac.osgeo.org/proj/).
9
+ module Proj4
10
+
11
+ # Base class for all Proj.4 exceptions. Subclasses with the name <errorname>Error are available for each exception.
12
+ class Error < StandardError
13
+
14
+ # List of all Proj.4 errors.
15
+ #--
16
+ # (This list is created from the one in pj_strerrno.c in the Proj.4 distribution.)
17
+ #++
18
+ 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}
19
+
20
+ # Return list of all errors.
21
+ #
22
+ # call-seq: list -> Array
23
+ #
24
+ def self.list
25
+ ERRORS
26
+ end
27
+
28
+ # Return name of error with given number.
29
+ #
30
+ # call-seq: error(errnum) -> String
31
+ #
32
+ def self.error(errnum)
33
+ ERRORS[errnum.abs] || 'Unknown'
34
+ end
35
+
36
+ # Raise an error with error number +errnum+.
37
+ def self.raise_error(errnum)
38
+ raise eval("#{error(errnum.abs)}Error"), message(-(errnum.abs)), caller[0..-1]
39
+ end
40
+
41
+ # Return error number of this error.
42
+ def errnum
43
+ self.class.errnum
44
+ end
45
+
46
+ end
47
+
48
+ Error.list.each_with_index do |err, index|
49
+ eval "class #{err}Error < Error;
50
+ def self.errnum;
51
+ #{index};
52
+ end;
53
+ end"
54
+ end
55
+
56
+ # The Projection class represents a geographical projection.
57
+ #
58
+ # = Creating a new projection object
59
+ #
60
+ # Projection objects are created through the new method as usual. Depending on the kind of projection, many
61
+ # different parameters are needed. Please consult the documentation of the Proj.4 C library at http://trac.osgeo.org/proj/
62
+ # for details.
63
+ #
64
+ # There are several ways of specifying the parameters:
65
+ #
66
+ # [<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.
67
+ #
68
+ # proj = Projection.new "+proj=utm +zone=21 +units=m"
69
+ #
70
+ # [<b>as an Array:</b>] An array with each parameter as a member in the array in '[+]key=value' format.
71
+ #
72
+ # proj = Projection.new [ "proj=utm", "zone=21", "units=m" ]
73
+ #
74
+ # [<b>as a Hash:</b>] A hash with strings or symbols as keys.
75
+ #
76
+ # proj = Projection.new( "proj" => "utm", "zone" => "21", "units" => "m" )
77
+ # proj = Projection.new( :proj => "utm", :zone => "21", :units => "m" )
78
+ #
79
+ # With all variants the plus sign in front of the keys is optional.
80
+ #
81
+ # = Using a projection object to project points
82
+ #
83
+ # There are two ways a projection can be used: Through the +forward+ and +inverse+ methods (with all their variants)
84
+ # you can do projection from longitudes and latitudes into the coordinate system used by the projection and back.
85
+ # These projections are always 2D, i.e. you need and get lon/lat or x/y coordinates.
86
+ #
87
+ # The alternative is the +transform+ method (with all its variants) which is used to transform 3D points from one
88
+ # projection and datum to another. In addition to the x/y coordinates the transform method also reads and returns
89
+ # a z coordinate.
90
+ #
91
+ # = Versions of the projection methods
92
+ #
93
+ # All three projection methods (+forward+, +inverse+, and +transform+) work on points. Every method has an in-place
94
+ # version (with a name ending in !) which changes the given point and a normal version which first creates a copy of
95
+ # the point object and changes and returns that. All methods use radians when reading or returning points. For
96
+ # convenience there are also +forwardDeg+ and +inverseDeg+ methods (and in-place versions <tt>forwardDeg!</tt>
97
+ # and <tt>inverseDeg!</tt>) that will work with degrees.
98
+ #
99
+ # = Points
100
+ #
101
+ # All projection method project points to other points. You can use objects of the Proj4::Point class for this or
102
+ # any other object which supports the x, y, z read and write accessor methods. (In fact you don't even need the
103
+ # z accessor methods, 0 is assumed if they don't exist.)
104
+ #
105
+ # Some projection methods act on the given point in-place, other return a copy of the point object. But in any case
106
+ # all other attributes of the point object are retained.
107
+ #
108
+ # = Projection collections
109
+ #
110
+ # The methods forward_all, inverse_all, and transform_all (and their in-place versions forward_all!,
111
+ # inverse_all!, and transform_all! work just like their simple counterparts, but instead of a single
112
+ # point they convert a collection of points in one go.
113
+ #
114
+ # These methods all take an array as an argument or any object responding to the +each+ method (for the in-place versions)
115
+ # or +each+, +clear+, and <tt><<</tt> methods (for the normal version).
116
+ #
117
+ # Some projection methods act on the given collection in-place, i.e. the collection is not touched and all points
118
+ # in the collection will be projected in-place. The other methods act on a copy of the collection and on copies
119
+ # of each point in the collection. So you'll get back a brand new copy of the collection with new copies of the
120
+ # points with the projected coordinates. In any case all other attributes of the collection and points are retained.
121
+ #
122
+ class Projection
123
+
124
+ private
125
+
126
+ def self._parse_init_parameters(args)
127
+ case args
128
+ when Array
129
+ args.collect{ |a| a.sub(/^\+/, '') }
130
+ when String
131
+ args.strip.split(' ').collect{ |a| a.sub(/^\+/, '')}
132
+ when Hash
133
+ array = []
134
+ args.each_pair{ | key, value | array << (value.nil? ? key.to_s : "#{key}=#{value}") }
135
+ array
136
+ when Proj4::Projection
137
+ args.getDef.strip.split(' ').collect{ |a| a.sub(/^\+/, '')}
138
+ else
139
+ raise ArgumentError, "Unknown type #{args.class} for projection definition"
140
+ end
141
+ end
142
+
143
+ public
144
+
145
+ # Get the ID of this projection.
146
+ #
147
+ # call-seq: projection -> String
148
+ #
149
+ def projection
150
+ getDef =~ /\+proj=(.+?) / ? $1 : nil
151
+ end
152
+
153
+ # Get the ID of the datum used in this projection.
154
+ #
155
+ # call-seq: datum -> String
156
+ #
157
+ def datum
158
+ getDef =~ /\+datum=(.+?) / ? $1 : nil
159
+ end
160
+
161
+ # Get definition of projection in typical inspect format (#<Proj4::Projection +init=... +proj=... ...>).
162
+ #
163
+ # call-seq: to_s -> String
164
+ #
165
+ def to_s
166
+ "#<Proj4::Projection#{ getDef }>"
167
+ end
168
+
169
+ # Forward projection of a point. Returns a copy of the point object with coordinates projected.
170
+ #
171
+ # call-seq: forward(point) -> point
172
+ #
173
+ def forward(point)
174
+ forward!(point.dup)
175
+ end
176
+
177
+ # Convenience function for calculating a forward projection with degrees instead of radians.
178
+ #
179
+ # call-seq: forwardDeg(point) -> point
180
+ #
181
+ def forwardDeg(point)
182
+ forwardDeg!(point.dup)
183
+ end
184
+
185
+ # Convenience function for calculating a forward projection with degrees instead of radians.
186
+ # This version works in-place, i.e. the point objects content is overwritten.
187
+ #
188
+ # call-seq: forwardDeg!(point) -> point
189
+ #
190
+ def forwardDeg!(point)
191
+ point.x *= Proj4::DEG_TO_RAD
192
+ point.y *= Proj4::DEG_TO_RAD
193
+ forward!(point)
194
+ end
195
+
196
+ # Project all points in a collection 'in place'.
197
+ # The +collection+ object must implement the +each+
198
+ # method for this to work.
199
+ #
200
+ # call-seq: forward_all!(collection) -> collection
201
+ #
202
+ def forward_all!(collection)
203
+ collection.each do |point|
204
+ forward!(point)
205
+ end
206
+ collection
207
+ end
208
+
209
+ # Projects all points in a collection.
210
+ # The +collection+ object must implement the +each+,
211
+ # +clear+, and << methods (just like an Array) for this to work.
212
+ #
213
+ # call-seq: forward_all(collection) -> collection
214
+ #
215
+ def forward_all(collection)
216
+ newcollection = collection.dup.clear
217
+ collection.each do |point|
218
+ newcollection << forward(point)
219
+ end
220
+ newcollection
221
+ end
222
+
223
+ # Inverse projection of a point. Returns a copy of the point object with coordinates projected.
224
+ #
225
+ # call-seq: inverse(point) -> point
226
+ #
227
+ def inverse(point)
228
+ inverse!(point.dup)
229
+ end
230
+
231
+ # Convenience function for calculating an inverse projection with the result in degrees instead of radians.
232
+ #
233
+ # call-seq: inverseDeg(point) -> point
234
+ #
235
+ def inverseDeg(point)
236
+ inverseDeg!(point.dup)
237
+ end
238
+
239
+ # Convenience function for calculating an inverse projection with the result in degrees instead of radians.
240
+ # This version works in-place, i.e. the point objects content is overwritten.
241
+ #
242
+ # call-seq: inverseDeg!(point) -> point
243
+ #
244
+ def inverseDeg!(point)
245
+ inverse!(point)
246
+ point.x *= Proj4::RAD_TO_DEG
247
+ point.y *= Proj4::RAD_TO_DEG
248
+ point
249
+ end
250
+
251
+ # Project all points in a collection 'in place'.
252
+ # The +collection+ object must implement the +each+
253
+ # method for this to work.
254
+ #
255
+ # call-seq: inverse_all!(collection) -> collection
256
+ #
257
+ def inverse_all!(collection)
258
+ collection.each do |point|
259
+ inverse!(point)
260
+ end
261
+ collection
262
+ end
263
+
264
+ # Projects all points in a collection.
265
+ # The +collection+ object must implement the +each+,
266
+ # +clear+, and << methods (just like an Array) for this to work.
267
+ #
268
+ # call-seq: inverse_all(collection) -> collection
269
+ #
270
+ def inverse_all(collection)
271
+ newcollection = collection.dup.clear
272
+ collection.each do |point|
273
+ newcollection << inverse(point)
274
+ end
275
+ newcollection
276
+ end
277
+
278
+ # Transforms a point from one projection to another.
279
+ #
280
+ # call-seq: transform(destinationProjection, point) -> point
281
+ #
282
+ def transform(otherProjection, point)
283
+ transform!(otherProjection, point.dup)
284
+ end
285
+
286
+ # Transforms all points in a collection 'in place' from one projection
287
+ # to another. The +collection+ object must implement the +each+
288
+ # method for this to work.
289
+ #
290
+ # call-seq: transform_all!(destinationProjection, collection) -> collection
291
+ #
292
+ def transform_all!(otherProjection, collection)
293
+ collection.each do |point|
294
+ transform!(otherProjection, point)
295
+ end
296
+ collection
297
+ end
298
+
299
+ # Transforms all points in a collection from one projection to
300
+ # another. The +collection+ object must implement the +each+,
301
+ # +clear+, and << methods (just like an Array) for this to work.
302
+ #
303
+ # call-seq: transform_all(destinationProjection, collection) -> collection
304
+ #
305
+ def transform_all(otherProjection, collection)
306
+ newcollection = collection.dup.clear
307
+ collection.each do |point|
308
+ newcollection << transform(otherProjection, point)
309
+ end
310
+ newcollection
311
+ end
312
+
313
+ end
314
+
315
+ # This class represents a point in either lon/lat or projected x/y coordinates.
316
+ class Point
317
+
318
+ # X coordinate or longitude
319
+ attr_accessor :x
320
+
321
+ # Y coordinate or latitude
322
+ attr_accessor :y
323
+
324
+ # Z coordinate (height)
325
+ attr_accessor :z
326
+
327
+ # Create new Proj4::Point object from coordinates.
328
+ def initialize(x, y, z=0)
329
+ @x = x
330
+ @y = y
331
+ @z = z
332
+ end
333
+
334
+ # Get longitude/x coordinate.
335
+ def lon
336
+ x
337
+ end
338
+
339
+ # Get latitude/y coordinate.
340
+ def lat
341
+ y
342
+ end
343
+
344
+ # Set longitude/x coordinate.
345
+ def lon=(lon)
346
+ @x = lon
347
+ end
348
+
349
+ # Set latitude/y coordinate.
350
+ def lat=(lat)
351
+ @y = lat
352
+ end
353
+
354
+ end
355
+
356
+ # Abstract base class for several types of definitions: Proj4::Datum, Proj4::Ellipsoid, Proj4::PrimeMeridian, Proj4::ProjectionType, Proj4::Unit.
357
+ #
358
+ # Note that these classes only work if the version of the Proj.4 C library used is at least 449.
359
+ class Def
360
+
361
+ # Initialize function raises error. Definitions are always defined by the underlying Proj.4 library, you can't create them yourself.
362
+ def initialize # :nodoc:
363
+ raise TypeError, "You can't created objects of this type yourself."
364
+ end
365
+
366
+ # Get the definition with given id.
367
+ def self.get(id)
368
+ self.list.select{ |u| u.id == id }.first
369
+ end
370
+
371
+ # Compares definitions by comparing ids.
372
+ #
373
+ # call-seq: one == other -> true or false
374
+ #
375
+ def ==(other)
376
+ self.id == other.id
377
+ end
378
+
379
+ # Compares definitions by comparing ids.
380
+ #
381
+ # call-seq: one <=> other -> -1, 0, 1
382
+ #
383
+ def <=>(other)
384
+ self.id <=> other.id
385
+ end
386
+
387
+ # Stringify definition. Returns ID of this definition.
388
+ #
389
+ # call-seq: to_s -> String
390
+ #
391
+ def to_s
392
+ id
393
+ end
394
+
395
+ end
396
+
397
+ class Datum < Def
398
+
399
+ # Returns datum definition as string in format '#<Proj4::Datum id="...", ellipse_id="...", defn="...", comments="...">'.
400
+ #
401
+ # call-seq: inspect -> String
402
+ #
403
+ def inspect
404
+ "#<Proj4::Datum id=\"#{id}\", ellipse_id=\"#{ellipse_id}\", defn=\"#{defn}\", comments=\"#{comments}\">"
405
+ end
406
+
407
+ end
408
+
409
+ class Ellipsoid < Def
410
+
411
+ # Returns ellipsoid definition as string in format '#<Proj4::Ellipsoid id="...", major="...", ell="...", name="...">'.
412
+ #
413
+ # call-seq: inspect -> String
414
+ #
415
+ def inspect
416
+ "#<Proj4::Ellipsoid id=\"#{id}\", major=\"#{major}\", ell=\"#{ell}\", name=\"#{name}\">"
417
+ end
418
+
419
+ end
420
+
421
+ class PrimeMeridian < Def
422
+
423
+ # Returns a prime meridian definition as string in format '#<Proj4::PrimeMeridian id="...", defn="...">'.
424
+ #
425
+ # call-seq: inspect -> String
426
+ #
427
+ def inspect
428
+ "#<Proj4::PrimeMeridian id=\"#{id}\", defn=\"#{defn}\">"
429
+ end
430
+
431
+ end
432
+
433
+ class ProjectionType < Def
434
+
435
+ # Returns a projection type as string in format '#<Proj4::PrimeMeridian id="...", name="...">'.
436
+ #
437
+ # call-seq: inspect -> String
438
+ #
439
+ def inspect
440
+ "#<Proj4::ProjectionType id=\"#{id}\", name=\"#{name}\">"
441
+ end
442
+
443
+ # Gets name of this projection type.
444
+ #
445
+ # call-seq: name -> String
446
+ #
447
+ def name
448
+ descr.sub(/\n.*/m, '')
449
+ end
450
+
451
+ end
452
+
453
+ class Unit < Def
454
+
455
+ # Returns unit definition as string in format '#<Proj4::Unit id="...", to_meter="...", name="...">'.
456
+ #
457
+ # call-seq: inspect -> String
458
+ #
459
+ def inspect
460
+ "#<Proj4::Unit id=\"#{id}\", to_meter=\"#{to_meter}\", name=\"#{name}\">"
461
+ end
462
+
463
+ end
464
+
465
+ end
466
+