Struct shapefile::writer::Writer

source ·
pub struct Writer<T: Write + Seek> { /* private fields */ }
Expand description

The Writer writes a complete shapefile that is, it writes the 3 mandatory files (.shp, .shx, .dbf)

The recommended way to create a new shapefile is via the Writer::from_path or Writer::from_path_with_info associated functions.

§Examples

To create a Writer that writes a .dbf file that has the same structure as .dbf read earlier you will have to do:

let mut reader = shapefile::Reader::from_path("tests/data/multipatch.shp")?;
let shape_records = reader.read()?;
let table_info = reader.into_table_info();

let writer = shapefile::Writer::from_path_with_info("new_multipatch.shp", table_info);

Implementations§

source§

impl<T: Write + Seek> Writer<T>

source

pub fn new(shape_writer: ShapeWriter<T>, dbase_writer: TableWriter<T>) -> Self

Creates a new writer using the provided ShapeWriter and TableWriter

§Example

Creating a Writer that writes to in memory buffers.

use std::convert::TryInto;
let mut shp_dest = std::io::Cursor::new(Vec::<u8>::new());
let mut shx_dest = std::io::Cursor::new(Vec::<u8>::new());
let mut dbf_dest = std::io::Cursor::new(Vec::<u8>::new());

let shape_writer = shapefile::ShapeWriter::with_shx(&mut shp_dest, &mut shx_dest);
let dbase_writer = dbase::TableWriterBuilder::new()
    .add_character_field("Name".try_into().unwrap(), 50)
    .build_with_dest(&mut dbf_dest);

let shape_writer = shapefile::Writer::new(shape_writer, dbase_writer);
source

pub fn write_shape_and_record<S: EsriShape, R: WritableRecord>( &mut self, shape: &S, record: &R ) -> Result<(), Error>

source

pub fn write_shapes_and_records<'a, S: EsriShape + 'a, R: WritableRecord + 'a, C: IntoIterator<Item = (&'a S, &'a R)>>( self, container: C ) -> Result<(), Error>

source§

impl Writer<BufWriter<File>>

source

pub fn from_path<P: AsRef<Path>>( path: P, table_builder: TableWriterBuilder ) -> Result<Self, Error>

Creates all the files needed for the shapefile to be complete (.shp, .shx, .dbf)

use std::convert::TryInto;
let table_builder = dbase::TableWriterBuilder::new()
    .add_character_field("name".try_into().unwrap(), 50);
let writer = shapefile::Writer::from_path("new_cities.shp", table_builder)?;
source

pub fn from_path_with_info<P: AsRef<Path>>( path: P, table_info: TableInfo ) -> Result<Self, Error>

Auto Trait Implementations§

§

impl<T> Freeze for Writer<T>
where T: Freeze,

§

impl<T> !RefUnwindSafe for Writer<T>

§

impl<T> Send for Writer<T>
where T: Send,

§

impl<T> !Sync for Writer<T>

§

impl<T> Unpin for Writer<T>
where T: Unpin,

§

impl<T> !UnwindSafe for Writer<T>

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.