Class: Geos::WktWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi-geos/wkt_writer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ WktWriter

Returns a new instance of WktWriter.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ffi-geos/wkt_writer.rb', line 7

def initialize(options = {})
  options = {
    trim: false,
    old_3d: false,
    rounding_precision: -1,
    output_dimensions: 2
  }.merge(options)

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

  set_options(options)
end

Instance Attribute Details

#old_3dObject

Returns the value of attribute old_3d.



5
6
7
# File 'lib/ffi-geos/wkt_writer.rb', line 5

def old_3d
  @old_3d
end

#ptrObject (readonly)

Returns the value of attribute ptr.



5
6
7
# File 'lib/ffi-geos/wkt_writer.rb', line 5

def ptr
  @ptr
end

#rounding_precisionObject

Returns the value of attribute rounding_precision.



5
6
7
# File 'lib/ffi-geos/wkt_writer.rb', line 5

def rounding_precision
  @rounding_precision
end

#trimObject

Returns the value of attribute trim.



5
6
7
# File 'lib/ffi-geos/wkt_writer.rb', line 5

def trim
  @trim
end

Class Method Details

.release(ptr) ⇒ Object

:nodoc:



24
25
26
# File 'lib/ffi-geos/wkt_writer.rb', line 24

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

Instance Method Details

#output_dimensionsObject

Available in GEOS 3.3+.



94
95
96
# File 'lib/ffi-geos/wkt_writer.rb', line 94

def output_dimensions
  FFIGeos.GEOSWKTWriter_getOutputDimension_r(Geos.current_handle_pointer, ptr)
end

#output_dimensions=(dim) ⇒ Object

Available in GEOS 3.3+.

Raises:

  • (ArgumentError)


84
85
86
87
88
89
# File 'lib/ffi-geos/wkt_writer.rb', line 84

def output_dimensions=(dim)
  dim = dim.to_i
  raise ArgumentError, 'Output dimensions must be either 2 or 3' if dim < 2 || dim > 3

  FFIGeos.GEOSWKTWriter_setOutputDimension_r(Geos.current_handle_pointer, ptr, dim)
end

#write(geom, options = nil) ⇒ Object

Options can be set temporarily for individual writes using an options Hash. Options include :trim, :old_3d, :rounding_precision and :output_dimensions



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ffi-geos/wkt_writer.rb', line 38

def write(geom, options = nil)
  unless options.nil?
    old_options = {
      trim: trim,
      old_3d: old_3d,
      rounding_precision: rounding_precision,
      output_dimensions: output_dimensions
    }

    set_options(options)
  end

  FFIGeos.GEOSWKTWriter_write_r(Geos.current_handle_pointer, ptr, geom.ptr)
ensure
  set_options(old_options) unless options.nil?
end