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.



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

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)
  @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.



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

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.



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

def rounding_precision
  @rounding_precision
end

#trimObject

Returns the value of attribute trim.



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

def trim
  @trim
end

Class Method Details

.release(ptr) ⇒ Object

:nodoc:



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

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

Instance Method Details

#output_dimensionsObject

Available in GEOS 3.3+.



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

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

#output_dimensions=(dim) ⇒ Object

Available in GEOS 3.3+.



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

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



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

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, self.ptr, geom.ptr)
ensure
  set_options(old_options) unless options.nil?
end