Module: RGeo::Geos::Utils

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

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.ffi_compute_dimension(geom) ⇒ Object


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rgeo/geos/utils.rb', line 28

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


52
53
54
55
56
# File 'lib/rgeo/geos/utils.rb', line 52

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)

13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rgeo/geos/utils.rb', line 13

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

.ffi_supports_prepared_level_1Object


58
59
60
# File 'lib/rgeo/geos/utils.rb', line 58

def ffi_supports_prepared_level_1
  FFI_SUPPORTED && ::Geos::FFIGeos.respond_to?(:GEOSPreparedContains_r)
end

.ffi_supports_prepared_level_2Object


62
63
64
# File 'lib/rgeo/geos/utils.rb', line 62

def ffi_supports_prepared_level_2
  FFI_SUPPORTED && ::Geos::FFIGeos.respond_to?(:GEOSPreparedDisjoint_r)
end

.ffi_supports_set_output_dimensionObject


66
67
68
# File 'lib/rgeo/geos/utils.rb', line 66

def ffi_supports_set_output_dimension
  FFI_SUPPORTED && ::Geos::FFIGeos.respond_to?(:GEOSWKTWriter_setOutputDimension_r)
end

.ffi_supports_unary_unionObject


70
71
72
# File 'lib/rgeo/geos/utils.rb', line 70

def ffi_supports_unary_union
  FFI_SUPPORTED && ::Geos::FFIGeos.respond_to?(:GEOSUnaryUnion_r)
end

.marshal_wkb_generatorObject


78
79
80
# File 'lib/rgeo/geos/utils.rb', line 78

def marshal_wkb_generator
  WKRep::WKBGenerator.new
end

.psych_wkt_generatorObject


74
75
76
# File 'lib/rgeo/geos/utils.rb', line 74

def psych_wkt_generator
  WKRep::WKTGenerator.new(convert_case: :upper)
end