Module: GDAL::GeoTransform::Extensions
- Included in:
- GDAL::GeoTransform
- Defined in:
- lib/gdal/extensions/geo_transform/extensions.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#to_a ⇒ Array
All attributes as an Array, in the order the C-Struct describes them: * x_origin * pixel_width * x_rotation * y_origin * y_rotation * pixel_height.
-
#world_to_pixel(x_geo, y_geo) ⇒ Hash{pixel => Integer, line Integer}
Calculates the pixel and line location of a geospatial coordinate.
-
#world_to_x_pixel(x_geo) ⇒ Integer
Calculates the pixel location using the current GeoTransform and
x_geo
coordinate. -
#world_to_y_pixel(y_geo) ⇒ Integer
Calculates the line location using the current GeoTransform and
y_geo
coordinate.
Class Method Details
.included(base) ⇒ Object
10 11 12 |
# File 'lib/gdal/extensions/geo_transform/extensions.rb', line 10 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#to_a ⇒ Array
All attributes as an Array, in the order the C-Struct describes them:
* x_origin
* pixel_width
* x_rotation
* y_origin
* y_rotation
* pixel_height
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/gdal/extensions/geo_transform/extensions.rb', line 85 def to_a [ x_origin, pixel_width, x_rotation, y_origin, y_rotation, pixel_height ] end |
#world_to_pixel(x_geo, y_geo) ⇒ Hash{pixel => Integer, line Integer}
Calculates the pixel and line location of a geospatial coordinate. Used for converting from world coordinates to to image pixels.
39 40 41 42 43 44 |
# File 'lib/gdal/extensions/geo_transform/extensions.rb', line 39 def world_to_pixel(x_geo, y_geo) pixel = world_to_x_pixel(x_geo) line = world_to_y_pixel(y_geo) { pixel: pixel, line: line } end |
#world_to_x_pixel(x_geo) ⇒ Integer
Calculates the pixel location using the current GeoTransform and x_geo
coordinate.
53 54 55 56 57 58 59 |
# File 'lib/gdal/extensions/geo_transform/extensions.rb', line 53 def world_to_x_pixel(x_geo) pixel = (x_geo - x_origin) / pixel_width pixel.round.to_i rescue FloatDomainError raise GDAL::InvalidGeoTransform, "Invalid pixel_width (#{pixel_width})" end |
#world_to_y_pixel(y_geo) ⇒ Integer
Calculates the line location using the current GeoTransform and y_geo
coordinate.
68 69 70 71 72 73 74 |
# File 'lib/gdal/extensions/geo_transform/extensions.rb', line 68 def world_to_y_pixel(y_geo) line = (y_origin - y_geo) / pixel_height line.round.to_i rescue FloatDomainError raise GDAL::InvalidGeoTransform, "Invalid pixel_height (#{pixel_height})" end |