Struct 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 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 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>,

Source§

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>,

Source§

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.