Class: OGR::StyleTool

Inherits:
Object
  • Object
show all
Defined in:
lib/ogr/style_tool.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(style_tool_class) ⇒ StyleTool

Returns a new instance of StyleTool.

Parameters:



19
20
21
22
23
24
25
26
27
# File 'lib/ogr/style_tool.rb', line 19

def initialize(style_tool_class)
  pointer = FFI::OGR::API.OGR_ST_Create(style_tool_class)

  if !pointer || pointer.null?
    raise OGR::CreateFailure, "Unable to create StyleTool using class #{style_tool_class}"
  end

  @c_pointer = FFI::AutoPointer.new(pointer, StyleTool.method(:release))
end

Instance Attribute Details

#c_pointerFFI::Pointer (readonly)

Returns C pointer to the C style tool.

Returns:

  • (FFI::Pointer)

    C pointer to the C style tool.



15
16
17
# File 'lib/ogr/style_tool.rb', line 15

def c_pointer
  @c_pointer
end

Class Method Details

.release(pointer) ⇒ Object

Parameters:

  • pointer (FFI::Pointer)


8
9
10
11
12
# File 'lib/ogr/style_tool.rb', line 8

def self.release(pointer)
  return unless pointer && !pointer.null?

  FFI::OGR::API.OGR_ST_Destroy(pointer)
end

Instance Method Details

#param_as_double(param_number) ⇒ Float? Also known as: param_as_float

Parameters:

Returns:



55
56
57
58
59
60
# File 'lib/ogr/style_tool.rb', line 55

def param_as_double(param_number)
  value_is_null_ptr = FFI::MemoryPointer.new(:int)
  value = FFI::OGR::API.OGR_ST_GetParamDbl(@c_pointer, param_number, value_is_null_ptr)

  value_is_null_ptr.read_int.to_bool ? nil : value
end

#param_as_number(param_number) ⇒ Integer? Also known as: param_as_integer

Parameters:

Returns:



72
73
74
75
76
77
# File 'lib/ogr/style_tool.rb', line 72

def param_as_number(param_number)
  value_is_null_ptr = FFI::MemoryPointer.new(:int)
  value = FFI::OGR::API.OGR_ST_GetParamNum(@c_pointer, param_number, value_is_null_ptr)

  value_is_null_ptr.read_int.to_bool ? nil : value
end

#param_as_string(param_number) ⇒ String?

Parameters:

Returns:



89
90
91
92
93
94
95
# File 'lib/ogr/style_tool.rb', line 89

def param_as_string(param_number)
  value_is_null_ptr = FFI::MemoryPointer.new(:int)
  value, ptr = FFI::OGR::API.OGR_ST_GetParamStr(@c_pointer, param_number, value_is_null_ptr)
  ptr.autorelease = false

  value_is_null_ptr.read_int.to_bool ? nil : value
end

#rgb_from_string(color_string) ⇒ Hash{red => Integer, green => Integer, blue => Integer, alpha => Integer}

Returns the R, G, B, A components of a #RRGGBB formatted string.

Parameters:

Returns:



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/ogr/style_tool.rb', line 107

def rgb_from_string(color_string)
  red_ptr = FFI::MemoryPointer.new(:int)
  green_ptr = FFI::MemoryPointer.new(:int)
  blue_ptr = FFI::MemoryPointer.new(:int)
  alpha_ptr = FFI::MemoryPointer.new(:int)

  boolean_result = FFI::OGR::API.OGR_ST_GetRGBFromString(@c_pointer,
                                                         color_string, red_ptr, green_ptr, blue_ptr, alpha_ptr)

  if boolean_result
    {
      red: red_ptr.read_int,
      green: green_ptr.read_int,
      blue: blue_ptr.read_int,
      alpha: alpha_ptr.read_int
    }
  else
    { red: nil, green: nil, blue: nil, alpha: nil }
  end
end

#set_param_as_double(param_number, value) ⇒ Object Also known as: set_param_as_float

Parameters:



65
66
67
# File 'lib/ogr/style_tool.rb', line 65

def set_param_as_double(param_number, value)
  FFI::OGR::API.OGR_ST_SetParamDbl(@c_pointer, param_number, value)
end

#set_param_as_number(param_number, value) ⇒ Object Also known as: set_param_as_integer

Parameters:



82
83
84
# File 'lib/ogr/style_tool.rb', line 82

def set_param_as_number(param_number, value)
  FFI::OGR::API.OGR_ST_SetParamNum(@c_pointer, param_number, value)
end

#set_param_as_string(param_number, value) ⇒ Object

Parameters:



99
100
101
# File 'lib/ogr/style_tool.rb', line 99

def set_param_as_string(param_number, value)
  FFI::OGR::API.OGR_ST_SetParamStr(@c_pointer, param_number, value)
end

#set_unit(new_unit, ground_to_paper_scale) ⇒ Object

Parameters:



49
50
51
# File 'lib/ogr/style_tool.rb', line 49

def set_unit(new_unit, ground_to_paper_scale)
  FFI::OGR::API.OGR_ST_SetUnit(@c_pointer, new_unit, ground_to_paper_scale)
end

#style_stringString?

Returns:



30
31
32
33
34
35
# File 'lib/ogr/style_tool.rb', line 30

def style_string
  style, ptr = FFI::OGR::API.OGR_ST_GetStyleString(@c_pointer)
  ptr.autorelease = false

  style
end

#typeFFI::OGR::Core::STClassId



38
39
40
# File 'lib/ogr/style_tool.rb', line 38

def type
  FFI::OGR::API.OGR_ST_GetType(@c_pointer)
end

#unitFFI::OGR::Core::STUnitId



43
44
45
# File 'lib/ogr/style_tool.rb', line 43

def unit
  FFI::OGR::API.OGR_ST_GetUnit(@c_pointer)
end