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, #area_of_use, #auth, #auth_name, #context, #context=, create_from_database, create_from_name, create_from_wkt, #definition, #deprecated?, #description, #destroy, #domains, #equivalent_to?, #errorno, #factors, #geod_direct, #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

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 (PjCoordinateSystemType)

    Coordinate system type

  • axes (Array<PjAxisDescription>)

    Array of Axes

Returns:



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

def self.create(cs_type, axes, context)
  Error.validate_context!(context)
  axes_ptr = FFI::MemoryPointer.new(Api::PjAxisDescription, axes.size)
  # Keep source descriptions alive so their retained string pointers
  # are not GC'd before proj_create_cs reads them.
  descriptions = axes.map { |axis| axis.to_description }
  descriptions.each_with_index do |axis_description_source, i|
    axis_description_target = Api::PjAxisDescription.new(axes_ptr[i])
    axis_description_target.to_ptr.__copy_from__(axis_description_source.to_ptr, Api::PjAxisDescription.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 (PjCoordinateSystemType)

    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:



69
70
71
72
73
74
# File 'lib/proj/coordinate_system.rb', line 69

def self.create_cartesian_2d(context, cs_type, unit_name: nil, unit_conv_factor: 0)
  Error.validate_context!(context)
  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 (PjCoordinateSystemType)

    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:



37
38
39
40
41
42
# File 'lib/proj/coordinate_system.rb', line 37

def self.create_ellipsoidal_2d(cs_type, context, unit_name: nil, unit_conv_factor: 0)
  Error.validate_context!(context)
  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 (PjCoordinateSystemType)

    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:



54
55
56
57
58
59
# File 'lib/proj/coordinate_system.rb', line 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)
  Error.validate_context!(context)
  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:



137
138
139
140
141
# File 'lib/proj/coordinate_system.rb', line 137

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



94
95
96
97
98
99
100
# File 'lib/proj/coordinate_system.rb', line 94

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:



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/proj/coordinate_system.rb', line 109

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_typePjCoordinateSystemType

Returns the type of the coordinate system



81
82
83
84
85
86
87
# File 'lib/proj/coordinate_system.rb', line 81

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