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>
impl<T: Write + Seek> Writer<T>
sourcepub fn new(shape_writer: ShapeWriter<T>, dbase_writer: TableWriter<T>) -> Self
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);
pub fn write_shape_and_record<S: EsriShape, R: WritableRecord>( &mut self, shape: &S, record: &R ) -> Result<(), Error>
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>>
impl Writer<BufWriter<File>>
sourcepub fn from_path<P: AsRef<Path>>(
path: P,
table_builder: TableWriterBuilder
) -> Result<Self, Error>
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)?;
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> 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