pub struct Writer { /* private fields */ }Expand description
*.osm.pbf file reader
Write an ordered *.osm.pbf file split into blocks of 8000 or less elements of the same variant - Nodes, Ways, Relations. Example:
use std::path::PathBuf;
use osm_io::osm::model::element::Element;
use osm_io::osm::pbf;
use osm_io::osm::pbf::compression_type::CompressionType;
use osm_io::osm::pbf::file_info::FileInfo;
fn example() -> Result<(), anyhow::Error> {
let input_path = PathBuf::from("./tests/fixtures/malta-230109.osm.pbf");
let output_path = PathBuf::from("./target/results/malta-230109.osm.pbf");
let reader = pbf::reader::Reader::new(&input_path)?;
let mut file_info = FileInfo::default();
file_info.with_writingprogram_str("pbf-io-example");
let mut writer = pbf::writer::Writer::from_file_info(
output_path,
file_info,
CompressionType::Zlib,
)?;
writer.write_header()?;
for element in reader.elements()? {
let mut filtered_out = false;
match &element {
Element::Node { node: _ } => {}
Element::Way { way: _ } => {}
Element::Relation { relation: _ } => {}
Element::Sentinel => {
filtered_out = true;
}
}
if !filtered_out {
writer.write_element(element)?;
}
}
writer.close()?;
Ok(())
}Implementations§
source§impl Writer
impl Writer
sourcepub fn from_file_info(
path: PathBuf,
file_info: FileInfo,
compression_type: CompressionType
) -> Result<Writer, Error>
pub fn from_file_info( path: PathBuf, file_info: FileInfo, compression_type: CompressionType ) -> Result<Writer, Error>
sourcepub fn new(
path: PathBuf,
program_name: &str,
data_source: &str,
osmosis_replication_timestamp: Option<i64>,
osmosis_replication_sequence_number: Option<i64>,
osmosis_replication_base_url: Option<String>,
compression_type: CompressionType,
precomputed_bounding_box: Option<BoundingBox>,
contains_history: bool
) -> Result<Writer, Error>
pub fn new( path: PathBuf, program_name: &str, data_source: &str, osmosis_replication_timestamp: Option<i64>, osmosis_replication_sequence_number: Option<i64>, osmosis_replication_base_url: Option<String>, compression_type: CompressionType, precomputed_bounding_box: Option<BoundingBox>, contains_history: bool ) -> Result<Writer, Error>
Create a new Writer
sourcepub fn write_header(&mut self) -> Result<(), Error>
pub fn write_header(&mut self) -> Result<(), Error>
Write the *.osm.pbf file header.
Must be called before writing elements. That means that all header values, specifically the bounding box must be calculated before writing the file. I some cases that can incur a costly additional iteration.
sourcepub fn write_file_block(&mut self, file_block: FileBlock) -> Result<(), Error>
pub fn write_file_block(&mut self, file_block: FileBlock) -> Result<(), Error>
Low level API to write a FileBlock
sourcepub fn write_blob(
&mut self,
blob_header: Vec<u8>,
blob_body: Vec<u8>
) -> Result<(), Error>
pub fn write_blob( &mut self, blob_header: Vec<u8>, blob_body: Vec<u8> ) -> Result<(), Error>
Low level API to write a bytes of a blob
sourcepub fn write_element(&mut self, element: Element) -> Result<(), Error>
pub fn write_element(&mut self, element: Element) -> Result<(), Error>
Write element
Elements must be ordered, that is each element must be less then or equal to the following element
sourcepub fn write_elements(&mut self, elements: Vec<Element>) -> Result<(), Error>
pub fn write_elements(&mut self, elements: Vec<Element>) -> Result<(), Error>
Write elements
Elements must be ordered, that is each element must be less then or equal to the following element
Auto Trait Implementations§
impl RefUnwindSafe for Writer
impl Send for Writer
impl Sync for Writer
impl Unpin for Writer
impl UnwindSafe for Writer
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