Module: OGR::Envelope::Extensions
- Included in:
- OGR::Envelope
- Defined in:
- lib/ogr/extensions/envelope/extensions.rb
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares min/max X and min/max Y to the other envelope.
-
#contains?(other_envelope) ⇒ Boolean
Stolen from www.gdal.org/ogr__core_8h_source.html.
-
#intersects?(other_envelope) ⇒ Boolean
Stolen from www.gdal.org/ogr__core_8h_source.html.
-
#merge(other_envelope) ⇒ OGR::Envelope
Stolen from www.gdal.org/ogr__core_8h_source.html.
- #to_a ⇒ Object
- #to_polygon ⇒ OGR::Polygon
-
#world_to_pixels(geo_transform) ⇒ Hash{x_min => Integer, y_min => Integer, x_max => Integer, y_max => Integer}
Adapted from “Advanced Geospatial Python Modeling”.
-
#x_size ⇒ Float
X_max - x_min.
-
#y_size ⇒ Float
Y_max - y_min.
-
#z_size ⇒ Float
Z_max - z_min.
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.
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
Stolen from www.gdal.org/ogr__core_8h_source.html.
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
Stolen from www.gdal.org/ogr__core_8h_source.html.
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
Stolen from www.gdal.org/ogr__core_8h_source.html.
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_a ⇒ Object
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_polygon ⇒ OGR::Polygon
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.
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_size ⇒ Float
9 10 11 |
# File 'lib/ogr/extensions/envelope/extensions.rb', line 9 def x_size x_max - x_min end |
#y_size ⇒ Float
14 15 16 |
# File 'lib/ogr/extensions/envelope/extensions.rb', line 14 def y_size y_max - y_min end |
#z_size ⇒ Float
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 |