Class: Proj::Database
- Inherits:
-
Object
- Object
- Proj::Database
- Defined in:
- lib/proj/database.rb
Overview
This class provides access the Proj SQLite database called proj.db. The database stores transformation information that must be accessible for the library to work properly.
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
-
#authorities ⇒ Array<Strings>
Return a list of authorities used in the database.
-
#celestial_bodies(authority = nil) ⇒ Array<CelestialBody>
Returns a list of celestial bodies from the database.
-
#celestial_body_name(object) ⇒ String
Return the name of the celestial body of the specified object.
-
#codes(auth_name, pj_type, allow_deprecated = false) ⇒ Strings
Returns the set of authority codes of the given object type.
-
#crs_info(auth_name = nil, parameters = nil) ⇒ Array<CrsInfo>
Enumerate CRS infos from the database, taking into account various criteria.
-
#geoid_models(authority, code) ⇒ Strings
Returns a list of geoid models available.
-
#grid(name) ⇒ Grid
Returns information about a Grid from the database.
-
#initialize(context) ⇒ Database
constructor
Create a new database instance to query the Proj database.
-
#metadata(key) ⇒ String
Return a metadata from the database.
-
#path ⇒ Object
Returns the path the Proj database.
-
#path=(value) ⇒ Database
Sets the path to the Proj database.
-
#structure ⇒ Array<Strings>
Returns SQL statements to run to initiate a new valid auxiliary empty database.
-
#suggest_code_for(object, authority, numeric_code) ⇒ String
Suggests a database code for the specified object.
-
#unit(auth_name, code) ⇒ Unit
Returns information for a unit of measure from a database lookup.
-
#units(auth_name: nil, category: nil, allow_deprecated: false) ⇒ Array<Unit>
Returns a list of units from the database.
Constructor Details
#initialize(context) ⇒ Database
Create a new database instance to query the Proj database
16 17 18 |
# File 'lib/proj/database.rb', line 16 def initialize(context) @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
9 10 11 |
# File 'lib/proj/database.rb', line 9 def context @context end |
Instance Method Details
#authorities ⇒ Array<Strings>
Return a list of authorities used in the database
101 102 103 104 |
# File 'lib/proj/database.rb', line 101 def ptr = Api.(self.context) Strings.new(ptr) end |
#celestial_bodies(authority = nil) ⇒ Array<CelestialBody>
Returns a list of celestial bodies from the database
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/proj/database.rb', line 193 def celestial_bodies( = nil) out_result_count = FFI::MemoryPointer.new(:int) ptr = Api.proj_get_celestial_body_list_from_database(self.context, , out_result_count) body_ptrs = ptr.read_array_of_pointer(out_result_count.read_int) result = body_ptrs.map do |body_ptr| # First read the pointer to a structure struct = Api::ProjCelestialBodyInfo.new(body_ptr) # Now map this to a Ruby Struct CelestialBody.new(struct[:auth_name], struct[:name]) end Api.proj_celestial_body_list_destroy(ptr) result end |
#celestial_body_name(object) ⇒ String
Return the name of the celestial body of the specified object.
218 219 220 |
# File 'lib/proj/database.rb', line 218 def celestial_body_name(object) Api.proj_get_celestial_body_name(self.context, object) end |
#codes(auth_name, pj_type, allow_deprecated = false) ⇒ Strings
Returns the set of authority codes of the given object type.
91 92 93 94 |
# File 'lib/proj/database.rb', line 91 def codes(auth_name, pj_type, allow_deprecated = false) ptr = Api.proj_get_codes_from_database(self.context, auth_name, pj_type, allow_deprecated ? 1 : 0) Strings.new(ptr) end |
#crs_info(auth_name = nil, parameters = nil) ⇒ Array<CrsInfo>
Enumerate CRS infos from the database, taking into account various criteria.
114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/proj/database.rb', line 114 def crs_info(auth_name = nil, parameters = nil) out_result_count = FFI::MemoryPointer.new(:int) ptr = Api.proj_get_crs_info_list_from_database(self.context, auth_name, parameters, out_result_count) result = out_result_count.read_int.times.map do |index| index_ptr = ptr + (index * FFI::Pointer::SIZE) struct = Api::PROJ_CRS_INFO.new(index_ptr.read_pointer) CrsInfo.from_proj_crs_info(struct) end Api.proj_crs_info_list_destroy(ptr) result end |
#geoid_models(authority, code) ⇒ Strings
Returns a list of geoid models available
181 182 183 184 |
# File 'lib/proj/database.rb', line 181 def geoid_models(, code) ptr = Api.proj_get_geoid_models_from_database(self.context, , code, nil) Strings.new(ptr) end |
#grid(name) ⇒ Grid
Returns information about a Grid from the database
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/proj/database.rb', line 135 def grid(name) out_full_name = FFI::MemoryPointer.new(:string) out_package_name = FFI::MemoryPointer.new(:string) out_url = FFI::MemoryPointer.new(:string) out_downloadable = FFI::MemoryPointer.new(:int) out_open_license = FFI::MemoryPointer.new(:int) out_available = FFI::MemoryPointer.new(:int) result = Api.proj_grid_get_info_from_database(self.context, name, out_full_name, out_package_name, out_url, out_downloadable, out_open_license, out_available) if result == 1 full_name_ptr = out_full_name.read_pointer package_name_ptr = out_package_name.read_pointer url_ptr = out_url.read_pointer downloadable_ptr = out_downloadable open_license_ptr = out_open_license available_ptr = out_available full_name = full_name_ptr.read_string_to_null package_name = package_name_ptr.read_string_to_null url = url_ptr.read_string_to_null downloadable = downloadable_ptr.read_int == 1 ? true : false open_license = open_license_ptr.read_int == 1 ? true : false available = available_ptr.read_int == 1 ? true : false Grid.new(name, self.context, full_name: full_name, package_name: package_name, url: url ? URI(url) : nil, downloadable: downloadable, open_license: open_license, available: available) else Error.check_context(self.context) end end |
#metadata(key) ⇒ String
Return a metadata from the database.
78 79 80 |
# File 'lib/proj/database.rb', line 78 def (key) Api.(self.context, key) end |
#path ⇒ Object
Returns the path the Proj database
return [String]
25 26 27 28 29 |
# File 'lib/proj/database.rb', line 25 def path if Api.method_defined?(:proj_context_get_database_path) Api.proj_context_get_database_path(self.context) end end |
#path=(value) ⇒ Database
Sets the path to the Proj database
38 39 40 41 42 43 44 |
# File 'lib/proj/database.rb', line 38 def path=(value) result = Api.proj_context_set_database_path(self.context, value, nil, nil) unless result == 1 Error.check_context(self.context) end self end |
#structure ⇒ Array<Strings>
Returns SQL statements to run to initiate a new valid auxiliary empty database.
51 52 53 54 |
# File 'lib/proj/database.rb', line 51 def structure ptr = Api.proj_context_get_database_structure(self.context, nil) Strings.new(ptr) end |
#suggest_code_for(object, authority, numeric_code) ⇒ String
Suggests a database code for the specified object.
231 232 233 234 235 236 |
# File 'lib/proj/database.rb', line 231 def suggest_code_for(object, , numeric_code) ptr = Api.proj_suggests_code_for(self.context, object, , numeric_code ? 1 : 0, nil) result = ptr.read_string_to_null Api.proj_string_destroy(ptr) result end |
#unit(auth_name, code) ⇒ Unit
Returns information for a unit of measure from a database lookup
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/proj/database.rb', line 282 def unit(auth_name, code) out_name = FFI::MemoryPointer.new(:string) out_conv_factor = FFI::MemoryPointer.new(:double) out_category = FFI::MemoryPointer.new(:string) result = Api.proj_uom_get_info_from_database(self.context, auth_name, code, out_name, out_conv_factor , out_category) if result == 1 name_ptr = out_name.read_pointer conv_factor_ptr = out_conv_factor category_ptr = out_category.read_pointer name = name_ptr.read_string_to_null conv_factor = conv_factor_ptr.read_double category = category_ptr.read_string_to_null Unit.new(auth_name, code, name, category, conv_factor, nil, false) else Error.check_context(self.context) end end |
#units(auth_name: nil, category: nil, allow_deprecated: false) ⇒ Array<Unit>
Returns a list of units from the database
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/proj/database.rb', line 247 def units(auth_name: nil, category: nil, allow_deprecated: false) # Create pointer to read the count output parameter out_result_count = FFI::MemoryPointer.new(:int) # Result is an array of pointers to structures pp_units = Api.proj_get_units_from_database(Context.current, auth_name, category, allow_deprecated ? 1 : 0, out_result_count) count = out_result_count.read(:int) array_p_units = pp_units.read_array_of_pointer(count) result = Array.new(count) count.times do |i| unit_info = Api::PROJ_UNIT_INFO.new(array_p_units[i]) result[i] = Unit.new(unit_info[:auth_name], unit_info[:code], unit_info[:name], unit_info[:category], unit_info[:conv_factor], unit_info[:proj_short_name], unit_info[:deprecated]) end Api.proj_unit_list_destroy(pp_units) result end |