pub struct WKTWriter<'a> { /* private fields */ }
Expand description
The WKTWriter
type is used to generate WKT
formatted output from Geometry
.
Example
use geos::{Geometry, WKTWriter};
let point_geom = Geometry::new_from_wkt("POINT (2.5 2.5)").expect("Invalid geometry");
let mut writer = WKTWriter::new().expect("Failed to create WKTWriter");
assert_eq!(writer.write(&point_geom).unwrap(), "POINT (2.5000000000000000 2.5000000000000000)");
Implementations
sourceimpl<'a> WKTWriter<'a>
impl<'a> WKTWriter<'a>
sourcepub fn new() -> GResult<WKTWriter<'a>>
pub fn new() -> GResult<WKTWriter<'a>>
Creates a new WKTWriter
instance.
Example
use geos::{Geometry, WKTWriter};
let point_geom = Geometry::new_from_wkt("POINT (2.5 2.5)").expect("Invalid geometry");
let mut writer = WKTWriter::new().expect("Failed to create WKTWriter");
assert_eq!(writer.write(&point_geom).unwrap(), "POINT (2.5000000000000000 2.5000000000000000)");
sourcepub fn new_with_context(
context: Arc<ContextHandle<'a>>
) -> GResult<WKTWriter<'a>>
pub fn new_with_context(
context: Arc<ContextHandle<'a>>
) -> GResult<WKTWriter<'a>>
Creates a new WKTWriter
instance with a given context.
Example
use geos::{ContextHandling, Geometry, WKTWriter};
let point_geom = Geometry::new_from_wkt("POINT (2.5 2.5)").expect("Invalid geometry");
let mut writer = WKTWriter::new_with_context(point_geom.clone_context())
.expect("Failed to create WKTWriter");
assert_eq!(writer.write(&point_geom).unwrap(), "POINT (2.5000000000000000 2.5000000000000000)");
sourcepub fn write<'b, G: Geom<'b>>(&mut self, geometry: &G) -> GResult<String>
pub fn write<'b, G: Geom<'b>>(&mut self, geometry: &G) -> GResult<String>
Writes out the given geometry
as WKT format.
Example
use geos::{Geometry, WKTWriter};
let point_geom = Geometry::new_from_wkt("POINT (2.5 2.5)").expect("Invalid geometry");
let mut writer = WKTWriter::new().expect("Failed to create WKTWriter");
assert_eq!(writer.write(&point_geom).unwrap(), "POINT (2.5000000000000000 2.5000000000000000)");
sourcepub fn set_rounding_precision(&mut self, precision: u32)
pub fn set_rounding_precision(&mut self, precision: u32)
Sets the precision
to be used when calling WKTWriter::write
. Often, what users
actually want is the WKTWriter::set_trim
method instead.
Example
use geos::{Geometry, WKTWriter};
let point_geom = Geometry::new_from_wkt("POINT (2.5 2.5)").expect("Invalid geometry");
let mut writer = WKTWriter::new().expect("Failed to create WKTWriter");
writer.set_rounding_precision(2);
assert_eq!(writer.write(&point_geom).unwrap(), "POINT (2.50 2.50)");
writer.set_rounding_precision(4);
assert_eq!(writer.write(&point_geom).unwrap(), "POINT (2.5000 2.5000)");
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 WKTWriter::write
. By default, it
is 2.
Example
use geos::{Geometry, OutputDimension, WKTWriter};
let point_geom = Geometry::new_from_wkt("POINT (1.1 2.2 3.3)").expect("Invalid geometry");
let mut writer = WKTWriter::new().expect("Failed to create WKTWriter");
writer.set_trim(true);
assert_eq!(writer.write(&point_geom).unwrap(), "POINT (1.1 2.2)");
writer.set_output_dimension(OutputDimension::ThreeD);
assert_eq!(writer.write(&point_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 WKTWriter::write
. By default,
it is 2.
Example
use geos::{OutputDimension, WKTWriter};
let mut writer = WKTWriter::new().expect("Failed to create WKTWriter");
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 set_trim(&mut self, trim: bool)
pub fn set_trim(&mut self, trim: bool)
Enables/disables trimming of unnecessary decimals.
Example
use geos::{Geometry, WKTWriter};
let point_geom = Geometry::new_from_wkt("POINT (2.5 2.5)").expect("Invalid geometry");
let mut writer = WKTWriter::new().expect("Failed to create WKTWriter");
assert_eq!(writer.write(&point_geom).unwrap(), "POINT (2.5000000000000000 2.5000000000000000)");
writer.set_trim(true);
assert_eq!(writer.write(&point_geom).unwrap(), "POINT (2.5 2.5)");
sourcepub fn set_old_3D(&mut self, use_old_3D: bool)
pub fn set_old_3D(&mut self, use_old_3D: bool)
Enables/disables old 3D/4D WKT style generation.
Example
use geos::{Geometry, OutputDimension, WKTWriter};
let point_geom = Geometry::new_from_wkt("POINT (2.5 2.5 2.5)").expect("Invalid geometry");
let mut writer = WKTWriter::new().expect("Failed to create WKTWriter");
writer.set_output_dimension(OutputDimension::ThreeD);
writer.set_trim(true);
assert_eq!(writer.write(&point_geom).unwrap(), "POINT Z (2.5 2.5 2.5)");
writer.set_old_3D(true);
assert_eq!(writer.write(&point_geom).unwrap(), "POINT (2.5 2.5 2.5)");
Trait Implementations
sourceimpl<'a> ContextHandling for WKTWriter<'a>
impl<'a> ContextHandling for WKTWriter<'a>
type Context = Arc<ContextHandle<'a>>
fn clone_context(&self) -> Arc<ContextHandle<'a>>
sourceimpl<'a> ContextInteractions<'a> for WKTWriter<'a>
impl<'a> ContextInteractions<'a> for WKTWriter<'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 WKTWriter
.
use geos::{ContextInteractions, ContextHandle, WKTWriter};
let context_handle = ContextHandle::init().expect("invalid init");
let mut writer = WKTWriter::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 WKTWriter
.
use geos::{ContextInteractions, WKTWriter};
let mut writer = WKTWriter::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 WKTWriter<'a>
impl<'a> Sync for WKTWriter<'a>
Auto Trait Implementations
impl<'a> RefUnwindSafe for WKTWriter<'a>
impl<'a> Unpin for WKTWriter<'a>
impl<'a> UnwindSafe for WKTWriter<'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