Struct geos::WKTWriter

source ·
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

source

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)");
source

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)");
source

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)");
source

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)");
source

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)");
source

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));
source

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)");
source

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

source§

impl ContextInteractions for WKTWriter

source§

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

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>

Gets the last error (if any) from the ContextHandle held by this object. Read more
source§

fn get_last_notification(&self) -> Option<String>

Gets the last notification (if any) from the ContextHandle held by this object. Read more
source§

impl Drop for WKTWriter

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Send for WKTWriter

source§

impl Sync for WKTWriter

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.