Module: RGeo::Geos::Utils

Defined in:
lib/rgeo/geos/utils.rb

Overview

:nodoc:

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.ffi_supports_prepared_level_1Object (readonly)

Returns the value of attribute ffi_supports_prepared_level_1


105
106
107
# File 'lib/rgeo/geos/utils.rb', line 105

def ffi_supports_prepared_level_1
  @ffi_supports_prepared_level_1
end

.ffi_supports_prepared_level_2Object (readonly)

Returns the value of attribute ffi_supports_prepared_level_2


106
107
108
# File 'lib/rgeo/geos/utils.rb', line 106

def ffi_supports_prepared_level_2
  @ffi_supports_prepared_level_2
end

.ffi_supports_set_output_dimensionObject (readonly)

Returns the value of attribute ffi_supports_set_output_dimension


107
108
109
# File 'lib/rgeo/geos/utils.rb', line 107

def ffi_supports_set_output_dimension
  @ffi_supports_set_output_dimension
end

.marshal_wkb_generatorObject (readonly)

Returns the value of attribute marshal_wkb_generator


109
110
111
# File 'lib/rgeo/geos/utils.rb', line 109

def marshal_wkb_generator
  @marshal_wkb_generator
end

.psych_wkt_generatorObject (readonly)

Returns the value of attribute psych_wkt_generator


108
109
110
# File 'lib/rgeo/geos/utils.rb', line 108

def psych_wkt_generator
  @psych_wkt_generator
end

Class Method Details

._initObject


95
96
97
98
99
100
101
102
103
# File 'lib/rgeo/geos/utils.rb', line 95

def _init
  if FFI_SUPPORTED
    @ffi_supports_prepared_level_1 = ::Geos::FFIGeos.respond_to?(:GEOSPreparedContains_r)
    @ffi_supports_prepared_level_2 = ::Geos::FFIGeos.respond_to?(:GEOSPreparedDisjoint_r)
    @ffi_supports_set_output_dimension = ::Geos::FFIGeos.respond_to?(:GEOSWKTWriter_setOutputDimension_r)
  end
  @psych_wkt_generator = WKRep::WKTGenerator.new(:convert_case => :upper)
  @marshal_wkb_generator = WKRep::WKBGenerator.new
end

.ffi_compute_dimension(geom_) ⇒ Object


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/rgeo/geos/utils.rb', line 63

def ffi_compute_dimension(geom_)
  result_ = -1
  case geom_.type_id
  when ::Geos::GeomTypes::GEOS_POINT
    result_ = 0
  when ::Geos::GeomTypes::GEOS_MULTIPOINT
    result_ = 0 unless geom_.empty?
  when ::Geos::GeomTypes::GEOS_LINESTRING, ::Geos::GeomTypes::GEOS_LINEARRING
    result_ = 1
  when ::Geos::GeomTypes::GEOS_MULTILINESTRING
    result_ = 1 unless geom_.empty?
  when ::Geos::GeomTypes::GEOS_POLYGON
    result_ = 2
  when ::Geos::GeomTypes::GEOS_MULTIPOLYGON
    result_ = 2 unless geom_.empty?
  when ::Geos::GeomTypes::GEOS_GEOMETRYCOLLECTION
    geom_.each do |g_|
      dim_ = ffi_compute_dimension(g_)
      result_ = dim_ if result_ < dim_
    end
  end
  result_
end

.ffi_coord_seq_hash(cs_, hash_ = 0) ⇒ Object


88
89
90
91
92
# File 'lib/rgeo/geos/utils.rb', line 88

def ffi_coord_seq_hash(cs_, hash_=0)
  (0...cs_.length).inject(hash_) do |h_, i_|
    [hash_, cs_.get_x(i_), cs_.get_y(i_), cs_.get_z(i_)].hash
  end
end

.ffi_coord_seqs_equal?(cs1_, cs2_, check_z_) ⇒ Boolean

Returns:

  • (Boolean)

47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rgeo/geos/utils.rb', line 47

def ffi_coord_seqs_equal?(cs1_, cs2_, check_z_)
  len1_ = cs1_.length
  len2_ = cs2_.length
  if len1_ == len2_
    (0...len1_).each do |i_|
      return false unless cs1_.get_x(i_) == cs2_.get_x(i_) &&
        cs1_.get_y(i_) == cs2_.get_y(i_) &&
        (!check_z_ || cs1_.get_z(i_) == cs2_.get_z(i_))
    end
    true
  else
    false
  end
end