Module: OGR::Envelope::Extensions

Included in:
OGR::Envelope
Defined in:
lib/ogr/extensions/envelope/extensions.rb

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Boolean

Compares min/max X and min/max Y to the other envelope. The envelopes are considered equal if those values are the same.

Parameters:

Returns:

  • (Boolean)


48
49
50
51
# File 'lib/ogr/extensions/envelope/extensions.rb', line 48

def ==(other)
  x_min == other.x_min && y_min == other.y_min &&
    x_max == other.x_max && y_max == other.y_max
end

#contains?(other_envelope) ⇒ Boolean

Parameters:

  • other_envelope (OGR::Envelope)

    The Envelope to check containment with.

Returns:

  • (Boolean)


84
85
86
87
88
89
# File 'lib/ogr/extensions/envelope/extensions.rb', line 84

def contains?(other_envelope)
  x_min <= other_envelope.x_min &&
    y_min <= other_envelope.y_min &&
    x_max >= other_envelope.x_max &&
    y_max >= other_envelope.y_max
end

#intersects?(other_envelope) ⇒ Boolean

Parameters:

  • other_envelope (OGR::Envelope)

    The Envelope to check intersection with.

Returns:

  • (Boolean)


72
73
74
75
76
77
# File 'lib/ogr/extensions/envelope/extensions.rb', line 72

def intersects?(other_envelope)
  x_min <= other_envelope.x_max &&
    x_max >= other_envelope.x_min &&
    y_min <= other_envelope.y_max &&
    y_max >= other_envelope.y_min
end

#merge(other_envelope) ⇒ OGR::Envelope

Parameters:

  • other_envelope (OGR::Envelope)

    The Envelope to merge self with.

Returns:



57
58
59
60
61
62
63
64
65
# File 'lib/ogr/extensions/envelope/extensions.rb', line 57

def merge(other_envelope)
  new_envelope = OGR::Envelope.new
  new_envelope.x_min = [x_min, other_envelope.x_min].min
  new_envelope.x_max = [x_max, other_envelope.x_max].max
  new_envelope.y_min = [y_min, other_envelope.y_min].min
  new_envelope.y_max = [y_max, other_envelope.y_max].max

  new_envelope
end

#to_aObject



107
108
109
# File 'lib/ogr/extensions/envelope/extensions.rb', line 107

def to_a
  [x_min, y_min, x_max, y_max]
end

#to_polygonOGR::Polygon

Returns:



92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/ogr/extensions/envelope/extensions.rb', line 92

def to_polygon
  ring = OGR::LinearRing.new
  ring.point_count = 5
  ring.set_point(0, x_min, y_max)
  ring.set_point(1, x_max, y_max)
  ring.set_point(2, x_max, y_min)
  ring.set_point(3, x_min, y_min)
  ring.set_point(4, x_min, y_max)

  polygon = OGR::Polygon.new
  polygon.add_geometry(ring)

  polygon
end

#world_to_pixels(geo_transform) ⇒ Hash{x_min => Integer, y_min => Integer, x_max => Integer, y_max => Integer}

Adapted from “Advanced Geospatial Python Modeling”. Calculates the pixel locations of these geospatial coordinates according to the given GeoTransform.

Parameters:

Returns:



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ogr/extensions/envelope/extensions.rb', line 31

def world_to_pixels(geo_transform)
  min_values = geo_transform.world_to_pixel(x_min, y_max)
  max_values = geo_transform.world_to_pixel(x_max, y_min)

  {
    x_min: min_values[:pixel].round.to_i,
    y_min: min_values[:line].round.to_i,
    x_max: max_values[:pixel].round.to_i,
    y_max: max_values[:line].round.to_i
  }
end

#x_sizeFloat

Returns x_max - x_min.

Returns:

  • (Float)

    x_max - x_min



9
10
11
# File 'lib/ogr/extensions/envelope/extensions.rb', line 9

def x_size
  x_max - x_min
end

#y_sizeFloat

Returns y_max - y_min.

Returns:

  • (Float)

    y_max - y_min



14
15
16
# File 'lib/ogr/extensions/envelope/extensions.rb', line 14

def y_size
  y_max - y_min
end

#z_sizeFloat

Returns z_max - z_min.

Returns:

  • (Float)

    z_max - z_min



19
20
21
22
23
# File 'lib/ogr/extensions/envelope/extensions.rb', line 19

def z_size
  return unless z_max && z_min

  z_max - z_min
end