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

Class Method Details

.included(base) ⇒ Object

Parameters:

  • base (Class, Module)


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_aArray

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

Returns:

  • (Array)


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.

Parameters:

  • x_geo (Number)
  • y_geo (Number)

Returns:



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.

Parameters:

  • x_geo (Number)

Returns:

Raises:



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.

Parameters:

  • y_geo (Number)

Returns:

Raises:



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