Class: Proj::CoordinateSystem

Inherits:
PjObject
  • Object
show all
Defined in:
lib/proj/coordinate_system.rb

Overview

Represents a coordinate system for a CRS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PjObject

#accuracy, #angular_input?, #angular_output?, #area_of_use, #auth, #auth_name, #context, #context=, 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, #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

This class inherits a constructor from Proj::PjObject

Class Method Details

.create(cs_type, axes, context) ⇒ CoordinateSystem

Create a CoordinateSystem

Parameters:

  • context (Context)

    The context associated with the CoordinateSystem

  • cs_type (PJ_COORDINATE_SYSTEM_TYPE)

    Coordinate system type

  • axes (Array<PJ_AXIS_DESCRIPTION>)

    Array of Axes

Returns:



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/proj/coordinate_system.rb', line 13

def self.create(cs_type, axes, context)
  axes_ptr = FFI::MemoryPointer.new(Api::PJ_AXIS_DESCRIPTION, axes.size)
  axes.each_with_index do |axis, i|
    axis_description_target = Api::PJ_AXIS_DESCRIPTION.new(axes_ptr[i])
    axis_description_source = axis.to_description
    axis_description_target.to_ptr.__copy_from__(axis_description_source.to_ptr, Api::PJ_AXIS_DESCRIPTION.size)
  end

  pointer = Api.proj_create_cs(context, cs_type, axes.count, axes_ptr)
  Error.check_context(context)
  self.create_object(pointer, context)
end

.create_cartesian_2d(context, cs_type, unit_name: nil, unit_conv_factor: 0) ⇒ CoordinateSystem

Create a CartesiansCS 2D coordinate system

Parameters:

  • context (Context)

    The context associated with the CoordinateSystem

  • cs_type (PJ_COORDINATE_SYSTEM_TYPE)

    Coordinate system type

  • unit_name (String) (defaults to: nil)

    Name of the unit. Default is nil.

  • unit_conv_factor (Float) (defaults to: 0)

    Unit conversion factor to SI. Default is 0.

Returns:



64
65
66
67
68
# File 'lib/proj/coordinate_system.rb', line 64

def self.create_cartesian_2d(context, cs_type, unit_name: nil, unit_conv_factor: 0)
  pointer = Api.proj_create_cartesian_2D_cs(context, cs_type, unit_name, unit_conv_factor)
  Error.check_context(context)
  self.create_object(pointer, context)
end

.create_ellipsoidal_2d(cs_type, context, unit_name: nil, unit_conv_factor: 0) ⇒ CoordinateSystem

Create an Ellipsoidal 2D CoordinateSystem

Parameters:

  • context (Context)

    The context associated with the CoordinateSystem

  • cs_type (PJ_COORDINATE_SYSTEM_TYPE)

    Coordinate system type

  • unit_name (String) (defaults to: nil)

    Name of the angular units. Or nil for degree

  • unit_conv_factor (Float) (defaults to: 0)

    Conversion factor from the angular unit to radian. Set to 0 if unit name is degree

Returns:



34
35
36
37
38
# File 'lib/proj/coordinate_system.rb', line 34

def self.create_ellipsoidal_2d(cs_type, context, unit_name: nil, unit_conv_factor: 0)
  pointer = Api.proj_create_ellipsoidal_2D_cs(context, cs_type, unit_name, unit_conv_factor)
  Error.check_context(context)
  self.create_object(pointer, context)
end

.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) ⇒ CoordinateSystem

Create an Ellipsoidal 3D CoordinateSystem

Parameters:

  • context (Context)

    The context associated with the CoordinateSystem

  • cs_type (PJ_COORDINATE_SYSTEM_TYPE)

    Coordinate system type

  • horizontal_angular_unit_name (String) (defaults to: nil)

    Name of the angular units. Or nil for degree

  • horizontal_angular_unit_conv_factor (Float) (defaults to: 0)

    Conversion factor from the angular unit to radian. Set to 0 if horizontal_angular_unit_name name is degree

  • vertical_linear_unit_name (String) (defaults to: nil)

    Name of the linear units. Or nil for meters. # @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.

Returns:



50
51
52
53
54
# File 'lib/proj/coordinate_system.rb', line 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)
  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)
  Error.check_context(context)
  self.create_object(pointer, context)
end

Instance Method Details

#axesArray<AxisInfo>

Returns information about all axes

Returns:



131
132
133
134
135
# File 'lib/proj/coordinate_system.rb', line 131

def axes
  self.axis_count.times.map do |index|
    self.axis_info(index)
  end
end

#axis_countInteger

Returns the number of axes in the coordinate system



88
89
90
91
92
93
94
# File 'lib/proj/coordinate_system.rb', line 88

def axis_count
  result = Api.proj_cs_get_axis_count(self.context, self)
  if result == -1
    Error.check_object(self)
  end
  result
end

#axis_info(index) ⇒ AxisInfo

Returns information about a single axis

Parameters:

  • index (Integer)

    Index of the axis

Returns:

See Also:



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/proj/coordinate_system.rb', line 103

def axis_info(index)
  p_name = FFI::MemoryPointer.new(:pointer)
  p_abbreviation = FFI::MemoryPointer.new(:pointer)
  p_direction = FFI::MemoryPointer.new(:pointer)
  p_unit_conv_factor = FFI::MemoryPointer.new(:double)
  p_unit_name = FFI::MemoryPointer.new(:pointer)
  p_unit_auth_name = FFI::MemoryPointer.new(:pointer)
  p_unit_code = FFI::MemoryPointer.new(:pointer)

  result = Api.proj_cs_get_axis_info(self.context, self, index,
                                     p_name, p_abbreviation, p_direction, p_unit_conv_factor, p_unit_name, p_unit_auth_name, p_unit_code)

  unless result
    Error.check_object(self)
  end

  AxisInfo.new(name: p_name.read_pointer.read_string,
               abbreviation: p_abbreviation.read_pointer.read_string_to_null,
               direction: p_direction.read_pointer.read_string_to_null,
               unit_conv_factor: p_unit_conv_factor.read_double,
               unit_name: p_unit_name.read_pointer.read_string_to_null,
               unit_auth_name: p_unit_auth_name.read_pointer.read_string_to_null,
               unit_code: p_unit_code.read_pointer.read_string_to_null)
end

#cs_typePJ_COORDINATE_SYSTEM_TYPE

Returns the type of the coordinate system

Returns:

  • (PJ_COORDINATE_SYSTEM_TYPE)

See Also:



75
76
77
78
79
80
81
# File 'lib/proj/coordinate_system.rb', line 75

def cs_type
  result = Api.proj_cs_get_type(self.context, self)
  if result == :PJ_CS_TYPE_UNKNOWN
    Error.check_object(self)
  end
  result
end