pub struct Point {
pub x: f64,
pub y: f64,
}Expand description
Point with only x and y Coords
Fields§
§x: f64§y: f64Implementations§
Source§impl Point
impl Point
Sourcepub fn new(x: f64, y: f64) -> Self
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 ConcreteReadableShape for Point
impl ConcreteReadableShape for Point
Source§impl CoordTrait for &Point
impl CoordTrait for &Point
Source§fn dim(&self) -> Dimensions
fn dim(&self) -> Dimensions
Dimensions of the coordinate tuple
Source§fn nth_or_panic(&self, n: usize) -> Self::T
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
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§impl CoordTrait for Point
impl CoordTrait for Point
Source§fn dim(&self) -> Dimensions
fn dim(&self) -> Dimensions
Dimensions of the coordinate tuple
Source§fn nth_or_panic(&self, n: usize) -> Self::T
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
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§impl PointTrait for &Point
impl PointTrait for &Point
Source§type CoordType<'a> = &'a Point
where
Self: 'a
type CoordType<'a> = &'a Point where Self: 'a
The type of the underlying coordinate, which implements CoordTrait
Source§fn dim(&self) -> Dimensions
fn dim(&self) -> Dimensions
Dimensions of the coordinate tuple
Source§impl PointTrait for Point
impl PointTrait for Point
Source§type CoordType<'a> = &'a Point
where
Self: 'a
type CoordType<'a> = &'a Point where Self: 'a
The type of the underlying coordinate, which implements CoordTrait
Source§fn dim(&self) -> Dimensions
fn dim(&self) -> Dimensions
Dimensions of the coordinate tuple
Source§impl WritableShape for Point
impl WritableShape for Point
impl ConcreteShape for Point
impl Copy for Point
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> 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