Class: Geos::BufferParams

Inherits:
Object
  • Object
show all
Includes:
Tools
Defined in:
lib/ffi-geos/buffer_params.rb

Constant Summary collapse

VALID_PARAMETERS =
[
  :quad_segs, :endcap, :join, :mitre_limit, :single_sided
].freeze

Constants included from GeomTypes

GeomTypes::GEOS_GEOMETRYCOLLECTION, GeomTypes::GEOS_LINEARRING, GeomTypes::GEOS_LINESTRING, GeomTypes::GEOS_MULTILINESTRING, GeomTypes::GEOS_MULTIPOINT, GeomTypes::GEOS_MULTIPOLYGON, GeomTypes::GEOS_POINT, GeomTypes::GEOS_POLYGON

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Tools

#bool_result, #bool_to_int, #cast_geometry_ptr, #check_enum_value, #check_geometry, #extract_options!, #pick_srid_according_to_policy, #pick_srid_from_geoms, #symbol_for_enum

Constructor Details

#initialize(params = {}) ⇒ BufferParams

The defaults for the params according to GEOS are as found in Geos::Constants::BUFFER_PARAMS_DEFAULTS. Note that when setting the :quad_segs value that you should set it before setting other values like :join and :mitre_limit, as GEOS contains logic concerning how the :quad_segs value affects these parameters and vice versa. For details, refer to src/operation/buffer/BufferParameters.cpp and the BufferParameters::setQuadrantSegments(int) method in the GEOS source code for details.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ffi-geos/buffer_params.rb', line 24

def initialize(params = {})
  params = Geos::Constants::BUFFER_PARAM_DEFAULTS.merge(params)

  ptr = FFIGeos.GEOSBufferParams_create_r(Geos.current_handle_pointer)
  @ptr = FFI::AutoPointer.new(
    ptr,
    self.class.method(:release)
  )

  @params = {}
  VALID_PARAMETERS.each do |param|
    send("#{param}=", params[param])
  end
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



14
15
16
# File 'lib/ffi-geos/buffer_params.rb', line 14

def params
  @params
end

#ptrObject (readonly)

Returns the value of attribute ptr.



14
15
16
# File 'lib/ffi-geos/buffer_params.rb', line 14

def ptr
  @ptr
end

Class Method Details

.release(ptr) ⇒ Object

:nodoc:



39
40
41
# File 'lib/ffi-geos/buffer_params.rb', line 39

def self.release(ptr) # :nodoc:
  FFIGeos.GEOSBufferParams_destroy_r(Geos.current_handle_pointer, ptr)
end

Instance Method Details

#endcap=(value) ⇒ Object



43
44
45
46
47
# File 'lib/ffi-geos/buffer_params.rb', line 43

def endcap=(value)
  check_enum_value(Geos::BufferCapStyles, value)

  @params[:endcap] = symbol_for_enum(Geos::BufferCapStyles, value) if bool_result(FFIGeos.GEOSBufferParams_setEndCapStyle_r(Geos.current_handle_pointer, ptr, value))
end

#join=(value) ⇒ Object



49
50
51
52
53
# File 'lib/ffi-geos/buffer_params.rb', line 49

def join=(value)
  check_enum_value(Geos::BufferJoinStyles, value)

  @params[:join] = symbol_for_enum(Geos::BufferJoinStyles, value) if bool_result(FFIGeos.GEOSBufferParams_setJoinStyle_r(Geos.current_handle_pointer, ptr, value))
end

#mitre_limit=(value) ⇒ Object



55
56
57
# File 'lib/ffi-geos/buffer_params.rb', line 55

def mitre_limit=(value)
  @params[:mitre_limit] = value if bool_result(FFIGeos.GEOSBufferParams_setMitreLimit_r(Geos.current_handle_pointer, ptr, value))
end

#quad_segs=(value) ⇒ Object



59
60
61
# File 'lib/ffi-geos/buffer_params.rb', line 59

def quad_segs=(value)
  @params[:quad_segs] = value if bool_result(FFIGeos.GEOSBufferParams_setQuadrantSegments_r(Geos.current_handle_pointer, ptr, value))
end

#single_sided=(value) ⇒ Object



63
64
65
# File 'lib/ffi-geos/buffer_params.rb', line 63

def single_sided=(value)
  @params[:single_sided] = value if bool_result(FFIGeos.GEOSBufferParams_setSingleSided_r(Geos.current_handle_pointer, ptr, Geos::Tools.bool_to_int(value)))
end