proj4rb 2.2.2 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +82 -66
  3. data/Gemfile +4 -4
  4. data/README.rdoc +82 -45
  5. data/lib/api/api.rb +96 -111
  6. data/lib/api/api_5_0.rb +331 -300
  7. data/lib/api/api_5_1.rb +6 -6
  8. data/lib/api/api_5_2.rb +4 -4
  9. data/lib/api/api_6_0.rb +116 -14
  10. data/lib/api/api_6_1.rb +4 -4
  11. data/lib/api/api_6_2.rb +9 -6
  12. data/lib/api/api_6_3.rb +6 -0
  13. data/lib/api/api_7_0.rb +68 -0
  14. data/lib/api/api_7_1.rb +73 -0
  15. data/lib/api/api_7_2.rb +14 -0
  16. data/lib/api/api_8_0.rb +6 -0
  17. data/lib/api/api_8_1.rb +24 -0
  18. data/lib/api/api_8_2.rb +6 -0
  19. data/lib/api/api_9_1.rb +7 -0
  20. data/lib/api/api_9_2.rb +9 -0
  21. data/lib/api/api_experimental.rb +196 -0
  22. data/lib/proj/area.rb +73 -0
  23. data/lib/proj/axis_info.rb +44 -0
  24. data/lib/proj/bounds.rb +13 -0
  25. data/lib/proj/context.rb +249 -0
  26. data/lib/proj/conversion.rb +92 -0
  27. data/lib/{coordinate.rb → proj/coordinate.rb} +281 -197
  28. data/lib/proj/coordinate_operation_mixin.rb +381 -0
  29. data/lib/proj/coordinate_system.rb +137 -0
  30. data/lib/proj/crs.rb +672 -0
  31. data/lib/proj/crs_info.rb +47 -0
  32. data/lib/proj/database.rb +305 -0
  33. data/lib/proj/datum.rb +32 -0
  34. data/lib/proj/datum_ensemble.rb +34 -0
  35. data/lib/proj/ellipsoid.rb +78 -0
  36. data/lib/proj/error.rb +71 -0
  37. data/lib/proj/file_api.rb +166 -0
  38. data/lib/proj/grid.rb +121 -0
  39. data/lib/proj/grid_cache.rb +64 -0
  40. data/lib/proj/grid_info.rb +19 -0
  41. data/lib/proj/network_api.rb +92 -0
  42. data/lib/{operation.rb → proj/operation.rb} +42 -42
  43. data/lib/proj/operation_factory_context.rb +136 -0
  44. data/lib/proj/parameter.rb +38 -0
  45. data/lib/proj/parameters.rb +106 -0
  46. data/lib/proj/pj_object.rb +670 -0
  47. data/lib/proj/pj_objects.rb +44 -0
  48. data/lib/proj/prime_meridian.rb +66 -0
  49. data/lib/proj/projection.rb +698 -0
  50. data/lib/proj/session.rb +46 -0
  51. data/lib/proj/strings.rb +32 -0
  52. data/lib/proj/transformation.rb +102 -0
  53. data/lib/proj/unit.rb +109 -0
  54. data/lib/proj.rb +118 -17
  55. data/proj4rb.gemspec +32 -32
  56. data/test/abstract_test.rb +29 -7
  57. data/test/context_test.rb +172 -82
  58. data/test/conversion_test.rb +368 -0
  59. data/test/coordinate_system_test.rb +144 -0
  60. data/test/coordinate_test.rb +34 -34
  61. data/test/crs_test.rb +1071 -372
  62. data/test/database_test.rb +360 -0
  63. data/test/datum_ensemble_test.rb +65 -0
  64. data/test/datum_test.rb +55 -0
  65. data/test/ellipsoid_test.rb +80 -34
  66. data/test/file_api_test.rb +66 -0
  67. data/test/grid_cache_test.rb +72 -0
  68. data/test/grid_test.rb +141 -0
  69. data/test/network_api_test.rb +45 -0
  70. data/test/operation_factory_context_test.rb +201 -0
  71. data/test/operation_test.rb +29 -29
  72. data/test/parameters_test.rb +40 -0
  73. data/test/pj_object_test.rb +179 -0
  74. data/test/prime_meridian_test.rb +76 -0
  75. data/test/proj_test.rb +58 -16
  76. data/test/projection_test.rb +650 -224
  77. data/test/session_test.rb +78 -0
  78. data/test/transformation_test.rb +209 -67
  79. data/test/unit_test.rb +76 -47
  80. metadata +67 -29
  81. data/lib/api/api_4_9.rb +0 -31
  82. data/lib/area.rb +0 -32
  83. data/lib/config.rb +0 -70
  84. data/lib/context.rb +0 -103
  85. data/lib/crs.rb +0 -204
  86. data/lib/ellipsoid.rb +0 -42
  87. data/lib/error.rb +0 -18
  88. data/lib/pj_object.rb +0 -80
  89. data/lib/point.rb +0 -72
  90. data/lib/prime_meridian.rb +0 -40
  91. data/lib/projection.rb +0 -207
  92. data/lib/transformation.rb +0 -61
  93. data/lib/unit.rb +0 -54
  94. data/test/prime_meridians_test.rb +0 -33
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec1833a8b87e9d94521de30e1179f81f6cf04896c1200ce1949df372ed68b3c9
4
- data.tar.gz: 192835632d10989b94df05a038c17595c4735787bb6a0d8dde7edb55a60e0948
3
+ metadata.gz: 0d9e88b214716f78e690e7265c6a9edc9e2c9c77cbb6e40c32883eec61320cc5
4
+ data.tar.gz: 4102575947ce82e7fdc40d6feeb37bb4b34f024dbfeda66fe20a1909b4a93ccd
5
5
  SHA512:
6
- metadata.gz: 8dd8fa60741b1db78714fd63c496d33ad07439c7bf248bdffee0ecbe96f299dcb6527dc22eb014c8ee3024ae91094ebad3cb39df293438a759e704aa818677dc
7
- data.tar.gz: 252a6e5efd3fd85f136a281dc69d82f9993d630b0c5b7d4fbfe67739af1dd7cb19d4c863deb81dd8a5ec0a7c71c45cdcedfe8092feba267b85775eb77013bcae
6
+ metadata.gz: 87926009a11eb4a4d71cedcd79a4d72b8196e57df4ac7b59cb28c6b75da5635b89291fa564a1153fb4d2cd5cd910e5ff2c489695177aac54d5a6302a90d1cb26
7
+ data.tar.gz: 412e2777701a836b9b7d76f00e0e8526a5488711adf10051ea34f9603999a25d290d74b073d2e0f7940e68efc210c416f5a14b6f74e01e4572883caafe620738
data/ChangeLog CHANGED
@@ -1,67 +1,83 @@
1
- 2.2.2 (January 10, 2020)
2
- =========================
3
- * Move proj_context_set_autoclose_database to api 6.2 (Jan Klimke)
4
- * Improve search path generation code (Charlie Savage)
5
-
6
- 2.2.1 (January 8, 2020)
7
- =========================
8
- * Move proj_as_projjson from version 6.0 to 6.2 api (Charlie Savage)
9
- * Improve search path generation code (Charlie Savage)
10
-
11
- 2.2.0 (January 7, 2020)
12
- =========================
13
- * Fix broken gem - was not including all api files (Jan Klimke)
14
- * Add paths on MacOS when using Brew (Jan Klimke)
15
- * Various code cleanups (Charlie Savage)
16
-
17
- 2.1.0 (January 5, 2020)
18
- =========================
19
- * Set Ruby 2.4.1 to be the minimum allowed version (Samuel Williams)
20
- * Fix incorrect use of context, reduce warnings when running tests (Samuel Williams)
21
- * Fix `bundle exec rake test` (Samuel Williams)
22
- * Add 2.4.1 to the travis test matrix (Samuel Williams)
23
-
24
- 2.0.0 (December 30, 2019)
25
- =========================
26
- - Full rewrite to support API changes in Proj versions 5 and 6 (Charlie Savage)
27
- - As part of rewrite switch bindings to use FFI versus a C extension (Charlie Savage)
28
- - Split Ruby code into multiple files based on classes (Charlie Savage)
29
- - Add in a bunch of new classes including Context, Crs, Coordinate, Ellipsoid, Prime Meridian and Transform (Charlie Savage)
30
- - Deprecate Projection and Point - these will stop working with Proj 7 since the use an older deprecated API (Charlie Savage)
31
-
32
- 1.0.0 (December 14, 2014)
33
- =========================
34
- - Calling this 1.0.0 since its a very stable gem (Charlie Savage)
35
-
36
- 0.4.3 (August 30, 2011)
37
- =========================
38
- - Remove reference to now private projects.h header
39
-
40
- 0.4.2 (August 15, 2011)
41
- =========================
42
- - Minor build tweak to support MSVC++
43
-
44
- 0.4.1 (July 30, 2011)
45
- =========================
46
- - Search first for binaries when using windows gems
47
- - Add # encoding to test files
48
- - Reformat tests files to use standard ruby 2 space indenting
49
-
50
- 0.4.0 (July 30, 2011)
51
- =========================
52
- - Update to compile on Ruby 1.9.* (Fabio Renzo Panettieri)
53
- - Add in gemspec file (Charlie Savage)
54
- - Add rake-compiler as development dependency, remove older MinGW build system (Charlie Savage)
55
- - Move to GitHub (Charlie Savage)
56
-
57
- 0.3.1 (December 23, 2009)
58
- =========================
59
- - Update extconf.conf file to be more flexible to make it easier to build
60
- on OS X when using MacPorts
61
- - Updated windows binary to link against proj4.7
62
-
63
- 0.3.0 (August 14, 2008)
64
- =========================
65
- - Removed Proj4::UV class which was previously deprecated
66
- - New build infrastructure for Windows (Charlie Savage)
1
+ 4.0.0 - March 12, 2023
2
+ ======================
3
+ * Support Proj 9
4
+ * Add support for missing APIs - the gem now provides almost 100% coverage
5
+ * Add support for Proj experimental APIs including the creation of projection conversions
6
+ * Add/updated support for a number of ISO 19111 classes, including PrimeMeridian, Ellipsoid,
7
+ Datum, DatumEnsemble, CoordinateOperation and Parameters
8
+ * Greatly improved documentation (https://rubydoc.info/github/cfis/proj4rb)
9
+ * Remove old Proj 4.9 support
10
+ * Note this release does have some API changes. These include the removal of Proj 4.9 Point and Coordinate classes, changes to the PrimeMeridian class and changes to the Ellipsoid class. These changes should not impact most users.
11
+
12
+ 3.0.0 - September 26, 2021
13
+ =========================
14
+ * Support Proj 8 which removes the old Proj API (Charlie Savage)
15
+ * Support newer versions of FFI which remove support for returning strings from callbacks (Charlie Savage)
16
+
17
+ 2.2.2 - January 10, 2020
18
+ =========================
19
+ * Move proj_context_set_autoclose_database to api 6.2 - Jan Klimke)
20
+ * Improve search path generation code (Charlie Savage)
21
+
22
+ 2.2.1 - January 8, 2020
23
+ =========================
24
+ * Move proj_as_projjson from version 6.0 to 6.2 api (Charlie Savage)
25
+ * Improve search path generation code (Charlie Savage)
26
+
27
+ 2.2.0 - January 7, 2020
28
+ =========================
29
+ * Fix broken gem - was not including all api files (Jan Klimke)
30
+ * Add paths on MacOS when using Brew (Jan Klimke)
31
+ * Various code cleanups (Charlie Savage)
32
+
33
+ 2.1.0 - January 5, 2020
34
+ =========================
35
+ * Set Ruby 2.4.1 to be the minimum allowed version (Samuel Williams)
36
+ * Fix incorrect use of context, reduce warnings when running tests (Samuel Williams)
37
+ * Fix `bundle exec rake test` (Samuel Williams)
38
+ * Add 2.4.1 to the travis test matrix (Samuel Williams)
39
+
40
+ 2.0.0 - December 30, 2019
41
+ =========================
42
+ - Full rewrite to support API changes in Proj versions 5 and 6 - Charlie Savage)
43
+ - As part of rewrite switch bindings to use FFI versus a C extension (Charlie Savage)
44
+ - Split Ruby code into multiple files based on classes (Charlie Savage)
45
+ - Add in a bunch of new classes including Context, Crs, Coordinate, Ellipsoid, Prime Meridian and Transform (Charlie Savage)
46
+ - Deprecate Projection and Point - these will stop working with Proj 7 since the use an older deprecated API (Charlie Savage)
47
+
48
+ 1.0.0 - December 14, 2014
49
+ =========================
50
+ - Calling this 1.0.0 since its a very stable gem (Charlie Savage)
51
+
52
+ 0.4.3 - August 30, 2011
53
+ =========================
54
+ - Remove reference to now private projects.h header
55
+
56
+ 0.4.2 - August 15, 2011
57
+ =========================
58
+ - Minor build tweak to support MSVC++
59
+
60
+ 0.4.1 - July 30, 2011
61
+ =========================
62
+ - Search first for binaries when using windows gems
63
+ - Add # encoding to test files
64
+ - Reformat tests files to use standard ruby 2 space indenting
65
+
66
+ 0.4.0 - July 30, 2011
67
+ =========================
68
+ - Update to compile on Ruby 1.9.* (Fabio Renzo Panettieri)
69
+ - Add in gemspec file (Charlie Savage)
70
+ - Add rake-compiler as development dependency, remove older MinGW build system (Charlie Savage)
71
+ - Move to GitHub (Charlie Savage)
72
+
73
+ 0.3.1 - December 23, 2009
74
+ =========================
75
+ - Update extconf.conf file to be more flexible to make it easier to build
76
+ on OS X when using MacPorts
77
+ - Updated windows binary to link against proj4.7
78
+
79
+ 0.3.0 - August 14, 2008
80
+ =========================
81
+ - Removed Proj4::UV class which was previously deprecated
82
+ - New build infrastructure for Windows (Charlie Savage)
67
83
  - Fixed memory leaks in forward() and inverse() methods (Charlie Savage)
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in tensorflow-ruby.gemspec
4
- gemspec
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in tensorflow-ruby.gemspec
4
+ gemspec
data/README.rdoc CHANGED
@@ -3,7 +3,9 @@ This gem provides Ruby bindings for the Proj Library (https://proj.org). The Pro
3
3
  between a number of different coordinate systems and projections.
4
4
 
5
5
  == Documentation
6
- Besides this readme file, reference documentation is available at https://rubydoc.info/github/cfis/proj4rb.
6
+ Reference documentation is available at https://rubydoc.info/github/cfis/proj4rb.
7
+
8
+ Examples can be found in this README file as well as in the {file:Examples.rdoc Examples} file. In addition, the test suite has exapmles of calling almost every API so when in doubt take a look at them!
7
9
 
8
10
  == Installation
9
11
  First install the gem in the usual manner:
@@ -23,9 +25,9 @@ If you are using the old Proj4 namespace, then you can do this:
23
25
 
24
26
  require 'proj4'
25
27
 
26
- === Crs
27
- If you are using Proj 6 create a coordinate system. To create a coordinate system, you can use CRS codes, well-known text (WKT) strings
28
- or old-style Proj4 strings (which are deprecated).
28
+ === CRS
29
+ To create a coordinate system, you can use CRS codes, well-known text (WKT) strings
30
+ or old-style Proj strings (which are deprecated).
29
31
 
30
32
  crs1 = Proj::Crs.new('EPSG:4326')
31
33
 
@@ -64,14 +66,14 @@ After you have created two coordinate systems, you can then create a transformat
64
66
  convert coordinates from the "3-degree Gauss-Kruger zone 3" coordinate system to WGS84 (one version of lat-long)
65
67
  first create a transformation:
66
68
 
67
- crs_gk = Proj::Crs.new('epsg:31467')
68
- crs_wgs84 = Proj::Crs.new('epsg:4326')
69
+ crs_gk = Proj::Crs.new('EPSG:31467')
70
+ crs_wgs84 = Proj::Crs.new('EPSG:4326')
69
71
  transform = Proj::Transformation.new(crs_gk, crs_wgs84)
70
72
 
71
73
  Alternatively, or if you are using Proj 5, you can create a transformation without first
72
74
  creating Crs instances. Instead, pass the EPSG information directly to the transformation:
73
75
 
74
- transform = Proj::Transformation.new('epsg:31467', 'epsg:4326')
76
+ transform = Proj::Transformation.new('EPSG:31467', 'EPSG:4326')
75
77
 
76
78
  Once you've created the transformation, you can tranform coordinates using either
77
79
  the +forward+ or +inverse+ methods. The forward transformation looks like this:
@@ -94,6 +96,25 @@ While the inverse transformation looks like this:
94
96
  assert_in_delta(0, to.z, 0.01)
95
97
  assert_in_delta(0, to.t, 0.01)
96
98
 
99
+ === Coordinate Operations
100
+ Transformations are a type of Coordinate Operation. PROJ divides coordinate operations into three groups:
101
+
102
+ * Conversions
103
+ * Projections
104
+ * Transformations
105
+
106
+ Conversions are coordinate operations that do not exert a change in reference frame. The Ruby bindings support these via the Conversion class. See https://proj.org/operations/conversions/index.html for more information.
107
+
108
+ Projections are cartographic mappings of the sphere onto the plane. Technically projections are conversions (according to ISO standards), but PROJ distinguishes them from conversions. The Ruby bindings support these
109
+ via the Projection module which has methods to create many common projections. A list can be found at https://proj.org/operations/projections/index.html.
110
+
111
+ Transformations are coordinate operations that do cause a change in reference frames. The Ruby bindings support these via the Transformation class.
112
+
113
+ For more information see https://proj.org/operations/index.html
114
+
115
+ === Operation Factory
116
+ The OperationFactoryContext class can be used to build coordinate operations between two CRSes. This is done by first creating a factory and setting appropiate filters. These include spatial filters, accuracy filters, grid availability filters, etc. Once filters are set, then the factory can be queried for a list of possible conversions. For examples, please see the operation_factory_context_test.rb file.
117
+
97
118
  === Coordinate
98
119
  Notice the examples above transform Coordinate objects. A Coordinate consists
99
120
  of up to four double values to represent three directions plus time. In general
@@ -104,6 +125,21 @@ you will need to fill out at least the first two values:
104
125
 
105
126
  Lam is longitude and phi is latitude.
106
127
 
128
+ === Axis Order
129
+ By default tranformations accept coordinates expressed in the units and axis order of the source CRS and return transformed coordinates in the units and axis order of the target CRS.
130
+
131
+ For most geographic CRSes, the units will be in degrees. For geographic CRSes defined by the EPSG authority, the order of coordinates is latitude and then longitude.
132
+
133
+ For projected CRSes, the units will vary (metre, us-foot, etc.). For projected CRS defined by the EPSG authority, and with EAST / NORTH directions, the order might may be east and then north or north and then east.
134
+
135
+ If you prefer to work with a uniform axis order, regardless of the axis orders mandated by the source and target CRSes, then call the Context#normalize_for_visualization method:
136
+
137
+ normalized = transform.normalize_for_visualization
138
+
139
+ The normalized transformation will return output coordinates in longitude, latitude order for geographic CRSes and easting, northing for most projected CRSes.
140
+
141
+ For more information see {https://proj.org/faq.html#why-is-the-axis-ordering-in-proj-not-consistent Why Is The Axis Ordering In Proj Not Consistent?}
142
+
107
143
  === Context
108
144
  Contexts are used to support multi-threaded programs. The bindings expose this object via Context.current
109
145
  and store it using thread local storage. Use the context object to access error codes, set proj4
@@ -112,49 +148,50 @@ compatability settings, set the logging level and to install custom logging code
112
148
  Both Crs and Transformation objects take a context object in their constructors. If none is passed, they default
113
149
  to using Context.current
114
150
 
115
- === Projection
116
- If you are using Proj 4, then instead of using Coordinates, Crses and Tranformations you need to us Points and Projections.
117
- Those are deprecated classes but will continue to work until the release of Proj 7. Please refer to the documentation
118
- for more information.
151
+ == Network Access
152
+ Proj supports downloading grid files on demand if network access is enabled (it is disabled by default). To enable network use the method {Context#network_enabled=}. To specify the url endpoint use {Context#url=}. Advanced users can replace Proj's networking code, which uses libcurl, with their own implementation. To do this see the NetworkApi class.
153
+
154
+ Downloaded grids are cached in a sqlite file named cache.db. To specify the location, size and other characteristics of the cache file refer to the {GridCache} class which is accessible via Context#cache. By default the cache size is 300MB. Caching is on by default but can be disabled via GridCache#enabled=.
119
155
 
120
156
  == Error handling
121
157
  When an error occurs, a Proj::Error instance will be thrown with the underlying message provided
122
158
  from the Proj library.
123
159
 
124
- == Finding Proj Files (LIB_PROJ)
160
+ == Finding Proj Library (PROJ_LIB_PATH)
161
+ proj4rb will search in a number of well-known locations for the libproj shared library. You
162
+ can override this by specifying the full path to the library using the PROJ_LIB_PATH
163
+ environmental variable.
164
+
165
+ == Finding Proj Files (PROJ_DATA)
125
166
  Starting with version 6, Proj stores its information (datums, ellipsoids, prime meridians, coordinate systems,
126
- units, etc) in a sqlite file called proj.db. If Proj cannot find its database, then the Ruby bindings will
127
- search for it in some well-known locations. Failing that, the Ruby bindings will raise an exception.
128
- In this case, set the environmental variable PROJ_LIB to point at the folder that contains the proj.db file.
129
- Note PROJ_LIB must be set by whatever launches your Ruby program. The Ruby program itself cannot set this
130
- variable and have it work correctly (at least not on windows).
131
-
132
- == Backwards Compatibility
133
- Proj versions 5 and 6 are *very* different than Proj version 4. Changes are documented at
134
- https://proj.org/development/migration.html. Note that the gem should gracefully degrade
135
- (as in newer functionality stops working but older functionality keeps working) depending on
136
- the version of Proj you are using.
137
-
138
- To ensure backwards compatiblity, the Ruby bindings still include the older Point and Projection
139
- classes. However, these classes are no longer documented in this Readme because they will be
140
- removed upon the release of Proj 7 which will remove the underlying API's they depend on.
141
- So please port your code! But take note of the changes in Proj 6 described below.
142
-
143
- Proj 5 introduced the Coordinate, Crs and Tranformation APIs. However, it wasn't until Proj 6 that additional
144
- metadata APIs were added, so the amount of information about each object is somewhat limited in Proj 5.
145
-
146
- Proj 6 makes a big change compared to previous releases that is not well documented (see
147
- https://github.com/OSGeo/PROJ/pull/1182). When creating tranformations with EPSG values Proj 6
148
- will assume EPSG axis order and units (typically lat-long degree for geodetic CRS). First,
149
- this means that lat-long should usually be specified in degrees and not radians (breaking change one).
150
- Second, the axis order is likely different than what your previous code assumed (breaking change two).
151
- Note if creating transformations with the deprecated "+init=epsg:XXXX" values, Proj 6 will assume the traditional
152
- axis order and units (long-lat radians for geodetic CRS).
153
-
154
- Bottom line - when porting your code to the new Proj 6 APIs generally:
155
-
156
- * Use degrees, not radians
157
- * Swap the order of the lat and long values
167
+ units, etc) in a sqlite file called proj.db. If Proj cannot find its database an exception will be
168
+ raised. In this case, you can set the environmental variable PROJ_DATA to point to the folder that
169
+ contains the proj.db file. Note PROJ_LIB must be set by whatever launches your Ruby program.
170
+ The Ruby program itself cannot set this variable and have it work correctly (at least not on windows).
171
+
172
+ For more information see https://proj.org/resource_files.html
173
+
174
+ == Class Hierarchy
175
+ The proj4rb class hierarchy is based on Proj's class hiearchy which, in turn, is derived from {http://docs.opengeospatial.org/as/18-005r5/18-005r5.html ISO 19111:2019}. It is:
176
+
177
+ PjObject
178
+ CoordinateOperationMixin
179
+ Conversion
180
+ Transformation
181
+ CoordinateSystem
182
+ Crs
183
+ Datum
184
+ Ellipsoid
185
+ PrimeMerdian
186
+
187
+ The PjObject class defines several methods to create new objects:
188
+
189
+ * PjObject.create
190
+ * PjObject.create_from_database
191
+ * PjObject.create_from_name
192
+ * PjObject.create_from_wkt
193
+
194
+ The methods will return instances of the correct subclass.
158
195
 
159
196
  == Tests
160
197
  Proj4rb ships with a full test suite designed to work using Proj 6. If you are using an earlier version of Proj,
@@ -163,7 +200,7 @@ then expect *many* test failures.
163
200
  == License
164
201
  Proj4rb is released under the MIT license.
165
202
 
166
- ==Authors
203
+ == Authors
167
204
  The proj4rb Ruby bindings were started by Guilhem Vellut with most of the code
168
205
  written by Jochen Topf. Charlie Savage ported the code to Windows and added
169
206
  the Windows build infrastructure. Later, he rewrote the code to support
data/lib/api/api.rb CHANGED
@@ -1,111 +1,96 @@
1
- require 'rbconfig'
2
- require 'ffi'
3
-
4
- module Proj
5
- module Api
6
- extend FFI::Library
7
-
8
- def self.library_versions
9
- [17, # 6.2 *and* 6.1
10
- 15, # 6.0
11
- 14, # 5.2
12
- 13, # 5.0
13
- 12, # 4.9
14
- 11] # 4.9
15
- end
16
-
17
- def self.search_paths
18
- result = case RbConfig::CONFIG['host_os']
19
- when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
20
- self.windows_search_paths
21
- when /darwin|mac os/
22
- self.macos_search_paths
23
- else
24
- self.linux_search_paths
25
- end
26
-
27
- result << 'libproj'
28
- result
29
- end
30
-
31
- def self.windows_search_paths
32
- self.library_versions.map do |version|
33
- "libproj-#{version}"
34
- end
35
- end
36
-
37
- def self.linux_search_paths
38
- self.library_versions.map do |version|
39
- "libproj.so.#{version}"
40
- end
41
- end
42
-
43
- def self.macos_search_paths
44
- # Mac Ports
45
- paths1 = self.library_versions.map do |version|
46
- case version
47
- when 15..17
48
- "/opt/local/lib/proj6/lib/libproj.#{version}.dylib"
49
- when 13..14
50
- "/opt/local/lib/proj5/lib/libproj.#{version}.dylib"
51
- when 11..12
52
- "/opt/local/lib/proj49/lib/libproj.#{version}.dylib"
53
- end
54
- end
55
-
56
- # Mac HomeBrew
57
- paths2 = self.library_versions.map do |version|
58
- "/usr/local/lib/libproj.#{version}.dylib"
59
- end
60
-
61
- paths1 + paths2
62
- end
63
-
64
- ffi_lib self.search_paths
65
-
66
- # Load the old deprecated api - supported by all Proj versions (until Proj 7!)
67
- require_relative './api_4_9'
68
-
69
- library = ffi_libraries.first
70
-
71
- # proj_info was introduced in Proj 5
72
- if library.find_function('proj_info')
73
- require_relative './api_5_0'
74
- PROJ_VERSION = Gem::Version.new(self.proj_info[:version])
75
- else
76
- release = self.pj_get_release
77
- version = release.match(/\d\.\d\.\d/)
78
- PROJ_VERSION = Gem::Version.new(version)
79
- end
80
- end
81
-
82
- if Api::PROJ_VERSION < Gem::Version.new('5.0.0')
83
- def Api.proj_torad(value)
84
- value * 0.017453292519943296
85
- end
86
-
87
- def Api.proj_todeg(value)
88
- value * 57.295779513082321
89
- end
90
- end
91
-
92
- if Api::PROJ_VERSION >= Gem::Version.new('5.1.0')
93
- require_relative './api_5_1'
94
- end
95
-
96
- if Api::PROJ_VERSION >= Gem::Version.new('5.2.0')
97
- require_relative './api_5_2'
98
- end
99
-
100
- if Api::PROJ_VERSION >= Gem::Version.new('6.0.0')
101
- require_relative './api_6_0'
102
- end
103
-
104
- if Api::PROJ_VERSION >= Gem::Version.new('6.1.0')
105
- require_relative './api_6_1'
106
- end
107
-
108
- if Api::PROJ_VERSION >= Gem::Version.new('6.2.0')
109
- require_relative './api_6_2'
110
- end
111
- end
1
+ require 'rbconfig'
2
+ require 'ffi'
3
+
4
+ module Proj
5
+ module Api
6
+ extend FFI::Library
7
+
8
+ def self.library_versions
9
+ ["25", # 9.2
10
+ "9_1", # 9.1
11
+ "22", # 8.0 and 8.1
12
+ "19", # 7.x
13
+ "17", # 6.1 *and* 6.2
14
+ "15", # 6.0
15
+ "14", # 5.2
16
+ "13", # 5.0
17
+ "12", # 4.9
18
+ "11"] # 4.9
19
+ end
20
+
21
+ def self.search_paths
22
+ result = case RbConfig::CONFIG['host_os']
23
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
24
+ self.windows_search_paths
25
+ when /darwin|mac os/
26
+ self.macos_search_paths
27
+ else
28
+ self.linux_search_paths
29
+ end
30
+
31
+ # Try libproj as catch all
32
+ result << 'libproj'
33
+ result
34
+ end
35
+
36
+ def self.windows_search_paths
37
+ self.library_versions.map do |version|
38
+ ["libproj-#{version}", "libproj_#{version}"]
39
+ end.flatten
40
+ end
41
+
42
+ def self.linux_search_paths
43
+ self.library_versions.map do |version|
44
+ "libproj.so.#{version}"
45
+ end
46
+ end
47
+
48
+ def self.macos_search_paths
49
+ # On MacOS only support HomeBrew since the MacPort is unsupported and ancient (5.2).
50
+ self.library_versions.map do |version|
51
+ "libproj.#{version}.dylib"
52
+ end
53
+ end
54
+
55
+ def self.load_library
56
+ if ENV["PROJ_LIB_PATH"]
57
+ ffi_lib ENV["PROJ_LIB_PATH"]
58
+ else
59
+ ffi_lib self.search_paths
60
+ end
61
+
62
+ ffi_libraries.first
63
+ end
64
+
65
+ def self.load_api
66
+ # First load the base 5.0 api so we can determine the Proj Version
67
+ require_relative './api_5_0'
68
+ Api.const_set('PROJ_VERSION', Gem::Version.new(self.proj_info[:version]))
69
+
70
+ # Now load the rest of the apis based on the proj version
71
+ versions = ['5.1.0', '5.2.0',
72
+ '6.0.0', '6.1.0', '6.2.0', '6.3.0',
73
+ '7.0.0', '7.1.0', '7.2.0',
74
+ '8.0.0', '8.1.0', '8.2.0',
75
+ '9.1.0', '9.2.0']
76
+
77
+ versions.each do |version|
78
+ api_version = Gem::Version.new(version)
79
+
80
+ if PROJ_VERSION >= api_version
81
+ require_relative "./api_#{api_version.segments[0]}_#{api_version.segments[1]}"
82
+ end
83
+ end
84
+
85
+ # Add in the experimental api
86
+ require_relative "./api_experimental"
87
+ end
88
+
89
+ # Load the library
90
+ load_library
91
+
92
+ # Load the api
93
+ load_api
94
+ end
95
+ end
96
+