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, #cast_geometry_ptr, #check_enum_value, #check_geometry, #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)
  @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, ptr)
end

Instance Method Details

#byte_orderObject



87
88
89
# File 'lib/ffi-geos/wkb_writer.rb', line 87

def byte_order
  FFIGeos.GEOSWKBWriter_getByteOrder_r(Geos.current_handle, self.ptr)
end

#byte_order=(val) ⇒ Object



91
92
93
94
# File 'lib/ffi-geos/wkb_writer.rb', line 91

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

#include_sridObject



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

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

#include_srid=(val) ⇒ Object



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

def include_srid=(val)
  FFIGeos.GEOSWKBWriter_setIncludeSRID_r(Geos.current_handle, self.ptr,
    val ? 1 : 0
  )
end

#output_dimensionsObject



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

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

#output_dimensions=(dim) ⇒ Object



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

def output_dimensions=(dim)
  if dim < 2 || dim > 3
    raise RuntimeError.new("Output dimensions must be either 2 or 3")
  end
  FFIGeos.GEOSWKBWriter_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. The only option currently available is :include_srid.



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

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

    set_options(options)
  end

  size_t = FFI::MemoryPointer.new(:size_t)
  FFIGeos.GEOSWKBWriter_write_r(Geos.current_handle, self.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



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ffi-geos/wkb_writer.rb', line 51

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

    set_options(options)
  end

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