Class: OGR::Envelope

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi-ogr/envelope.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Envelope

Returns a new instance of Envelope.

Raises:

  • (RuntimeError)


5
6
7
8
9
10
# File 'lib/ffi-ogr/envelope.rb', line 5

def initialize(env)
  raise RuntimeError.new("Invalid envelope specified") unless env.size == 4

  @min_x, @max_x = env[0], env[1]
  @min_y, @max_y = env[2], env[3]
end

Instance Attribute Details

#max_xObject

Returns the value of attribute max_x.



3
4
5
# File 'lib/ffi-ogr/envelope.rb', line 3

def max_x
  @max_x
end

#max_yObject

Returns the value of attribute max_y.



3
4
5
# File 'lib/ffi-ogr/envelope.rb', line 3

def max_y
  @max_y
end

#min_xObject

Returns the value of attribute min_x.



3
4
5
# File 'lib/ffi-ogr/envelope.rb', line 3

def min_x
  @min_x
end

#min_yObject

Returns the value of attribute min_y.



3
4
5
# File 'lib/ffi-ogr/envelope.rb', line 3

def min_y
  @min_y
end

Instance Method Details

#to_a(se_nw = false) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/ffi-ogr/envelope.rb', line 12

def to_a(se_nw=false)
  unless se_nw
    [@min_x, @max_x, @min_y, @max_y]
  else
    [@min_x, @min_y, @max_x, @max_y]
  end
end

#to_hashObject



20
21
22
# File 'lib/ffi-ogr/envelope.rb', line 20

def to_hash
  {min_x: @min_x, max_x: @max_x, min_y: @min_y, max_y: @max_y}
end

#to_jsonObject



24
25
26
# File 'lib/ffi-ogr/envelope.rb', line 24

def to_json
  MultiJson.dump(to_hash)
end

#to_polygonObject



28
29
30
31
# File 'lib/ffi-ogr/envelope.rb', line 28

def to_polygon
  coords = [[[@min_x, @min_y], [@min_x, @max_y], [@max_x, @max_y], [@max_x, @min_y], [@min_x, @min_y]]]
  OGR::Polygon.create coords
end