Class: Proj::Conversion
- Includes:
- CoordinateOperationMixin
- Defined in:
- lib/proj/conversion.rb
Overview
Conversions are coordinate operations that convert a source coordinate to a new value. In Proj they are defined as operations that do not exert a change in reference frame while {Transformation transformations } do.
Class Method Summary collapse
-
.create_conversion(context, name:, auth_name:, code:, method_name:, method_auth_name:, method_code:, params:) ⇒ Conversion
Create a Transformation.
Instance Method Summary collapse
-
#convert_to_other_method(new_method_epsg_code: nil, new_method_name: nil) ⇒ Conversion
Return an equivalent projection.
-
#initialize(value, context = nil) ⇒ Conversion
constructor
Instantiates an conversion from a string.
Methods included from CoordinateOperationMixin
#accuracy, #ballpark_transformation?, #create_inverse, #forward, #grid, #grid_count, #instantiable?, #inverse, #last_used_operation, #method_auth_name, #method_code, #method_name, #normalize_for_visualization, #param, #param_count, #param_index, #roundtrip, #step, #step_count, #to_wgs84, #transform, #transform_array, #transform_bounds
Methods inherited from PjObject
#accuracy, #angular_input?, #angular_output?, #area_of_use, #auth, #auth_name, #context, #context=, create, create_from_database, create_from_name, create_from_wkt, #definition, #degree_input?, #degree_output?, #deprecated?, #description, #equivalent_to?, #errno, #errorno, #factors, #geod_distance, #has_inverse?, #id, #id_code, #info, #initialize_copy, #lp_distance, #lpz_distance, #name, #non_deprecated, #proj_type, #remarks, #scope, #source_crs, #target_crs, #to_json, #to_proj_string, #to_ptr, #to_s, #to_wkt, #xy_distance, #xyz_distance
Constructor Details
#initialize(value, context = nil) ⇒ Conversion
Instantiates an conversion from a string. The string can be:
-
proj-string,
-
WKT string,
-
object code (like “EPSG:4326”, “urn:ogc:def:crs:EPSG::4326”, “urn:ogc:def:coordinateOperation:EPSG::1671”),
-
Object name. e.g “WGS 84”, “WGS 84 / UTM zone 31N”. In that case as uniqueness is not guaranteed, heuristics are applied to determine the appropriate best match.
-
OGC URN combining references for compound coordinate reference systems (e.g “urn:ogc:def:crs,crs:EPSG::2393,crs:EPSG::5717” or custom abbreviated syntax “EPSG:2393+5717”),
-
OGC URN combining references for concatenated operations (e.g. “urn:ogc:def:coordinateOperation,coordinateOperation:EPSG::3895,coordinateOperation:EPSG::1618”)
-
PROJJSON string. The jsonschema is at proj.org/schemas/v0.4/projjson.schema.json (added in 6.2)
-
compound CRS made from two object names separated with “ + ”. e.g. “WGS 84 + EGM96 height” (added in 7.1)
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/proj/conversion.rb', line 54 def initialize(value, context=nil) context ||= Context.current ptr = Api.proj_create(context, value) if ptr.null? Error.check_context(context) end if Api.method_defined?(:proj_is_crs) && Api.proj_is_crs(ptr) raise(Error, "Invalid conversion. Proj created an instance of: #{self.proj_type}.") end super(ptr, context) end |
Class Method Details
.create_conversion(context, name:, auth_name:, code:, method_name:, method_auth_name:, method_code:, params:) ⇒ Conversion
Create a Transformation
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/proj/conversion.rb', line 25 def self.create_conversion(context, name:, auth_name:, code:, method_name:, method_auth_name:, method_code:, params:) params_ptr = FFI::MemoryPointer.new(Api::PJ_PARAM_DESCRIPTION, params.size) params.each_with_index do |param, i| param_description_target = Api::PJ_PARAM_DESCRIPTION.new(params_ptr[i]) param_description_source = param.to_description param_description_target.to_ptr.__copy_from__(param_description_source.to_ptr, Api::PJ_PARAM_DESCRIPTION.size) end pointer = Api.proj_create_conversion(context, name, auth_name, code, method_name, method_auth_name, method_code, params.size, params_ptr) Error.check_context(context) self.create_object(pointer, context) end |
Instance Method Details
#convert_to_other_method(new_method_epsg_code: nil, new_method_name: nil) ⇒ Conversion
Return an equivalent projection. Currently implemented:
-
EPSG_CODE_METHOD_MERCATOR_VARIANT_A (1SP) to EPSG_CODE_METHOD_MERCATOR_VARIANT_B (2SP)
-
EPSG_CODE_METHOD_MERCATOR_VARIANT_B (2SP) to EPSG_CODE_METHOD_MERCATOR_VARIANT_A (1SP)
-
EPSG_CODE_METHOD_LAMBERT_CONIC_CONFORMAL_1SP to EPSG_CODE_METHOD_LAMBERT_CONIC_CONFORMAL_2SP
-
EPSG_CODE_METHOD_LAMBERT_CONIC_CONFORMAL_2SP to EPSG_CODE_METHOD_LAMBERT_CONIC_CONFORMAL_1SP
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/proj/conversion.rb', line 79 def convert_to_other_method(new_method_epsg_code: nil, new_method_name: nil) ptr = Api.proj_convert_conversion_to_other_method(self.context, self, new_method_epsg_code ? new_method_epsg_code: 0, new_method_name) if ptr.null? Error.check_context(context) end self.class.create_object(ptr, context) end |