Raster

Struct Raster 

Source
pub struct Raster {
    pub endian: Endian,
    pub version: u16,
    pub scale_x: f64,
    pub scale_y: f64,
    pub ip_x: f64,
    pub ip_y: f64,
    pub skew_x: f64,
    pub skew_y: f64,
    pub srid: i32,
    pub width: u16,
    pub height: u16,
    pub bands: Vec<RasterBand>,
}
Expand description

Raster data

Fields§

§endian: Endian

Endinanness, 1:ndr/little endian, 0:xdr/big endian

§version: u16

format version (0 for this structure)

§scale_x: f64

pixel width in geographical units

§scale_y: f64

pixel height in geographical units

§ip_x: f64

X ordinate of upper-left pixel’s upper-left corner in geographical units

§ip_y: f64

Y ordinate of upper-left pixel’s upper-left corner in geographical units

§skew_x: f64

rotation about Y-axis

§skew_y: f64

rotation about X-axis

§srid: i32

Spatial reference id

§width: u16

Number of pixel columns

§height: u16

Number of pixel rows

§bands: Vec<RasterBand>

Bands data

Implementations§

Source§

impl Raster

Source

pub fn to_wkb_string(self) -> String

Outputs the raster as a Well-Known-Binary string, ready to be used in SQL statements

Examples found in repository?
examples/test_runner.rs (line 23)
4fn run_encode_test_inner(endian: Endian, input: InMemoryRasterData, width: u16, height: u16) {
5    let setup = Raster {
6        endian,
7        version: 0,
8        scale_x: 500.0,
9        scale_y: 1.0,
10        ip_x: 0.0,
11        ip_y: 0.0,
12        skew_x: 0.0,
13        skew_y: 0.0,
14        srid: 4326,
15        width,
16        height,
17        bands: vec![RasterBand {
18            is_nodata_value: false,
19            data: RasterDataSource::InMemory(input),
20        }],
21    };
22
23    let encoded = setup.clone().to_wkb_string();
24    let decoded = Raster::from_wkb_string(&encoded.as_bytes()).unwrap();
25    if decoded != setup {
26        use std::process::exit;
27        println!("expected: {:#?}\n\ngot:{:#?}", setup, decoded);
28        exit(1);
29    }
30}
More examples
Hide additional examples
examples/write.rs (line 33)
3fn main() {
4    // 2x2 image bytes, u8 format
5    let bytes = vec![
6        vec![34, 40],
7        vec![56, 0],
8    ];
9
10    let raster = Raster {
11        endian: Endian::Big,    // note: currently Endian::Little is not supported in PostGIS
12        version: 0,             // always set to 0
13        scale_x: 500.0,           // pixel width in degrees
14        scale_y: 1.0,           // pixel height in degrees
15        ip_x: 0.0,              // upper left corner longitude in degrees
16        ip_y: 0.0,              // upper left corner latitude in degrees
17        skew_x: 0.0,            // rotation in degrees (0 to 360)
18        skew_y: 0.0,            // rotation in degrees (0 to 360)
19        srid: 4326,             // SRID EPSG identifier
20        width: 2,               // pixel columns
21        height: 2,              // rows
22        bands: vec![RasterBand {
23            is_nodata_value: false,                     // See documentation, usually false
24            data: RasterDataSource::InMemory(
25                InMemoryRasterData::UInt8 {
26                    data: bytes,
27                    nodata: None,
28                }
29            ),
30        }],
31    };
32
33    println!("{}", raster.to_wkb_string());
34}
Source

pub fn from_wkb_string(string_bytes: &[u8]) -> Result<Self, ParseError>

Examples found in repository?
examples/read.rs (line 5)
3fn main() {
4    let s = b"0000000001407F4000000000003FF00000000000000000000000000000000000000000000000000000000000000000000000000000000010E600020002040022283800";
5    let raster = Raster::from_wkb_string(&s[..]);
6    println!("raster: {:#?}", raster);
7}
More examples
Hide additional examples
examples/test_runner.rs (line 24)
4fn run_encode_test_inner(endian: Endian, input: InMemoryRasterData, width: u16, height: u16) {
5    let setup = Raster {
6        endian,
7        version: 0,
8        scale_x: 500.0,
9        scale_y: 1.0,
10        ip_x: 0.0,
11        ip_y: 0.0,
12        skew_x: 0.0,
13        skew_y: 0.0,
14        srid: 4326,
15        width,
16        height,
17        bands: vec![RasterBand {
18            is_nodata_value: false,
19            data: RasterDataSource::InMemory(input),
20        }],
21    };
22
23    let encoded = setup.clone().to_wkb_string();
24    let decoded = Raster::from_wkb_string(&encoded.as_bytes()).unwrap();
25    if decoded != setup {
26        use std::process::exit;
27        println!("expected: {:#?}\n\ngot:{:#?}", setup, decoded);
28        exit(1);
29    }
30}
31
32fn run_encode_test(input: InMemoryRasterData, width: u16, height: u16) {
33    run_encode_test_inner(Endian::Big, input.clone(), width, height);
34    run_encode_test_inner(Endian::Little, input, width, height);
35}
36
37fn run_decode_test(decode: &[u8]) {
38    let _ = Raster::from_wkb_string(decode);
39}

Trait Implementations§

Source§

impl Clone for Raster

Source§

fn clone(&self) -> Raster

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 Raster

Source§

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

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

impl PartialEq for Raster

Source§

fn eq(&self, other: &Raster) -> 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 PartialOrd for Raster

Source§

fn partial_cmp(&self, other: &Raster) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for Raster

Auto Trait Implementations§

§

impl Freeze for Raster

§

impl RefUnwindSafe for Raster

§

impl Send for Raster

§

impl Sync for Raster

§

impl Unpin for Raster

§

impl UnwindSafe for Raster

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, 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, 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.