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.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ffi-geos/wkt_writer.rb', line 11

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.



7
8
9
# File 'lib/ffi-geos/wkt_writer.rb', line 7

def old_3d
  @old_3d
end

#ptrObject (readonly)

Returns the value of attribute ptr.



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

def ptr
  @ptr
end

#rounding_precisionObject

Returns the value of attribute rounding_precision.



8
9
10
# File 'lib/ffi-geos/wkt_writer.rb', line 8

def rounding_precision
  @rounding_precision
end

#trimObject

Returns the value of attribute trim.



9
10
11
# File 'lib/ffi-geos/wkt_writer.rb', line 9

def trim
  @trim
end

Class Method Details

.release(ptr) ⇒ Object

:nodoc:



28
29
30
# File 'lib/ffi-geos/wkt_writer.rb', line 28

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+.



105
106
107
# File 'lib/ffi-geos/wkt_writer.rb', line 105

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

#output_dimensions=(dim) ⇒ Object

Available in GEOS 3.3+.



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

def output_dimensions=(dim)
  dim = dim.to_i
  if dim < 2 || dim > 3
    raise ArgumentError.new("Output dimensions must be either 2 or 3")
  end
  FFIGeos.GEOSWKTWriter_setOutputDimension_r(Geos.current_handle_pointer, self.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



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ffi-geos/wkt_writer.rb', line 42

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

    set_options(options)
  end

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