Struct geos::CoordSeq

source ·
pub struct CoordSeq<'a> { /* private fields */ }
Expand description

CoordSeq represents a list of coordinates inside a Geometry.

§Example

use geos::{CoordDimensions, CoordSeq};

let mut coords = CoordSeq::new(1, CoordDimensions::OneD)
                          .expect("failed to create CoordSeq");
coords.set_x(0, 10.);
assert_eq!(coords.get_x(0), Ok(10.));

Implementations§

source§

impl<'a> CoordSeq<'a>

source

pub fn new(size: u32, dims: CoordDimensions) -> GResult<CoordSeq<'a>>

Creates a new CoordSeq.

§Example
use geos::{CoordDimensions, CoordSeq};

let mut coord_seq = CoordSeq::new(2, CoordDimensions::ThreeD)
                             .expect("failed to create CoordSeq");

// Then you fill the positions of your `coord_seq`:
let positions: &[(f64, f64, f64)] = &[(0., 0., 0.), (1., 2., 1.)];
for (pos, (x, y, z)) in positions.into_iter().enumerate() {
    coord_seq.set_x(pos, *x).expect("failed to set x...");
    coord_seq.set_y(pos, *y).expect("failed to set y...");
    coord_seq.set_z(pos, *z).expect("failed to set z...");
}
assert_eq!(coord_seq.get_z(1), Ok(1.));

// An example with 2 dimensions (and 3 lines) as well:
let mut coord_seq2 = CoordSeq::new(3, CoordDimensions::TwoD)
                              .expect("failed to create CoordSeq");
let positions2: &[(f64, f64)] = &[(0., 0.), (1., 2.), (14., 5.)];
for (pos, (x, y)) in positions2.into_iter().enumerate() {
    coord_seq2.set_x(pos, *x).expect("failed to set x...");
    coord_seq2.set_y(pos, *y).expect("failed to set y...");
}
assert_eq!(coord_seq2.get_x(1), Ok(1.));
source

pub fn new_from_vec<T: AsRef<[f64]>>(data: &[T]) -> GResult<CoordSeq<'a>>

Creates a new CoordSeq.

§Example
use geos::CoordSeq;

let coords = CoordSeq::new_from_vec(&[&[0., 1.], &[2., 3.]])
                      .expect("failed to create CoordSeq");
assert_eq!(coords.get_y(1), Ok(3.));

// Doing it from a Vec<Vec<f64>>.
let positions = vec![vec![0., 1.], vec![2., 3.]];
let s_positions = positions.iter().map(|x| x.as_slice()).collect::<Vec<_>>();
let coords = CoordSeq::new_from_vec(&s_positions)
                      .expect("failed to create CoordSeq");
assert_eq!(coords.get_y(1), Ok(3.));

// All vectors don't have the same length, this is an error!
assert!(CoordSeq::new_from_vec(&[vec![0., 1.], vec![3.]]).is_err());

// An empty vector is an error as well since we can't figure out its dimensions!
let x: &[f64] = &[];
assert!(CoordSeq::new_from_vec(&[x]).is_err());
source

pub fn set_x(&mut self, line: usize, val: f64) -> GResult<()>

Sets the X position value at the given line.

§Example
use geos::{CoordDimensions, CoordSeq};

let mut coords = CoordSeq::new(1, CoordDimensions::OneD)
                          .expect("failed to create CoordSeq");
coords.set_x(0, 10.);
assert_eq!(coords.get_x(0), Ok(10.));
source

pub fn set_y(&mut self, line: usize, val: f64) -> GResult<()>

Sets the Y position value at the given line.

Note: your CoordSeq object must have at least two dimensions!

§Example
use geos::{CoordDimensions, CoordSeq};

let mut coords = CoordSeq::new(1, CoordDimensions::TwoD)
                          .expect("failed to create CoordSeq");
coords.set_y(0, 10.);
assert_eq!(coords.get_y(0), Ok(10.));
source

pub fn set_z(&mut self, line: usize, val: f64) -> GResult<()>

Sets the Z position value at the given line.

Note: your CoordSeq object must have three dimensions!

§Example
use geos::{CoordDimensions, CoordSeq};

let mut coords = CoordSeq::new(1, CoordDimensions::ThreeD)
                          .expect("failed to create CoordSeq");
coords.set_z(0, 10.);
assert_eq!(coords.get_z(0), Ok(10.));
source

pub fn set_ordinate( &mut self, line: usize, ordinate: Ordinate, val: f64 ) -> GResult<()>

Sets the value at the given ordinate (aka position).

Note: your CoordSeq object must have enough dimensions to set at the given ordinate!

§Example
use geos::{CoordDimensions, CoordSeq, Ordinate};

let mut coords = CoordSeq::new(1, CoordDimensions::ThreeD)
                          .expect("failed to create CoordSeq");
coords.set_ordinate(0, Ordinate::Z, 10.);
assert_eq!(coords.get_z(0), Ok(10.));
assert_eq!(coords.get_ordinate(0, Ordinate::Z), Ok(10.));
source

pub fn get_x(&self, line: usize) -> GResult<f64>

Gets the X position value at the given line.

§Example
use geos::{CoordDimensions, CoordSeq};

let mut coords = CoordSeq::new(1, CoordDimensions::OneD)
                          .expect("failed to create CoordSeq");
coords.set_x(0, 10.);
assert_eq!(coords.get_x(0), Ok(10.));
source

pub fn get_y(&self, line: usize) -> GResult<f64>

Gets the Y position value at the given line.

Note: your CoordSeq object must have at least two dimensions!

§Example
use geos::{CoordDimensions, CoordSeq};

let mut coords = CoordSeq::new(1, CoordDimensions::TwoD)
                          .expect("failed to create CoordSeq");
coords.set_y(0, 10.);
assert_eq!(coords.get_y(0), Ok(10.));
source

pub fn get_z(&self, line: usize) -> GResult<f64>

Gets the Z position value at the given line.

Note: your CoordSeq object must have three dimensions!

§Example
use geos::{CoordDimensions, CoordSeq};

let mut coords = CoordSeq::new(1, CoordDimensions::ThreeD)
                          .expect("failed to create CoordSeq");
coords.set_z(0, 10.);
assert_eq!(coords.get_z(0), Ok(10.));
source

pub fn get_ordinate(&self, line: usize, ordinate: Ordinate) -> GResult<f64>

Gets the value at the given ordinate (aka position).

Note: your CoordSeq object must have enough dimensions to access the given ordinate!

§Example
use geos::{CoordDimensions, CoordSeq, Ordinate};

let mut coords = CoordSeq::new(1, CoordDimensions::ThreeD)
                          .expect("failed to create CoordSeq");
coords.set_ordinate(0, Ordinate::Z, 10.);
assert_eq!(coords.get_z(0), Ok(10.));
assert_eq!(coords.get_ordinate(0, Ordinate::Z), Ok(10.));
source

pub fn size(&self) -> GResult<usize>

Returns the number of lines of the CoordSeq object.

§Example
use geos::{CoordDimensions, CoordSeq};

let coords = CoordSeq::new(2, CoordDimensions::ThreeD)
                      .expect("failed to create CoordSeq");
assert_eq!(coords.size(), Ok(2));

let coords = CoordSeq::new_from_vec(&[&[1f64], &[2.], &[3.], &[4.]])
                      .expect("failed to create CoordSeq");
assert_eq!(coords.size(), Ok(4));
source

pub fn number_of_lines(&self) -> GResult<usize>

Returns the number of lines of the CoordSeq object.

Note: This is an alias to the size method.

§Example
use geos::{CoordDimensions, CoordSeq};

let coords = CoordSeq::new(2, CoordDimensions::ThreeD)
                      .expect("failed to create CoordSeq");
assert_eq!(coords.number_of_lines(), Ok(2));

let coords = CoordSeq::new_from_vec(&[&[1f64], &[2.], &[3.], &[4.]])
                      .expect("failed to create CoordSeq");
assert_eq!(coords.number_of_lines(), Ok(4));
source

pub fn dimensions(&self) -> GResult<CoordDimensions>

Returns the number of dimensions of the CoordSeq object.

§Example
use geos::{CoordDimensions, CoordSeq};

let coords = CoordSeq::new(2, CoordDimensions::OneD)
                      .expect("failed to create CoordSeq");
assert_eq!(coords.dimensions(), Ok(CoordDimensions::OneD));

let coords = CoordSeq::new_from_vec(&[&[1., 2.], &[3. ,4.]])
                      .expect("failed to create CoordSeq");
assert_eq!(coords.dimensions(), Ok(CoordDimensions::TwoD));
source

pub fn is_ccw(&self) -> GResult<bool>

Returns true if the geometry has a counter-clockwise orientation.

Available using the v3_7_0 feature.

source

pub fn create_point(self) -> GResult<Geometry<'a>>

Creates a point geometry.

§Example
use geos::{CoordDimensions, CoordSeq, Geom, Geometry};

let coords = CoordSeq::new_from_vec(&[&[1., 2.]])
                      .expect("failed to create CoordSeq");

let geom = Geometry::create_point(coords).expect("Failed to create point");

assert_eq!(geom.to_wkt().unwrap(), "POINT (1.0000000000000000 2.0000000000000000)");
source

pub fn create_line_string(self) -> GResult<Geometry<'a>>

Creates a line string geometry.

§Example
use geos::{CoordDimensions, CoordSeq, Geom, Geometry};

let coords = CoordSeq::new_from_vec(&[&[1., 2.], &[3., 4.]])
                      .expect("failed to create CoordSeq");

let geom = Geometry::create_line_string(coords).expect("Failed to create line string");

assert_eq!(geom.to_wkt().unwrap(),
           "LINESTRING (1.0000000000000000 2.0000000000000000, \
                        3.0000000000000000 4.0000000000000000)");
source

pub fn create_linear_ring(self) -> GResult<Geometry<'a>>

Creates a linear ring geometry.

Trait Implementations§

source§

impl<'a> Clone for CoordSeq<'a>

source§

fn clone(&self) -> CoordSeq<'a>

Also pass the context to the newly created CoordSeq.

1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> ContextHandling for CoordSeq<'a>

source§

impl<'a> ContextInteractions<'a> for CoordSeq<'a>

source§

fn set_context_handle(&mut self, context: ContextHandle<'a>)

Set the context handle to the CoordSeq.

use geos::{ContextInteractions, CoordDimensions, CoordSeq, ContextHandle};

let context_handle = ContextHandle::init().expect("invalid init");
context_handle.set_notice_message_handler(Some(Box::new(|s| println!("new message: {}", s))));
let mut coord_seq = CoordSeq::new(2, CoordDimensions::TwoD).expect("failed to create CoordSeq");
coord_seq.set_context_handle(context_handle);
source§

fn get_context_handle(&self) -> &ContextHandle<'a>

Get the context handle of the CoordSeq.

use geos::{ContextInteractions, CoordDimensions, CoordSeq};

let coord_seq = CoordSeq::new(2, CoordDimensions::TwoD).expect("failed to create CoordSeq");
let context = coord_seq.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<'a> Drop for CoordSeq<'a>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'a> Send for CoordSeq<'a>

source§

impl<'a> Sync for CoordSeq<'a>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for CoordSeq<'a>

§

impl<'a> Unpin for CoordSeq<'a>

§

impl<'a> UnwindSafe for CoordSeq<'a>

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.