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: EndianEndinanness, 1:ndr/little endian, 0:xdr/big endian
version: u16format version (0 for this structure)
scale_x: f64pixel width in geographical units
scale_y: f64pixel height in geographical units
ip_x: f64X ordinate of upper-left pixel’s upper-left corner in geographical units
ip_y: f64Y ordinate of upper-left pixel’s upper-left corner in geographical units
skew_x: f64rotation about Y-axis
skew_y: f64rotation about X-axis
srid: i32Spatial reference id
width: u16Number of pixel columns
height: u16Number of pixel rows
bands: Vec<RasterBand>Bands data
Implementations§
Source§impl Raster
impl Raster
Sourcepub fn to_wkb_string(self) -> String
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
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}Sourcepub fn from_wkb_string(string_bytes: &[u8]) -> Result<Self, ParseError>
pub fn from_wkb_string(string_bytes: &[u8]) -> Result<Self, ParseError>
Examples found in repository?
More 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 PartialOrd for Raster
impl PartialOrd for Raster
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more