Skip to main content

GeoTransform

Struct GeoTransform 

Source
pub struct GeoTransform {
    pub origin_x: f64,
    pub pixel_width: f64,
    pub row_rotation: f64,
    pub origin_y: f64,
    pub col_rotation: f64,
    pub pixel_height: f64,
}
Expand description

An affine transformation matrix for converting between pixel and world coordinates

The transformation follows the GDAL convention:

x_geo = c0 + pixel_x * c1 + pixel_y * c2
y_geo = c3 + pixel_x * c4 + pixel_y * c5

For a north-up image:

  • c1 (pixel width) is positive
  • c5 (pixel height) is negative (Y increases downward in pixel space)
  • c2 and c4 (rotation terms) are zero

Fields§

§origin_x: f64

X coordinate of the upper-left corner of the upper-left pixel (origin X)

§pixel_width: f64

W-E pixel resolution (pixel width)

§row_rotation: f64

Row rotation (typically zero for north-up images)

§origin_y: f64

Y coordinate of the upper-left corner of the upper-left pixel (origin Y)

§col_rotation: f64

Column rotation (typically zero for north-up images)

§pixel_height: f64

N-S pixel resolution (pixel height, typically negative)

Implementations§

Source§

impl GeoTransform

Source

pub const fn new( origin_x: f64, pixel_width: f64, row_rotation: f64, origin_y: f64, col_rotation: f64, pixel_height: f64, ) -> GeoTransform

Creates a new GeoTransform from the six coefficients

§Arguments
  • origin_x - X coordinate of the upper-left corner
  • pixel_width - W-E pixel resolution
  • row_rotation - Row rotation (0 for north-up)
  • origin_y - Y coordinate of the upper-left corner
  • col_rotation - Column rotation (0 for north-up)
  • pixel_height - N-S pixel resolution (negative for north-up)
Source

pub const fn north_up( origin_x: f64, origin_y: f64, pixel_width: f64, pixel_height: f64, ) -> GeoTransform

Creates a north-up GeoTransform (no rotation)

§Arguments
  • origin_x - X coordinate of the upper-left corner
  • origin_y - Y coordinate of the upper-left corner
  • pixel_width - Pixel width (positive)
  • pixel_height - Pixel height (negative for north-up)
Source

pub const fn from_gdal_array(coeffs: [f64; 6]) -> GeoTransform

Creates a GeoTransform from the standard GDAL 6-element array

The array format is: [origin_x, pixel_width, row_rotation, origin_y, col_rotation, pixel_height]

Source

pub const fn to_gdal_array(&self) -> [f64; 6]

Converts to the standard GDAL 6-element array

Source

pub const fn identity() -> GeoTransform

Creates an identity transform (pixel = world)

Source

pub fn from_bounds( bbox: &BoundingBox, width: u64, height: u64, ) -> Result<GeoTransform, OxiGdalError>

Creates a GeoTransform from a bounding box and image dimensions

§Arguments
  • bbox - The bounding box of the image
  • width - Image width in pixels
  • height - Image height in pixels
§Errors

Returns an error if width or height is zero

Source

pub fn pixel_to_world(&self, pixel_x: f64, pixel_y: f64) -> (f64, f64)

Transforms pixel coordinates to world coordinates

§Arguments
  • pixel_x - X pixel coordinate (column)
  • pixel_y - Y pixel coordinate (row)
§Returns

A tuple of (x, y) world coordinates

Source

pub fn world_to_pixel( &self, world_x: f64, world_y: f64, ) -> Result<(f64, f64), OxiGdalError>

Transforms world coordinates to pixel coordinates

§Arguments
  • world_x - X world coordinate
  • world_y - Y world coordinate
§Returns

Ok with a tuple of (pixel_x, pixel_y), or an error if the transform is singular

§Errors

Returns an error if the determinant is zero (singular matrix)

Source

pub fn pixel_center(&self, pixel_x: u64, pixel_y: u64) -> (f64, f64)

Returns the center of a pixel in world coordinates

Source

pub fn compute_bounds(&self, width: u64, height: u64) -> BoundingBox

Computes the bounding box for the given raster dimensions

§Arguments
  • width - Raster width in pixels
  • height - Raster height in pixels
§Returns

The bounding box in world coordinates

Source

pub fn is_north_up(&self) -> bool

Returns true if this is a north-up transform (no rotation)

Source

pub fn has_rotation(&self) -> bool

Returns true if the transform has rotation

Source

pub fn resolution(&self) -> (f64, f64)

Returns the absolute pixel resolution (ignoring sign)

Source

pub fn rotation_radians(&self) -> f64

Returns the rotation angle in radians (assuming uniform scaling)

The rotation is calculated from the affine transformation matrix. For a standard rotation, this extracts the angle from the col_rotation and pixel_width terms.

Source

pub fn rotation_degrees(&self) -> f64

Returns the rotation angle in degrees

Source

pub fn inverse(&self) -> Result<GeoTransform, OxiGdalError>

Creates the inverse transform

§Errors

Returns an error if the transform is singular

Source

pub fn compose(&self, other: &GeoTransform) -> GeoTransform

Composes two transforms: self followed by other

The result transforms from pixel space through self to world space, then from world space through other.

Source

pub const fn scale(&self, scale_x: f64, scale_y: f64) -> GeoTransform

Scales the transform by the given factors

Source

pub const fn translate(&self, offset_x: f64, offset_y: f64) -> GeoTransform

Translates the transform by the given offset

Trait Implementations§

Source§

impl Clone for GeoTransform

Source§

fn clone(&self) -> GeoTransform

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GeoTransform

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for GeoTransform

Source§

fn default() -> GeoTransform

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for GeoTransform

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<GeoTransform, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for GeoTransform

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for GeoTransform

Source§

fn eq(&self, other: &GeoTransform) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for GeoTransform

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for GeoTransform

Source§

impl StructuralPartialEq for GeoTransform

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,