Point

Struct Point 

Source
pub struct Point {
    pub x: f64,
    pub y: f64,
}
Expand description

Point with only x and y Coords

Fields§

§x: f64§y: f64

Implementations§

Source§

impl Point

Source

pub fn new(x: f64, y: f64) -> Self

Creates a new point

§Examples
use shapefile::Point;
let point = Point::new(1.0, 42.0);
assert_eq!(point.x, 1.0);
assert_eq!(point.y, 42.0);
use shapefile::Point;
let point = Point::default();
assert_eq!(point.x, 0.0);
assert_eq!(point.y, 0.0);
Examples found in repository?
examples/create.rs (line 8)
4fn example_1() {
5    const FILE_NAME: &str = "hello_shape_1.shp";
6
7    let square = Polyline::new(vec![
8        Point::new(0.0, 0.0),
9        Point::new(0.0, 1.0),
10        Point::new(1.0, 1.0),
11        Point::new(1.0, 0.0),
12    ]);
13
14    let bigger_square = Polyline::new(vec![
15        Point::new(0.0, 0.0),
16        Point::new(0.0, 10.0),
17        Point::new(10.0, 10.0),
18        Point::new(10.0, 0.0),
19    ]);
20
21    // Create the builder for the accompanying dbase (.dbf) file
22    // For this simple example we will only have a single field
23    // "Name", with 55 chars max
24    let table_builder =
25        TableWriterBuilder::new().add_character_field("Name".try_into().unwrap(), 55);
26
27    {
28        let mut writer = Writer::from_path(FILE_NAME, table_builder)
29            .expect("Failed to create the shapefile writer");
30
31        let mut first_record = dbase::Record::default();
32        first_record.insert("Name".to_string(), "Square".to_string().into());
33        writer
34            .write_shape_and_record(&square, &first_record)
35            .expect("Failed to write first record");
36
37        let mut second_record = dbase::Record::default();
38        second_record.insert("Name".to_string(), "Big Square".to_string().into());
39        writer
40            .write_shape_and_record(&bigger_square, &second_record)
41            .expect("Failed to write second record");
42    }
43
44    println!("File created, you can use `cargo run --example print-content {FILE_NAME}`");
45}
46
47fn example_2() {
48    dbase_record!(
49        #[derive(Debug)]
50        struct UserRecord {
51            first_name: String,
52            last_name: String,
53        }
54    );
55
56    const FILE_NAME: &str = "hello_shape_2.shp";
57
58    let square = Polyline::new(vec![
59        Point::new(0.0, 0.0),
60        Point::new(0.0, 1.0),
61        Point::new(1.0, 1.0),
62        Point::new(1.0, 0.0),
63    ]);
64
65    let bigger_square = Polyline::new(vec![
66        Point::new(0.0, 0.0),
67        Point::new(0.0, 10.0),
68        Point::new(10.0, 10.0),
69        Point::new(10.0, 0.0),
70    ]);
71
72    // Create the builder for the accompanying dbase (.dbf) file
73    let table_builder = TableWriterBuilder::new()
74        .add_character_field("FirstName".try_into().unwrap(), 55)
75        .add_character_field("LastName".try_into().unwrap(), 55);
76
77    {
78        let mut writer = Writer::from_path(FILE_NAME, table_builder)
79            .expect("Failed to create the shapefile writer");
80
81        let first_record = UserRecord {
82            first_name: "Yoshi".to_string(),
83            last_name: "Green".to_string(),
84        };
85
86        writer
87            .write_shape_and_record(&square, &first_record)
88            .expect("Failed to write first record");
89
90        let second_record = UserRecord {
91            first_name: "Yoshi".to_string(),
92            last_name: "Red".to_string(),
93        };
94        writer
95            .write_shape_and_record(&bigger_square, &second_record)
96            .expect("Failed to write second record");
97    }
98
99    println!("File created, you can use `cargo run --example print-content {FILE_NAME}`");
100}

Trait Implementations§

Source§

impl Clone for Point

Source§

fn clone(&self) -> Point

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl ConcreteReadableShape for Point

Source§

fn read_shape_content<T: Read>( source: &mut T, record_size: i32, ) -> Result<Self, Error>

Function that actually reads the ActualShape from the source and returns it
Source§

impl CoordTrait for &Point

Source§

type T = f64

The coordinate type of this geometry
Source§

fn dim(&self) -> Dimensions

Dimensions of the coordinate tuple
Source§

fn nth_or_panic(&self, n: usize) -> Self::T

Access the n’th (0-based) element of the CoordinateTuple. May panic if n >= DIMENSION. See also nth().
Source§

unsafe fn nth_unchecked(&self, n: usize) -> Self::T

Access the n’th (0-based) element of the CoordinateTuple. May panic if n >= DIMENSION. Read more
Source§

fn x(&self) -> Self::T

x component of this coord.
Source§

fn y(&self) -> Self::T

y component of this coord.
Source§

fn nth(&self, n: usize) -> Option<Self::T>

Access the n’th (0-based) element of the CoordinateTuple. Returns None if n >= DIMENSION. Read more
Source§

fn x_y(&self) -> (Self::T, Self::T)

Returns a tuple that contains the x/horizontal & y/vertical component of the coord.
Source§

impl CoordTrait for Point

Source§

type T = f64

The coordinate type of this geometry
Source§

fn dim(&self) -> Dimensions

Dimensions of the coordinate tuple
Source§

fn nth_or_panic(&self, n: usize) -> Self::T

Access the n’th (0-based) element of the CoordinateTuple. May panic if n >= DIMENSION. See also nth().
Source§

unsafe fn nth_unchecked(&self, n: usize) -> Self::T

Access the n’th (0-based) element of the CoordinateTuple. May panic if n >= DIMENSION. Read more
Source§

fn x(&self) -> Self::T

x component of this coord.
Source§

fn y(&self) -> Self::T

y component of this coord.
Source§

fn nth(&self, n: usize) -> Option<Self::T>

Access the n’th (0-based) element of the CoordinateTuple. Returns None if n >= DIMENSION. Read more
Source§

fn x_y(&self) -> (Self::T, Self::T)

Returns a tuple that contains the x/horizontal & y/vertical component of the coord.
Source§

impl Debug for Point

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Point

Source§

fn default() -> Point

Returns the “default value” for a type. Read more
Source§

impl Display for Point

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl EsriShape for Point

Source§

fn x_range(&self) -> [f64; 2]

Source§

fn y_range(&self) -> [f64; 2]

Source§

fn z_range(&self) -> [f64; 2]

Should return the Z range of this shape
Source§

fn m_range(&self) -> [f64; 2]

Should return the M range of this shape
Source§

impl From<Coord> for Point

Available on crate feature geo-types only.
Source§

fn from(c: Coord<f64>) -> Self

Converts to this type from the input type.
Source§

impl From<Point> for Coord<f64>

Available on crate feature geo-types only.
Source§

fn from(p: Point) -> Self

Converts to this type from the input type.
Source§

impl From<Point> for Point<f64>

Available on crate feature geo-types only.
Source§

fn from(p: Point) -> Self

Converts to this type from the input type.
Source§

impl From<Point> for Point

Available on crate feature geo-types only.
Source§

fn from(p: Point<f64>) -> Self

Converts to this type from the input type.
Source§

impl From<Point> for Shape

Source§

fn from(concrete: Point) -> Self

Converts to this type from the input type.
Source§

impl GrowablePoint for Point

Source§

fn grow(&mut self, other: &Self)

Source§

impl HasShapeType for Point

Source§

fn shapetype() -> ShapeType

Returns the ShapeType
Source§

impl HasXY for Point

Source§

fn x(&self) -> f64

Returns the value of the x dimension
Source§

fn y(&self) -> f64

Returns the value of the y dimension
Source§

impl PartialEq for Point

Source§

fn eq(&self, other: &Point) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PointTrait for &Point

Source§

type T = f64

The coordinate type of this geometry
Source§

type CoordType<'a> = &'a Point where Self: 'a

The type of the underlying coordinate, which implements CoordTrait
Source§

fn dim(&self) -> Dimensions

Dimensions of the coordinate tuple
Source§

fn coord(&self) -> Option<Self::CoordType<'_>>

The location of this 0-dimensional geometry. Read more
Source§

impl PointTrait for Point

Source§

type T = f64

The coordinate type of this geometry
Source§

type CoordType<'a> = &'a Point where Self: 'a

The type of the underlying coordinate, which implements CoordTrait
Source§

fn dim(&self) -> Dimensions

Dimensions of the coordinate tuple
Source§

fn coord(&self) -> Option<Self::CoordType<'_>>

The location of this 0-dimensional geometry. Read more
Source§

impl ShrinkablePoint for Point

Source§

fn shrink(&mut self, other: &Self)

Source§

impl TryFrom<Shape> for Point

Source§

type Error = Error

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

fn try_from(shape: Shape) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl WritableShape for Point

Source§

fn size_in_bytes(&self) -> usize

Returns the size in bytes that the Shapes will take once written. Does not include the shapetype
Source§

fn write_to<T: Write>(&self, dest: &mut T) -> Result<(), Error>

Writes the shape to the dest
Source§

impl ConcreteShape for Point

Source§

impl Copy for Point

Source§

impl StructuralPartialEq for Point

Auto Trait Implementations§

§

impl Freeze for Point

§

impl RefUnwindSafe for Point

§

impl Send for Point

§

impl Sync for Point

§

impl Unpin for Point

§

impl UnwindSafe for Point

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<S> ReadableShape for S

Source§

fn read_from<T>(source: &mut T, record_size: i32) -> Result<S, Error>
where T: Read,

Source§

impl<T, G> ToGeoCoord<T> for G
where T: CoordNum, G: CoordTrait<T = T>,

Source§

fn to_coord(&self) -> Coord<T>

Convert to a geo_types Coord.
Source§

impl<T, G> ToGeoPoint<T> for G
where T: CoordNum, G: PointTrait<T = T>,

Source§

fn try_to_point(&self) -> Option<Point<T>>

Convert to a geo_types Point. Read more
Source§

fn to_point(&self) -> Point<T>

Convert to a geo_types Point. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.