pub struct WKTWriter { /* 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§
source§impl WKTWriter
impl WKTWriter
sourcepub fn new() -> GResult<WKTWriter>
pub fn new() -> GResult<WKTWriter>
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>) -> GResult<WKTWriter>
pub fn new_with_context(context: Arc<ContextHandle>) -> GResult<WKTWriter>
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<G: Geom>(&mut self, geometry: &G) -> GResult<String>
pub fn write<G: Geom>(&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§
source§impl ContextHandling for WKTWriter
impl ContextHandling for WKTWriter
type Context = Arc<ContextHandle>
fn clone_context(&self) -> Arc<ContextHandle>
source§impl ContextInteractions for WKTWriter
impl ContextInteractions for WKTWriter
source§fn set_context_handle(&mut self, context: ContextHandle)
fn set_context_handle(&mut self, context: ContextHandle)
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);
source§fn get_context_handle(&self) -> &ContextHandle
fn get_context_handle(&self) -> &ContextHandle
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))));
source§fn 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 moresource§fn 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 moreimpl Send for WKTWriter
impl Sync for WKTWriter
Auto Trait Implementations§
impl Freeze for WKTWriter
impl RefUnwindSafe for WKTWriter
impl Unpin for WKTWriter
impl UnwindSafe for WKTWriter
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