Class: Geos::WkbWriter

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

Constant Summary

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(options = {}) ⇒ WkbWriter

Returns a new instance of WkbWriter.



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

def initialize(options = {})
  options = {
    include_srid: false
  }.merge(options)

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

  set_options(options)
end

Instance Attribute Details

#ptrObject (readonly)

Returns the value of attribute ptr.



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

def ptr
  @ptr
end

Class Method Details

.release(ptr) ⇒ Object

:nodoc:



23
24
25
# File 'lib/ffi-geos/wkb_writer.rb', line 23

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

Instance Method Details

#byte_orderObject



77
78
79
# File 'lib/ffi-geos/wkb_writer.rb', line 77

def byte_order
  FFIGeos.GEOSWKBWriter_getByteOrder_r(Geos.current_handle_pointer, ptr)
end

#byte_order=(val) ⇒ Object



81
82
83
84
# File 'lib/ffi-geos/wkb_writer.rb', line 81

def byte_order=(val)
  check_enum_value(Geos::ByteOrders, val)
  FFIGeos.GEOSWKBWriter_setByteOrder_r(Geos.current_handle_pointer, ptr, val)
end

#include_sridObject



69
70
71
# File 'lib/ffi-geos/wkb_writer.rb', line 69

def include_srid
  bool_result(FFIGeos.GEOSWKBWriter_getIncludeSRID_r(Geos.current_handle_pointer, ptr))
end

#include_srid=(val) ⇒ Object



73
74
75
# File 'lib/ffi-geos/wkb_writer.rb', line 73

def include_srid=(val)
  FFIGeos.GEOSWKBWriter_setIncludeSRID_r(Geos.current_handle_pointer, ptr, Geos::Tools.bool_to_int(val))
end

#output_dimensionsObject



65
66
67
# File 'lib/ffi-geos/wkb_writer.rb', line 65

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

#output_dimensions=(dim) ⇒ Object

Raises:

  • (ArgumentError)


59
60
61
62
63
# File 'lib/ffi-geos/wkb_writer.rb', line 59

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

  FFIGeos.GEOSWKBWriter_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. The only option currently available is :include_srid.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ffi-geos/wkb_writer.rb', line 29

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

    set_options(options)
  end

  size_t = FFI::MemoryPointer.new(:size_t)
  FFIGeos.GEOSWKBWriter_write_r(Geos.current_handle_pointer, ptr, geom.ptr, size_t).get_bytes(0, size_t.read_int)
ensure
  set_options(old_options) unless old_options.nil?
end

#write_hex(geom, options = nil) ⇒ Object



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

def write_hex(geom, options = nil)
  unless options.nil?
    old_options = {
      include_srid: include_srid
    }

    set_options(options)
  end

  size_t = FFI::MemoryPointer.new(:size_t)
  FFIGeos.GEOSWKBWriter_writeHEX_r(Geos.current_handle_pointer, ptr, geom.ptr, size_t).get_string(0, size_t.read_int)
ensure
  set_options(old_options) unless old_options.nil?
end