pub struct WKBWriter<'a> { /* private fields */ }
Expand description
The WKBWriter
type is used to generate HEX
or WKB
formatted output from Geometry
.
Example
use geos::{ContextHandling, Geom, Geometry, WKBWriter};
let point_geom = Geometry::new_from_wkt("POINT (2.5 2.5)").expect("Invalid geometry");
let mut writer = WKBWriter::new_with_context(point_geom.clone_context())
.expect("Failed to create WKBWriter");
// Output as WKB
let v: Vec<u8> = writer.write_wkb(&point_geom).unwrap().into();
assert_eq!(Geometry::new_from_wkb(&v).unwrap().to_wkt_precision(1).unwrap(),
"POINT (2.5 2.5)");
// Output as HEX
let v: Vec<u8> = writer.write_hex(&point_geom).unwrap().into();
assert_eq!(Geometry::new_from_hex(&v).unwrap().to_wkt_precision(1).unwrap(),
"POINT (2.5 2.5)");
Implementations
sourceimpl<'a> WKBWriter<'a>
impl<'a> WKBWriter<'a>
sourcepub fn new() -> GResult<WKBWriter<'a>>
pub fn new() -> GResult<WKBWriter<'a>>
Creates a new WKBWriter
instance.
Example
use geos::{Geom, Geometry, WKBWriter};
let point_geom = Geometry::new_from_wkt("POINT (2.5 2.5)").expect("Invalid geometry");
let mut writer = WKBWriter::new().expect("Failed to create WKBWriter");
let v: Vec<u8> = writer.write_wkb(&point_geom).unwrap().into();
assert_eq!(Geometry::new_from_wkb(&v).unwrap().to_wkt_precision(1).unwrap(),
"POINT (2.5 2.5)");
sourcepub fn new_with_context(
context: Arc<ContextHandle<'a>>
) -> GResult<WKBWriter<'a>>
pub fn new_with_context(
context: Arc<ContextHandle<'a>>
) -> GResult<WKBWriter<'a>>
Creates a new WKBWriter
instance with a given context.
Example
use geos::{ContextHandling, Geom, Geometry, WKBWriter};
let point_geom = Geometry::new_from_wkt("POINT (2.5 2.5)").expect("Invalid geometry");
let mut writer = WKBWriter::new_with_context(point_geom.clone_context())
.expect("Failed to create WKBWriter");
let v: Vec<u8> = writer.write_wkb(&point_geom).unwrap().into();
assert_eq!(Geometry::new_from_wkb(&v).unwrap().to_wkt_precision(1).unwrap(),
"POINT (2.5 2.5)");
sourcepub fn write_wkb<'b, G: Geom<'b>>(&mut self, geometry: &G) -> GResult<CVec<u8>>
pub fn write_wkb<'b, G: Geom<'b>>(&mut self, geometry: &G) -> GResult<CVec<u8>>
Writes out the given geometry
as WKB format.
Example
use geos::{Geometry, WKBWriter};
let point_geom = Geometry::new_from_wkt("POINT (2.5 2.5)").expect("Invalid geometry");
let mut writer = WKBWriter::new().expect("Failed to create WKBWriter");
let v: Vec<u8> = writer.write_wkb(&point_geom).unwrap().into();
let expected = vec![1u8, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 64, 0, 0, 0, 0, 0, 0, 4, 64];
assert_eq!(v, expected);
sourcepub fn write_hex<'b, G: Geom<'b>>(&mut self, geometry: &G) -> GResult<CVec<u8>>
pub fn write_hex<'b, G: Geom<'b>>(&mut self, geometry: &G) -> GResult<CVec<u8>>
Writes out the given geometry
as WKB format.
Example
use geos::{Geometry, WKBWriter};
let point_geom = Geometry::new_from_wkt("POINT (2.5 2.5)").expect("Invalid geometry");
let mut writer = WKBWriter::new().expect("Failed to create WKBWriter");
let v: Vec<u8> = writer.write_hex(&point_geom).unwrap().into();
let expected = vec![48u8,49,48,49,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,
52,52,48,48,48,48,48,48,48,48,48,48,48,48,48,48,52,52,48];
assert_eq!(v, expected);
sourcepub fn set_output_dimension(&mut self, dimension: OutputDimension)
pub fn set_output_dimension(&mut self, dimension: OutputDimension)
Sets the number of dimensions to be used when calling WKBWriter::write_wkb
or
WKBWriter::write_hex
. By default, it is 2.
Example
use geos::{Geometry, OutputDimension, WKBWriter, WKTWriter};
let mut wkt_writer = WKTWriter::new().expect("Failed to create WKTWriter");
wkt_writer.set_output_dimension(OutputDimension::ThreeD);
wkt_writer.set_trim(true);
let point_geom = Geometry::new_from_wkt("POINT (1.1 2.2 3.3)").expect("Invalid geometry");
let mut writer = WKBWriter::new().expect("Failed to create WKBWriter");
let v: Vec<u8> = writer.write_wkb(&point_geom).unwrap().into();
let geom = Geometry::new_from_wkb(&v).unwrap();
assert_eq!(wkt_writer.write(&geom).unwrap(), "POINT (1.1 2.2)");
writer.set_output_dimension(OutputDimension::ThreeD);
let v: Vec<u8> = writer.write_wkb(&point_geom).unwrap().into();
let geom = Geometry::new_from_wkb(&v).unwrap();
assert_eq!(wkt_writer.write(&geom).unwrap(), "POINT Z (1.1 2.2 3.3)");
sourcepub fn get_out_dimension(&self) -> GResult<OutputDimension>
pub fn get_out_dimension(&self) -> GResult<OutputDimension>
Returns the number of dimensions to be used when calling WKBWriter::write_wkb
.
By default, it is 2.
Example
use geos::{OutputDimension, WKBWriter};
let mut writer = WKBWriter::new().expect("Failed to create WKBWriter");
assert_eq!(writer.get_out_dimension(), Ok(OutputDimension::TwoD));
writer.set_output_dimension(OutputDimension::ThreeD);
assert_eq!(writer.get_out_dimension(), Ok(OutputDimension::ThreeD));
sourcepub fn get_wkb_byte_order(&self) -> GResult<ByteOrder>
pub fn get_wkb_byte_order(&self) -> GResult<ByteOrder>
Gets WKB byte order.
Example
use geos::{ByteOrder, WKBWriter};
let mut writer = WKBWriter::new().expect("Failed to create WKBWriter");
writer.set_wkb_byte_order(ByteOrder::LittleEndian);
assert_eq!(writer.get_wkb_byte_order(), Ok(ByteOrder::LittleEndian));
sourcepub fn set_wkb_byte_order(&mut self, byte_order: ByteOrder)
pub fn set_wkb_byte_order(&mut self, byte_order: ByteOrder)
Sets WKB byte order.
Example
use geos::{WKBWriter, ByteOrder};
let mut writer = WKBWriter::new().expect("Failed to create WKBWriter");
writer.set_wkb_byte_order(ByteOrder::LittleEndian);
assert_eq!(writer.get_wkb_byte_order(), Ok(ByteOrder::LittleEndian));
sourcepub fn get_include_SRID(&self) -> GResult<bool>
pub fn get_include_SRID(&self) -> GResult<bool>
Gets if output will include SRID.
Example
use geos::WKBWriter;
let mut writer = WKBWriter::new().expect("Failed to create WKBWriter");
writer.set_include_SRID(true);
assert_eq!(writer.get_include_SRID(), Ok(true));
sourcepub fn set_include_SRID(&mut self, include_SRID: bool)
pub fn set_include_SRID(&mut self, include_SRID: bool)
Sets if output will include SRID.
Example
use geos::WKBWriter;
let mut writer = WKBWriter::new().expect("Failed to create WKBWriter");
writer.set_include_SRID(true);
assert_eq!(writer.get_include_SRID(), Ok(true));
Trait Implementations
sourceimpl<'a> ContextHandling for WKBWriter<'a>
impl<'a> ContextHandling for WKBWriter<'a>
type Context = Arc<ContextHandle<'a>>
fn clone_context(&self) -> Arc<ContextHandle<'a>>
sourceimpl<'a> ContextInteractions<'a> for WKBWriter<'a>
impl<'a> ContextInteractions<'a> for WKBWriter<'a>
sourcefn set_context_handle(&mut self, context: ContextHandle<'a>)
fn set_context_handle(&mut self, context: ContextHandle<'a>)
Set the context handle to the WKBWriter
.
use geos::{ContextInteractions, ContextHandle, WKBWriter};
let context_handle = ContextHandle::init().expect("invalid init");
let mut writer = WKBWriter::new().expect("failed to create WKT writer");
context_handle.set_notice_message_handler(Some(Box::new(|s| println!("new message: {}", s))));
writer.set_context_handle(context_handle);
sourcefn get_context_handle(&self) -> &ContextHandle<'a>
fn get_context_handle(&self) -> &ContextHandle<'a>
Get the context handle of the WKBWriter
.
use geos::{ContextInteractions, WKBWriter};
let mut writer = WKBWriter::new().expect("failed to create WKT writer");
let context = writer.get_context_handle();
context.set_notice_message_handler(Some(Box::new(|s| println!("new message: {}", s))));
sourcefn get_last_error(&self) -> Option<String>
fn get_last_error(&self) -> Option<String>
Gets the last error (if any) from the ContextHandle
held by this object. Read more
sourcefn get_last_notification(&self) -> Option<String>
fn get_last_notification(&self) -> Option<String>
Gets the last notification (if any) from the ContextHandle
held by this object. Read more
impl<'a> Send for WKBWriter<'a>
impl<'a> Sync for WKBWriter<'a>
Auto Trait Implementations
impl<'a> RefUnwindSafe for WKBWriter<'a>
impl<'a> Unpin for WKBWriter<'a>
impl<'a> UnwindSafe for WKBWriter<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more