Class: Geos::GeoJSONWriter

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ GeoJSONWriter

Returns a new instance of GeoJSONWriter.



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

def initialize(options = {})
  options = {
    indentation: -1
  }.merge(options)

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

  set_options(options)
end

Instance Attribute Details

#indentationObject

Returns the value of attribute indentation.



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

def indentation
  @indentation
end

#ptrObject (readonly)

Returns the value of attribute ptr.



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

def ptr
  @ptr
end

Class Method Details

.release(ptr) ⇒ Object

:nodoc:



22
23
24
# File 'lib/ffi-geos/geojson_writer.rb', line 22

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

Instance Method Details

#write(geom, options = nil) ⇒ Object

Options can be set temporarily for individual writes using an options Hash. Options include :indentation.



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ffi-geos/geojson_writer.rb', line 35

def write(geom, options = nil)
  unless options.nil?
    old_options = {
      indentation: indentation
    }

    set_options(options)
  end

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