Well Known Binary format for PostGIS RASTER type
The WKB format for RASTER is meant for transport and takes into account endianness and avoids any padding. Still, beside padding and endianness, it matches the internal serialized format (see RFC1), for quick input/output.
```rust use wkb_raster::{Raster, RasterBand, RasterDataSource, InMemoryRasterData, Endian};
// 2x2 image bytes, u8 format let bytes = vec![ vec![0, 1], vec![1, 0], ];
let raster = Raster { endian: Endian::Big, // note: currently Endian::Little is not supported in PostGIS version: 0, // always set to 0 scalex: 1.0, // pixel width in degrees scaley: 1.0, // pixel height in degrees ipx: 0.0, // upper left corner longitude in degrees ipy: 0.0, // upper left corner latitude in degrees skewx: 0.0, // rotation in degrees (0 to 360) skewy: 0.0, // rotation in degrees (0 to 360) srid: 4326, // SRID EPSG identifier width: 2, // pixel columns height: 2, // rows bands: vec![RasterBand { isnodatavalue: false // true only if entire band is NODATA data: RasterDataSource::InMemory( InMemoryRasterData::UInt8 { data: bytes, nodata } ), }], };
asserteq!( raster.towkb_string(), String::from("00000000013FF00000000000003FF00000000000000000000000000000000000000000000000000000000000000000000000000000000010E600020002040000010100") ); ```
```rust use wkb_raster::{Raster, RasterBand, RasterDataSource, InMemoryRasterData, Endian};
let parsedraster = Raster::fromwkb_string(b"00000000013FF00000000000003FF00000000000000000000000000000000000000000000000000000000000000000000000000000000010E600020002040000010100").unwrap();
// 2x2 image bytes, u8 format let bytes = vec![ vec![0, 1], vec![1, 0], ];
asserteq!(parsedraster, Raster { endian: Endian::Big, version: 0, scalex: 1.0, scaley: 1.0, ipx: 0.0, ipy: 0.0, skewx: 0.0, skewy: 0.0, srid: 4326, width: 2, height: 2, bands: vec![RasterBand { isnodatavalue: false, data: RasterDataSource::InMemory( InMemoryRasterData::UInt8 { data: bytes, nodata } ), }], }); ```
License: MIT