module OGR::Envelope::Extensions
Public Instance Methods
Compares min/max X and min/max Y to the other envelope. The envelopes are considered equal if those values are the same.
@param other [OGR::Envelope] @return [Boolean]
# 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
Stolen from www.gdal.org/ogr__core_8h_source.html.
@param other_envelope [OGR::Envelope] The Envelope
to check containment
with.
@return [Boolean]
# 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
Stolen from www.gdal.org/ogr__core_8h_source.html.
@param other_envelope [OGR::Envelope] The Envelope
to check intersection
with.
@return [Boolean]
# 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
Stolen from www.gdal.org/ogr__core_8h_source.html.
@param other_envelope [OGR::Envelope] The Envelope
to merge self with. @return [OGR::Envelope]
# 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
# File lib/ogr/extensions/envelope/extensions.rb, line 107 def to_a [x_min, y_min, x_max, y_max] end
@return [OGR::Polygon]
# 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
Adapted from “Advanced Geospatial Python Modeling”. Calculates the pixel locations of these geospatial coordinates according to the given GeoTransform.
@param geo_transform [GDAL::GeoTransform] @return [Hash{x_min => Integer
, y_min => Integer
, x_max => Integer
, y_max => Integer}]
# 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
@return [Float] x_max - x_min
# File lib/ogr/extensions/envelope/extensions.rb, line 9 def x_size x_max - x_min end
@return [Float] y_max - y_min
# File lib/ogr/extensions/envelope/extensions.rb, line 14 def y_size y_max - y_min end
@return [Float] z_max - z_min
# File lib/ogr/extensions/envelope/extensions.rb, line 19 def z_size return unless z_max && z_min z_max - z_min end