proj4rb 4.1.1 → 5.0.0

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.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +98 -0
  3. data/Gemfile +4 -4
  4. data/README.md +53 -0
  5. data/lib/api/proj.rb +750 -0
  6. data/lib/api/proj_experimental.rb +7 -0
  7. data/lib/api/proj_ffi.rb +47 -0
  8. data/lib/api/proj_version.rb +26 -0
  9. data/lib/examples/axis_order_normalization.rb +13 -0
  10. data/lib/examples/batch_transformation.rb +25 -0
  11. data/lib/examples/context_logging.rb +26 -0
  12. data/lib/examples/crs_identification.rb +18 -0
  13. data/lib/examples/database_query.rb +27 -0
  14. data/lib/examples/geodetic_distance.rb +38 -0
  15. data/lib/examples/geodetic_to_projected.rb +18 -0
  16. data/lib/examples/operation_factory_context.rb +19 -0
  17. data/lib/examples/pipeline_operator.rb +21 -0
  18. data/lib/examples/promote_demote_3d.rb +23 -0
  19. data/lib/examples/serialization_formats.rb +17 -0
  20. data/lib/examples/transform_bounds.rb +18 -0
  21. data/lib/examples/transformation_with_area.rb +18 -0
  22. data/lib/proj/area.rb +74 -74
  23. data/lib/proj/axis_info.rb +44 -44
  24. data/lib/proj/bounds.rb +22 -0
  25. data/lib/proj/bounds3d.rb +45 -0
  26. data/lib/proj/context.rb +57 -23
  27. data/lib/proj/conversion.rb +94 -91
  28. data/lib/proj/coordinate.rb +304 -281
  29. data/lib/proj/coordinate_metadata.rb +38 -38
  30. data/lib/proj/coordinate_operation_mixin.rb +464 -381
  31. data/lib/proj/coordinate_system.rb +143 -137
  32. data/lib/proj/crs.rb +688 -680
  33. data/lib/proj/crs_info.rb +47 -47
  34. data/lib/proj/database.rb +310 -305
  35. data/lib/proj/datum.rb +32 -32
  36. data/lib/proj/datum_ensemble.rb +34 -34
  37. data/lib/proj/domain.rb +82 -0
  38. data/lib/proj/ellipsoid.rb +77 -77
  39. data/lib/proj/error.rb +7 -8
  40. data/lib/proj/file_api_callbacks.rb +165 -0
  41. data/lib/proj/grid.rb +121 -121
  42. data/lib/proj/grid_cache.rb +65 -64
  43. data/lib/proj/grid_info.rb +19 -19
  44. data/lib/proj/life_span.rb +21 -0
  45. data/lib/proj/network_api_callbacks.rb +86 -0
  46. data/lib/proj/operation.rb +66 -42
  47. data/lib/proj/operation_factory_context.rb +4 -2
  48. data/lib/proj/options.rb +41 -0
  49. data/lib/proj/parameter.rb +37 -37
  50. data/lib/proj/parameters.rb +106 -107
  51. data/lib/proj/pj_axis_description.rb +26 -0
  52. data/lib/proj/pj_object.rb +602 -672
  53. data/lib/proj/pj_objects.rb +45 -45
  54. data/lib/proj/pj_param_description.rb +28 -0
  55. data/lib/proj/prime_meridian.rb +65 -65
  56. data/lib/proj/projection.rb +54 -25
  57. data/lib/proj/session.rb +2 -0
  58. data/lib/proj/transformation.rb +102 -102
  59. data/lib/proj/unit.rb +81 -108
  60. data/lib/proj.rb +10 -3
  61. data/lib/proj4.rb +5 -5
  62. data/proj4rb.gemspec +10 -5
  63. data/test/abstract_test.rb +7 -5
  64. data/test/context_test.rb +210 -172
  65. data/test/context_validation_test.rb +11 -0
  66. data/test/conversion_test.rb +376 -368
  67. data/test/coordinate_metadata_test.rb +34 -0
  68. data/test/coordinate_system_test.rb +162 -144
  69. data/test/coordinate_test.rb +289 -34
  70. data/test/crs_test.rb +1112 -1082
  71. data/test/database_test.rb +407 -391
  72. data/test/datum_ensemble_test.rb +64 -64
  73. data/test/datum_test.rb +61 -54
  74. data/test/domain_test.rb +72 -0
  75. data/test/ellipsoid_test.rb +80 -80
  76. data/test/examples_test.rb +149 -0
  77. data/test/file_api_example.rb +58 -0
  78. data/test/file_api_test.rb +74 -66
  79. data/test/grid_cache_test.rb +72 -72
  80. data/test/grid_test.rb +126 -141
  81. data/test/network_api_example.rb +48 -0
  82. data/test/network_api_test.rb +33 -45
  83. data/test/operation_factory_context_test.rb +225 -205
  84. data/test/operation_test.rb +40 -29
  85. data/test/options_test.rb +17 -0
  86. data/test/parameters_test.rb +86 -40
  87. data/test/pj_object_test.rb +221 -187
  88. data/test/prime_meridian_test.rb +75 -75
  89. data/test/proj_test.rb +58 -58
  90. data/test/projection_test.rb +680 -650
  91. data/test/session_test.rb +78 -77
  92. data/test/transformation_test.rb +238 -210
  93. data/test/unit_test.rb +114 -76
  94. metadata +44 -32
  95. data/ChangeLog +0 -94
  96. data/README.rdoc +0 -189
  97. data/lib/api/api.rb +0 -117
  98. data/lib/api/api_5_0.rb +0 -338
  99. data/lib/api/api_5_1.rb +0 -7
  100. data/lib/api/api_5_2.rb +0 -5
  101. data/lib/api/api_6_0.rb +0 -146
  102. data/lib/api/api_6_1.rb +0 -5
  103. data/lib/api/api_6_2.rb +0 -10
  104. data/lib/api/api_6_3.rb +0 -6
  105. data/lib/api/api_7_0.rb +0 -69
  106. data/lib/api/api_7_1.rb +0 -73
  107. data/lib/api/api_7_2.rb +0 -14
  108. data/lib/api/api_8_0.rb +0 -6
  109. data/lib/api/api_8_1.rb +0 -24
  110. data/lib/api/api_8_2.rb +0 -6
  111. data/lib/api/api_9_1.rb +0 -7
  112. data/lib/api/api_9_2.rb +0 -9
  113. data/lib/api/api_9_4.rb +0 -6
  114. data/lib/api/api_experimental.rb +0 -201
  115. data/lib/proj/file_api.rb +0 -166
  116. data/lib/proj/network_api.rb +0 -92
@@ -1,137 +1,143 @@
1
- # encoding: UTF-8
2
-
3
- module Proj
4
- # Represents a coordinate system for a {Crs CRS}
5
- class CoordinateSystem < PjObject
6
- # Create a CoordinateSystem
7
- #
8
- # @param context [Context] The context associated with the CoordinateSystem
9
- # @param cs_type [PJ_COORDINATE_SYSTEM_TYPE] Coordinate system type
10
- # @param axes [Array<PJ_AXIS_DESCRIPTION>] Array of Axes
11
- #
12
- # @return [CoordinateSystem]
13
- def self.create(cs_type, axes, context)
14
- axes_ptr = FFI::MemoryPointer.new(Api::PJ_AXIS_DESCRIPTION, axes.size)
15
- axes.each_with_index do |axis, i|
16
- axis_description_target = Api::PJ_AXIS_DESCRIPTION.new(axes_ptr[i])
17
- axis_description_source = axis.to_description
18
- axis_description_target.to_ptr.__copy_from__(axis_description_source.to_ptr, Api::PJ_AXIS_DESCRIPTION.size)
19
- end
20
-
21
- pointer = Api.proj_create_cs(context, cs_type, axes.count, axes_ptr)
22
- Error.check_context(context)
23
- self.create_object(pointer, context)
24
- end
25
-
26
- # Create an Ellipsoidal 2D CoordinateSystem
27
- #
28
- # @param context [Context] The context associated with the CoordinateSystem
29
- # @param cs_type [PJ_COORDINATE_SYSTEM_TYPE] Coordinate system type
30
- # @param unit_name [String] Name of the angular units. Or nil for degree
31
- # @param unit_conv_factor [Float] Conversion factor from the angular unit to radian. Set to 0 if unit name is degree
32
- #
33
- # @return [CoordinateSystem]
34
- def self.create_ellipsoidal_2d(cs_type, context, unit_name: nil, unit_conv_factor: 0)
35
- pointer = Api.proj_create_ellipsoidal_2D_cs(context, cs_type, unit_name, unit_conv_factor)
36
- Error.check_context(context)
37
- self.create_object(pointer, context)
38
- end
39
-
40
- # Create an Ellipsoidal 3D CoordinateSystem
41
- #
42
- # @param context [Context] The context associated with the CoordinateSystem
43
- # @param cs_type [PJ_COORDINATE_SYSTEM_TYPE] Coordinate system type
44
- # @param horizontal_angular_unit_name [String] Name of the angular units. Or nil for degree
45
- # @param horizontal_angular_unit_conv_factor [Float] Conversion factor from the angular unit to radian. Set to 0 if horizontal_angular_unit_name name is degree
46
- # @param vertical_linear_unit_name [String] Name of the linear units. Or nil for meters.
47
- # # @param vertical_linear_unit_conv_factor [Float] Conversion factor from the linear unit to meter. Set to 0 if vertical_linear_unit_name is meter.
48
- #
49
- # @return [CoordinateSystem]
50
- def self.create_ellipsoidal_3d(cs_type, context, horizontal_angular_unit_name: nil, horizontal_angular_unit_conv_factor: 0, vertical_linear_unit_name: nil, vertical_linear_unit_conv_factor: 0)
51
- pointer = Api.proj_create_ellipsoidal_3D_cs(context, cs_type, horizontal_angular_unit_name, horizontal_angular_unit_conv_factor, vertical_linear_unit_name, vertical_linear_unit_conv_factor)
52
- Error.check_context(context)
53
- self.create_object(pointer, context)
54
- end
55
-
56
- # Create a CartesiansCS 2D coordinate system
57
- #
58
- # @param context [Context] The context associated with the CoordinateSystem
59
- # @param cs_type [PJ_COORDINATE_SYSTEM_TYPE] Coordinate system type
60
- # @param unit_name [String] Name of the unit. Default is nil.
61
- # @param unit_conv_factor [Float] Unit conversion factor to SI. Default is 0.
62
- #
63
- # @return [CoordinateSystem]
64
- def self.create_cartesian_2d(context, cs_type, unit_name: nil, unit_conv_factor: 0)
65
- pointer = Api.proj_create_cartesian_2D_cs(context, cs_type, unit_name, unit_conv_factor)
66
- Error.check_context(context)
67
- self.create_object(pointer, context)
68
- end
69
-
70
- # Returns the type of the coordinate system
71
- #
72
- # @see https://proj.org/development/reference/functions.html#c.proj_cs_get_type
73
- #
74
- # @return [PJ_COORDINATE_SYSTEM_TYPE]
75
- def cs_type
76
- result = Api.proj_cs_get_type(self.context, self)
77
- if result == :PJ_CS_TYPE_UNKNOWN
78
- Error.check_object(self)
79
- end
80
- result
81
- end
82
-
83
- # Returns the number of axes in the coordinate system
84
- #
85
- # @see https://proj.org/development/reference/functions.html#c.proj_cs_get_axis_count
86
- #
87
- # @return [Integer]
88
- def axis_count
89
- result = Api.proj_cs_get_axis_count(self.context, self)
90
- if result == -1
91
- Error.check_object(self)
92
- end
93
- result
94
- end
95
-
96
- # Returns information about a single axis
97
- #
98
- # @see https://proj.org/development/reference/functions.html#c.proj_cs_get_axis_info
99
- #
100
- # @param index [Integer] Index of the axis
101
- #
102
- # @return [AxisInfo]
103
- def axis_info(index)
104
- p_name = FFI::MemoryPointer.new(:pointer)
105
- p_abbreviation = FFI::MemoryPointer.new(:pointer)
106
- p_direction = FFI::MemoryPointer.new(:pointer)
107
- p_unit_conv_factor = FFI::MemoryPointer.new(:double)
108
- p_unit_name = FFI::MemoryPointer.new(:pointer)
109
- p_unit_auth_name = FFI::MemoryPointer.new(:pointer)
110
- p_unit_code = FFI::MemoryPointer.new(:pointer)
111
-
112
- result = Api.proj_cs_get_axis_info(self.context, self, index,
113
- p_name, p_abbreviation, p_direction, p_unit_conv_factor, p_unit_name, p_unit_auth_name, p_unit_code)
114
-
115
- unless result
116
- Error.check_object(self)
117
- end
118
-
119
- AxisInfo.new(name: p_name.read_pointer.read_string,
120
- abbreviation: p_abbreviation.read_pointer.read_string_to_null,
121
- direction: p_direction.read_pointer.read_string_to_null,
122
- unit_conv_factor: p_unit_conv_factor.read_double,
123
- unit_name: p_unit_name.read_pointer.read_string_to_null,
124
- unit_auth_name: p_unit_auth_name.read_pointer.read_string_to_null,
125
- unit_code: p_unit_code.read_pointer.read_string_to_null)
126
- end
127
-
128
- # Returns information about all axes
129
- #
130
- # @return [Array<AxisInfo>]
131
- def axes
132
- self.axis_count.times.map do |index|
133
- self.axis_info(index)
134
- end
135
- end
136
- end
137
- end
1
+ # encoding: UTF-8
2
+
3
+ module Proj
4
+ # Represents a coordinate system for a {Crs CRS}
5
+ class CoordinateSystem < PjObject
6
+ # Create a CoordinateSystem
7
+ #
8
+ # @param context [Context] The context associated with the CoordinateSystem
9
+ # @param cs_type [PjCoordinateSystemType] Coordinate system type
10
+ # @param axes [Array<PjAxisDescription>] Array of Axes
11
+ #
12
+ # @return [CoordinateSystem]
13
+ def self.create(cs_type, axes, context)
14
+ Error.validate_context!(context)
15
+ axes_ptr = FFI::MemoryPointer.new(Api::PjAxisDescription, axes.size)
16
+ # Keep source descriptions alive so their retained string pointers
17
+ # are not GC'd before proj_create_cs reads them.
18
+ descriptions = axes.map { |axis| axis.to_description }
19
+ descriptions.each_with_index do |axis_description_source, i|
20
+ axis_description_target = Api::PjAxisDescription.new(axes_ptr[i])
21
+ axis_description_target.to_ptr.__copy_from__(axis_description_source.to_ptr, Api::PjAxisDescription.size)
22
+ end
23
+
24
+ pointer = Api.proj_create_cs(context, cs_type, axes.count, axes_ptr)
25
+ Error.check_context(context)
26
+ self.create_object(pointer, context)
27
+ end
28
+
29
+ # Create an Ellipsoidal 2D CoordinateSystem
30
+ #
31
+ # @param context [Context] The context associated with the CoordinateSystem
32
+ # @param cs_type [PjCoordinateSystemType] Coordinate system type
33
+ # @param unit_name [String] Name of the angular units. Or nil for degree
34
+ # @param unit_conv_factor [Float] Conversion factor from the angular unit to radian. Set to 0 if unit name is degree
35
+ #
36
+ # @return [CoordinateSystem]
37
+ def self.create_ellipsoidal_2d(cs_type, context, unit_name: nil, unit_conv_factor: 0)
38
+ Error.validate_context!(context)
39
+ pointer = Api.proj_create_ellipsoidal_2d_cs(context, cs_type, unit_name, unit_conv_factor)
40
+ Error.check_context(context)
41
+ self.create_object(pointer, context)
42
+ end
43
+
44
+ # Create an Ellipsoidal 3D CoordinateSystem
45
+ #
46
+ # @param context [Context] The context associated with the CoordinateSystem
47
+ # @param cs_type [PjCoordinateSystemType] Coordinate system type
48
+ # @param horizontal_angular_unit_name [String] Name of the angular units. Or nil for degree
49
+ # @param horizontal_angular_unit_conv_factor [Float] Conversion factor from the angular unit to radian. Set to 0 if horizontal_angular_unit_name name is degree
50
+ # @param vertical_linear_unit_name [String] Name of the linear units. Or nil for meters.
51
+ # # @param vertical_linear_unit_conv_factor [Float] Conversion factor from the linear unit to meter. Set to 0 if vertical_linear_unit_name is meter.
52
+ #
53
+ # @return [CoordinateSystem]
54
+ def self.create_ellipsoidal_3d(cs_type, context, horizontal_angular_unit_name: nil, horizontal_angular_unit_conv_factor: 0, vertical_linear_unit_name: nil, vertical_linear_unit_conv_factor: 0)
55
+ Error.validate_context!(context)
56
+ pointer = Api.proj_create_ellipsoidal_3d_cs(context, cs_type, horizontal_angular_unit_name, horizontal_angular_unit_conv_factor, vertical_linear_unit_name, vertical_linear_unit_conv_factor)
57
+ Error.check_context(context)
58
+ self.create_object(pointer, context)
59
+ end
60
+
61
+ # Create a CartesiansCS 2D coordinate system
62
+ #
63
+ # @param context [Context] The context associated with the CoordinateSystem
64
+ # @param cs_type [PjCoordinateSystemType] Coordinate system type
65
+ # @param unit_name [String] Name of the unit. Default is nil.
66
+ # @param unit_conv_factor [Float] Unit conversion factor to SI. Default is 0.
67
+ #
68
+ # @return [CoordinateSystem]
69
+ def self.create_cartesian_2d(context, cs_type, unit_name: nil, unit_conv_factor: 0)
70
+ Error.validate_context!(context)
71
+ pointer = Api.proj_create_cartesian_2d_cs(context, cs_type, unit_name, unit_conv_factor)
72
+ Error.check_context(context)
73
+ self.create_object(pointer, context)
74
+ end
75
+
76
+ # Returns the type of the coordinate system
77
+ #
78
+ # @see https://proj.org/development/reference/functions.html#c.proj_cs_get_type
79
+ #
80
+ # @return [PjCoordinateSystemType]
81
+ def cs_type
82
+ result = Api.proj_cs_get_type(self.context, self)
83
+ if result == :PJ_CS_TYPE_UNKNOWN
84
+ Error.check_object(self)
85
+ end
86
+ result
87
+ end
88
+
89
+ # Returns the number of axes in the coordinate system
90
+ #
91
+ # @see https://proj.org/development/reference/functions.html#c.proj_cs_get_axis_count
92
+ #
93
+ # @return [Integer]
94
+ def axis_count
95
+ result = Api.proj_cs_get_axis_count(self.context, self)
96
+ if result == -1
97
+ Error.check_object(self)
98
+ end
99
+ result
100
+ end
101
+
102
+ # Returns information about a single axis
103
+ #
104
+ # @see https://proj.org/development/reference/functions.html#c.proj_cs_get_axis_info
105
+ #
106
+ # @param index [Integer] Index of the axis
107
+ #
108
+ # @return [AxisInfo]
109
+ def axis_info(index)
110
+ p_name = FFI::MemoryPointer.new(:pointer)
111
+ p_abbreviation = FFI::MemoryPointer.new(:pointer)
112
+ p_direction = FFI::MemoryPointer.new(:pointer)
113
+ p_unit_conv_factor = FFI::MemoryPointer.new(:double)
114
+ p_unit_name = FFI::MemoryPointer.new(:pointer)
115
+ p_unit_auth_name = FFI::MemoryPointer.new(:pointer)
116
+ p_unit_code = FFI::MemoryPointer.new(:pointer)
117
+
118
+ result = Api.proj_cs_get_axis_info(self.context, self, index,
119
+ p_name, p_abbreviation, p_direction, p_unit_conv_factor, p_unit_name, p_unit_auth_name, p_unit_code)
120
+
121
+ unless result
122
+ Error.check_object(self)
123
+ end
124
+
125
+ AxisInfo.new(name: p_name.read_pointer.read_string,
126
+ abbreviation: p_abbreviation.read_pointer.read_string_to_null,
127
+ direction: p_direction.read_pointer.read_string_to_null,
128
+ unit_conv_factor: p_unit_conv_factor.read_double,
129
+ unit_name: p_unit_name.read_pointer.read_string_to_null,
130
+ unit_auth_name: p_unit_auth_name.read_pointer.read_string_to_null,
131
+ unit_code: p_unit_code.read_pointer.read_string_to_null)
132
+ end
133
+
134
+ # Returns information about all axes
135
+ #
136
+ # @return [Array<AxisInfo>]
137
+ def axes
138
+ self.axis_count.times.map do |index|
139
+ self.axis_info(index)
140
+ end
141
+ end
142
+ end
143
+ end